diff --git a/api/v1/types.go b/api/v1/types.go index 4a9430cd..8bdd67cd 100644 --- a/api/v1/types.go +++ b/api/v1/types.go @@ -101,9 +101,14 @@ func (e ExternalID) WhereClause(db *gorm.DB) *gorm.DB { type ConfigDeleteReason string var ( - // DeletedReasonStale is used when a config item doesn't get updated on a scrape run - DeletedReasonStale ConfigDeleteReason = "STALE" - DeletedReasonFromAttribute ConfigDeleteReason = "FROM_ATTRIBUTE" - DeletedReasonFromEvent ConfigDeleteReason = "FROM_EVENT" + // DeletedReasonStale is used when a config item doesn't get updated on a scrape run. + DeletedReasonStale ConfigDeleteReason = "STALE" + + // DeletedReasonFromAttribute is used when a deletion field (& reason) + // is picked up from the scraped config itself. + DeletedReasonFromAttribute ConfigDeleteReason = "FROM_ATTRIBUTE" + + // DeletedReasonFromDeleteField is used when a deletion field (& reason) + // is picked up from the JSONPath expression provided in the scraper config. DeletedReasonFromDeleteField ConfigDeleteReason = "FROM_DELETE_FIELD" ) diff --git a/db/models/config_item.go b/db/models/config_item.go index e3b48069..2b31d5bf 100644 --- a/db/models/config_item.go +++ b/db/models/config_item.go @@ -44,7 +44,6 @@ type ConfigItem struct { ParentExternalID string `gorm:"-" json:"-"` ParentType string `gorm:"-" json:"-"` - TouchDeletedAt bool `gorm:"-" json:"-"` } func (ci ConfigItem) String() string { diff --git a/db/update.go b/db/update.go index bb768362..72b3c3dd 100644 --- a/db/update.go +++ b/db/update.go @@ -104,11 +104,9 @@ func updateCI(ctx api.ScrapeContext, result v1.ScrapeResult, ci, existing *model updates := make(map[string]interface{}) changes := make([]*models.ConfigChange, 0) - // In case a resource was marked as deleted but is un-deleted now - // we set an update flag as gorm ignores nil pointers if ci.DeletedAt != existing.DeletedAt { - ci.TouchDeletedAt = true updates["deleted_at"] = ci.DeletedAt + updates["delete_reason"] = ci.DeleteReason } changeResult, err := generateConfigChange(*ci, *existing) @@ -178,11 +176,6 @@ func updateCI(ctx api.ScrapeContext, result v1.ScrapeResult, ci, existing *model updates["properties"] = *ci.Properties } - if ci.TouchDeletedAt && ci.DeleteReason != v1.DeletedReasonFromEvent { - updates["deleted_at"] = nil - updates["delete_reason"] = nil - } - if len(updates) == 0 { return changes, nil }