diff --git a/services/describe/scheduler_describe_result.go b/services/describe/scheduler_describe_result.go index a3104cd31..24fa613f4 100644 --- a/services/describe/scheduler_describe_result.go +++ b/services/describe/scheduler_describe_result.go @@ -337,65 +337,6 @@ func (s *Scheduler) cleanupDescribeResourcesNotInIntegrations(ctx context.Contex return } -func (s *Scheduler) cleanupDescribeResourcesForIntegrations(ctx context.Context, connectionIds []string) { - for _, connectionId := range connectionIds { - var searchAfter []any - for { - esResp, err := es.GetResourceIDsForIntegrationFromES(ctx, s.es, connectionId, searchAfter, 1000) - if err != nil { - s.logger.Error("failed to get resource ids from es", zap.Error(err)) - break - } - - if len(esResp.Hits.Hits) == 0 { - break - } - deletedCount := 0 - for _, hit := range esResp.Hits.Hits { - searchAfter = hit.Sort - - resource := es2.Resource{ - ResourceID: hit.Source.ResourceID, - IntegrationID: hit.Source.IntegrationID, - ResourceType: strings.ToLower(hit.Source.ResourceType), - IntegrationType: hit.Source.IntegrationType, - } - keys, idx := resource.KeysAndIndex() - deletedCount += 1 - key := es2.HashOf(keys...) - resource.EsID = key - resource.EsIndex = idx - err = s.es.Delete(key, idx) - if err != nil { - s.logger.Error("failed to delete resource from open-search", zap.Error(err)) - return - } - - lookupResource := es2.LookupResource{ - ResourceID: hit.Source.ResourceID, - IntegrationID: hit.Source.IntegrationID, - ResourceType: strings.ToLower(hit.Source.ResourceType), - IntegrationType: hit.Source.IntegrationType, - } - deletedCount += 1 - keys, idx = lookupResource.KeysAndIndex() - key = es2.HashOf(keys...) - lookupResource.EsID = key - lookupResource.EsIndex = idx - err = s.es.Delete(key, idx) - if err != nil { - s.logger.Error("failed to delete lookup from open-search", zap.Error(err)) - return - } - } - - s.logger.Info("deleted old resources", zap.Int("deleted_count", deletedCount), zap.String("connection_id", connectionId)) - } - } - - return -} - func (s *Scheduler) cleanupDescribeResourcesForConnectionAndResourceType(IntegrationID, resourceType string) error { root := make(map[string]any) root["query"] = map[string]any{ diff --git a/services/describe/server.go b/services/describe/server.go index bd6e37552..9566c78a2 100644 --- a/services/describe/server.go +++ b/services/describe/server.go @@ -6,6 +6,8 @@ import ( "errors" "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/opengovern/opencomply/pkg/types" + "golang.org/x/net/context" "net/http" "regexp" "sort" @@ -3843,7 +3845,11 @@ func (h HttpServer) PurgeSampleData(c echo.Context) error { ids = append(ids, i) } - go es.CleanupSummariesForJobs(h.Scheduler.logger, h.Scheduler.es, ids) + _, err = h.Scheduler.es.ES().Indices.Delete([]string{types.BenchmarkSummaryIndex}, h.Scheduler.es.ES().Indices.Delete.WithContext(context.Background())) + if err != nil { + h.Scheduler.logger.Error("failed to delete summary job", zap.Error(err)) + return echo.NewHTTPError(http.StatusInternalServerError, "Failed to delete summary jobs") + } return c.NoContent(http.StatusOK) }