diff --git a/api/v1/const.go b/api/v1/const.go index ea5b3389..85f71c29 100644 --- a/api/v1/const.go +++ b/api/v1/const.go @@ -6,3 +6,5 @@ var ( Delete ChangeAction = "delete" Ignore ChangeAction = "ignore" ) + +const ChangeTypeDiff = "diff" diff --git a/db/update.go b/db/update.go index 1ba47e17..3ae3f1f2 100644 --- a/db/update.go +++ b/db/update.go @@ -375,7 +375,7 @@ func extractChanges(ctx api.ScrapeContext, result *v1.ScrapeResult, ci *models.C } } - if change.Severity == "" && change.ChangeType != "diff" { + if change.Severity == "" && change.ChangeType != v1.ChangeTypeDiff { change.Severity = events.GetSeverity(change.ChangeType) } @@ -739,7 +739,7 @@ func updateLastScrapedTime(ctx api.ScrapeContext, ids []string) error { // given 2 config items and returns a ConfigChange object if there are any changes. func generateConfigChange(ctx api.ScrapeContext, newConf, prev models.ConfigItem) (*v1.ChangeResult, error) { if changeTypExclusion, ok := lo.FromPtr(newConf.Labels)[v1.AnnotationIgnoreChangeByType]; ok { - if collections.MatchItems("diff", strings.Split(changeTypExclusion, ",")...) { + if collections.MatchItems(v1.ChangeTypeDiff, strings.Split(changeTypExclusion, ",")...) { if ctx.PropertyOn(false, "log.exclusions") { ctx.Logger.V(4).Infof("excluding diff change for config(%s) with annotation (%s)", newConf, changeTypExclusion) } @@ -801,7 +801,7 @@ func generateConfigChange(ctx api.ScrapeContext, newConf, prev models.ConfigItem return &v1.ChangeResult{ ConfigType: newConf.Type, - ChangeType: "diff", + ChangeType: v1.ChangeTypeDiff, ExternalID: newConf.ExternalID[0], Diff: &diff, Patches: string(patch), diff --git a/scrapers/processors/json.go b/scrapers/processors/json.go index 93fa9172..15c17868 100644 --- a/scrapers/processors/json.go +++ b/scrapers/processors/json.go @@ -476,6 +476,9 @@ func (e Extract) Extract(ctx api.ScrapeContext, inputs ...v1.ScrapeResult) ([]v1 } extracted, err := e.extractAttributes(result) + if extracted.ID == "" { + continue + } if err != nil { return results, fmt.Errorf("failed to extract attributes: %v", err) } @@ -517,6 +520,10 @@ func (e Extract) extractAttributes(input v1.ScrapeResult) (v1.ScrapeResult, erro } if input.ID == "" { + // Ignore kubernetes diffs + if len(input.Changes) == 1 && (input.Changes[0].ChangeType == v1.ChangeTypeDiff) { + return input, nil + } return input, fmt.Errorf("no id defined for: %s: %v", input, e.Config) }