Skip to content

Commit

Permalink
chore: enhance fetch resource error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
rahmatrhd committed Feb 28, 2024
1 parent 4ab6aef commit 2f7360c
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions core/provider/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (s *Service) FetchResources(ctx context.Context) error {
return err
}

failedProviders := make([]string, 0)
failedProviders := map[string]error{}
for _, p := range providers {
startTime := time.Now()
s.logger.Info(ctx, "fetching resources", "provider_urn", p.URN)
Expand All @@ -269,16 +269,21 @@ func (s *Service) FetchResources(ctx context.Context) error {
}
s.logger.Info(ctx, "resources added", "provider_urn", p.URN, "count", len(flattenResources(resources)))
if err := s.resourceService.BulkUpsert(ctx, resources); err != nil {
failedProviders = append(failedProviders, p.URN)
failedProviders[p.URN] = err
s.logger.Error(ctx, "failed to add resources", "provider_urn", p.URN, "error", err)
}
s.logger.Info(ctx, "fetching resources completed", "provider_urn", p.URN, "duration", time.Since(startTime))
}

if len(failedProviders) == 0 {
return nil
if len(failedProviders) > 0 {
var urns []string
for providerURN, err := range failedProviders {
s.logger.Error(ctx, "failed to add resources for provider", "provider_urn", providerURN, "error", err)
urns = append(urns, providerURN)
}
return fmt.Errorf("failed to add resources for providers: %v", urns)
}
return fmt.Errorf("failed to add resources %s - %v", "providers", failedProviders)
return nil
}

func (s *Service) GetRoles(ctx context.Context, id string, resourceType string) ([]*domain.Role, error) {
Expand Down Expand Up @@ -596,7 +601,7 @@ func (s *Service) getResources(ctx context.Context, p *domain.Provider) ([]*doma
existingProviderResources := map[string]bool{}
for _, r := range flattenedProviderResources {
for _, er := range existingGuardianResources {
if er.URN == r.URN {
if er.Type == r.Type && er.URN == r.URN {
if existingDetails := er.Details; existingDetails != nil {
if r.Details != nil {
for key, value := range existingDetails {
Expand Down

0 comments on commit 2f7360c

Please sign in to comment.