diff --git a/pkg/clients/tagging/v1/client.go b/pkg/clients/tagging/v1/client.go index 9e997b77b..aff528056 100644 --- a/pkg/clients/tagging/v1/client.go +++ b/pkg/clients/tagging/v1/client.go @@ -75,7 +75,7 @@ func NewClient( } func (c client) GetResources(ctx context.Context, job model.DiscoveryJob, region string) ([]*model.TaggedResource, error) { - svc := config.SupportedServices.GetService(job.Type) + svc := config.SupportedServices.GetService(job.Namespace) var resources []*model.TaggedResource shouldHaveDiscoveredResources := false @@ -112,7 +112,7 @@ func (c client) GetResources(ctx context.Context, job model.DiscoveryJob, region for _, resourceTagMapping := range page.ResourceTagMappingList { resource := model.TaggedResource{ ARN: aws.StringValue(resourceTagMapping.ResourceARN), - Namespace: job.Type, + Namespace: job.Namespace, Region: region, Tags: make([]model.Tag, 0, len(resourceTagMapping.Tags)), } diff --git a/pkg/clients/tagging/v1/filters.go b/pkg/clients/tagging/v1/filters.go index 0370e7c29..b02820450 100644 --- a/pkg/clients/tagging/v1/filters.go +++ b/pkg/clients/tagging/v1/filters.go @@ -107,7 +107,7 @@ var ServiceFilters = map[string]ServiceFilter{ for _, asg := range page.AutoScalingGroups { resource := model.TaggedResource{ ARN: aws.StringValue(asg.AutoScalingGroupARN), - Namespace: job.Type, + Namespace: job.Namespace, Region: region, } @@ -194,7 +194,7 @@ var ServiceFilters = map[string]ServiceFilter{ for _, ec2Spot := range page.SpotFleetRequestConfigs { resource := model.TaggedResource{ ARN: aws.StringValue(ec2Spot.SpotFleetRequestId), - Namespace: job.Type, + Namespace: job.Namespace, Region: region, } @@ -227,7 +227,7 @@ var ServiceFilters = map[string]ServiceFilter{ for _, ws := range page.Workspaces { resource := model.TaggedResource{ ARN: aws.StringValue(ws.Arn), - Namespace: job.Type, + Namespace: job.Namespace, Region: region, } @@ -260,7 +260,7 @@ var ServiceFilters = map[string]ServiceFilter{ for _, gwa := range page.Gateways { resource := model.TaggedResource{ ARN: fmt.Sprintf("%s/%s", *gwa.GatewayId, *gwa.GatewayName), - Namespace: job.Type, + Namespace: job.Namespace, Region: region, } @@ -300,7 +300,7 @@ var ServiceFilters = map[string]ServiceFilter{ for _, tgwa := range page.TransitGatewayAttachments { resource := model.TaggedResource{ ARN: fmt.Sprintf("%s/%s", *tgwa.TransitGatewayId, *tgwa.TransitGatewayAttachmentId), - Namespace: job.Type, + Namespace: job.Namespace, Region: region, } @@ -354,7 +354,7 @@ var ServiceFilters = map[string]ServiceFilter{ if protectedResource.Region == region || (protectedResource.Region == "" && region == "us-east-1") { taggedResource := &model.TaggedResource{ ARN: protectedResourceArn, - Namespace: job.Type, + Namespace: job.Namespace, Region: region, Tags: []model.Tag{{Key: "ProtectionArn", Value: protectionArn}}, } diff --git a/pkg/clients/tagging/v2/client.go b/pkg/clients/tagging/v2/client.go index 54bacf7d2..0558a66a3 100644 --- a/pkg/clients/tagging/v2/client.go +++ b/pkg/clients/tagging/v2/client.go @@ -75,7 +75,7 @@ func NewClient( } func (c client) GetResources(ctx context.Context, job model.DiscoveryJob, region string) ([]*model.TaggedResource, error) { - svc := config.SupportedServices.GetService(job.Type) + svc := config.SupportedServices.GetService(job.Namespace) var resources []*model.TaggedResource shouldHaveDiscoveredResources := false @@ -119,7 +119,7 @@ func (c client) GetResources(ctx context.Context, job model.DiscoveryJob, region for _, resourceTagMapping := range page.ResourceTagMappingList { resource := model.TaggedResource{ ARN: *resourceTagMapping.ResourceARN, - Namespace: job.Type, + Namespace: job.Namespace, Region: region, Tags: make([]model.Tag, 0, len(resourceTagMapping.Tags)), } diff --git a/pkg/clients/tagging/v2/filters.go b/pkg/clients/tagging/v2/filters.go index 0327fddd6..8be43eb62 100644 --- a/pkg/clients/tagging/v2/filters.go +++ b/pkg/clients/tagging/v2/filters.go @@ -116,7 +116,7 @@ var ServiceFilters = map[string]ServiceFilter{ for _, asg := range page.AutoScalingGroups { resource := model.TaggedResource{ ARN: *asg.AutoScalingGroupARN, - Namespace: job.Type, + Namespace: job.Namespace, Region: region, } @@ -209,7 +209,7 @@ var ServiceFilters = map[string]ServiceFilter{ for _, ec2Spot := range page.SpotFleetRequestConfigs { resource := model.TaggedResource{ ARN: *ec2Spot.SpotFleetRequestId, - Namespace: job.Type, + Namespace: job.Namespace, Region: region, } @@ -244,7 +244,7 @@ var ServiceFilters = map[string]ServiceFilter{ for _, ws := range page.Workspaces { resource := model.TaggedResource{ ARN: *ws.Arn, - Namespace: job.Type, + Namespace: job.Namespace, Region: region, } @@ -279,7 +279,7 @@ var ServiceFilters = map[string]ServiceFilter{ for _, gwa := range page.Gateways { resource := model.TaggedResource{ ARN: fmt.Sprintf("%s/%s", *gwa.GatewayId, *gwa.GatewayName), - Namespace: job.Type, + Namespace: job.Namespace, Region: region, } @@ -320,7 +320,7 @@ var ServiceFilters = map[string]ServiceFilter{ for _, tgwa := range page.TransitGatewayAttachments { resource := model.TaggedResource{ ARN: fmt.Sprintf("%s/%s", *tgwa.TransitGatewayId, *tgwa.TransitGatewayAttachmentId), - Namespace: job.Type, + Namespace: job.Namespace, Region: region, } @@ -379,7 +379,7 @@ var ServiceFilters = map[string]ServiceFilter{ if protectedResource.Region == region || (protectedResource.Region == "" && region == "us-east-1") { taggedResource := &model.TaggedResource{ ARN: protectedResourceArn, - Namespace: job.Type, + Namespace: job.Namespace, Region: region, Tags: []model.Tag{{Key: "ProtectionArn", Value: protectionArn}}, } diff --git a/pkg/config/config.go b/pkg/config/config.go index 8a60377eb..e6efa0195 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -412,7 +412,7 @@ func (c *ScrapeConf) toModelConfig() model.JobsConfig { job := model.DiscoveryJob{} job.Regions = discoveryJob.Regions - job.Type = svc.Namespace + job.Namespace = svc.Namespace job.DimensionNameRequirements = discoveryJob.DimensionNameRequirements job.RecentlyActiveOnly = discoveryJob.RecentlyActiveOnly job.RoundingPeriod = discoveryJob.RoundingPeriod diff --git a/pkg/job/cloudwatchrunner/discovery.go b/pkg/job/cloudwatchrunner/discovery.go index 02d7b1e1e..582e0cfc6 100644 --- a/pkg/job/cloudwatchrunner/discovery.go +++ b/pkg/job/cloudwatchrunner/discovery.go @@ -23,7 +23,7 @@ type DiscoveryJob struct { } func (d DiscoveryJob) Namespace() string { - return d.Job.Type + return d.Job.Namespace } func (d DiscoveryJob) CustomTags() []model.Tag { @@ -32,7 +32,7 @@ func (d DiscoveryJob) CustomTags() []model.Tag { func (d DiscoveryJob) listMetricsParams() listmetrics.ProcessingParams { return listmetrics.ProcessingParams{ - Namespace: d.Job.Type, + Namespace: d.Job.Namespace, Metrics: d.Job.Metrics, RecentlyActiveOnly: d.Job.RecentlyActiveOnly, DimensionNameRequirements: d.Job.DimensionNameRequirements, diff --git a/pkg/job/discovery.go b/pkg/job/discovery.go index 86485d6d3..d4624a71d 100644 --- a/pkg/job/discovery.go +++ b/pkg/job/discovery.go @@ -57,10 +57,10 @@ func runDiscoveryJob( } if len(resources) == 0 { - logger.Debug("No tagged resources", "region", region, "namespace", job.Type) + logger.Debug("No tagged resources", "region", region, "namespace", job.Namespace) } - svc := config.SupportedServices.GetService(job.Type) + svc := config.SupportedServices.GetService(job.Namespace) getMetricDatas := getMetricDataForQueries(ctx, logger, job, svc, clientCloudwatch, resources) if len(getMetricDatas) == 0 { logger.Info("No metrics data found") @@ -106,7 +106,7 @@ func getMetricDataForQueries( defer wg.Done() err := clientCloudwatch.ListMetrics(ctx, svc.Namespace, metric, discoveryJob.RecentlyActiveOnly, func(page []*model.Metric) { - data := getFilteredMetricDatas(logger, discoveryJob.Type, discoveryJob.ExportedTagsOnMetrics, page, discoveryJob.DimensionNameRequirements, metric, assoc) + data := getFilteredMetricDatas(logger, discoveryJob.Namespace, discoveryJob.ExportedTagsOnMetrics, page, discoveryJob.DimensionNameRequirements, metric, assoc) mux.Lock() getMetricDatas = append(getMetricDatas, data...) diff --git a/pkg/job/scrape.go b/pkg/job/scrape.go index f6e262d9a..66a4058b9 100644 --- a/pkg/job/scrape.go +++ b/pkg/job/scrape.go @@ -44,7 +44,7 @@ func ScrapeAwsData( wg.Add(1) go func(discoveryJob model.DiscoveryJob, region string, role model.Role) { defer wg.Done() - jobLogger := logger.With("job_type", discoveryJob.Type, "region", region, "arn", role.RoleArn) + jobLogger := logger.With("namespace", discoveryJob.Namespace, "region", region, "arn", role.RoleArn) accountID, err := factory.GetAccountClient(region, role).GetAccount(ctx) if err != nil { jobLogger.Error(err, "Couldn't get account Id") diff --git a/pkg/job/scraper.go b/pkg/job/scraper.go index 4719abb1f..08dabb8de 100644 --- a/pkg/job/scraper.go +++ b/pkg/job/scraper.go @@ -108,7 +108,7 @@ func (s Scraper) Scrape(ctx context.Context) ([]model.TaggedResourceResult, []mo var namespace string jobAction(s.logger, job, func(job model.DiscoveryJob) { - namespace = job.Type + namespace = job.Namespace }, func(job model.CustomNamespaceJob) { namespace = job.Namespace }) diff --git a/pkg/job/scraper_test.go b/pkg/job/scraper_test.go index f8c8be75e..a66a8aa8b 100644 --- a/pkg/job/scraper_test.go +++ b/pkg/job/scraper_test.go @@ -95,8 +95,8 @@ func TestScrapeRunner_Run(t *testing.T) { jobsCfg: model.JobsConfig{ DiscoveryJobs: []model.DiscoveryJob{ { - Regions: []string{"us-east-1"}, - Type: "aws-namespace", + Regions: []string{"us-east-1"}, + Namespace: "aws-namespace", Roles: []model.Role{ {RoleArn: "aws-arn-1", ExternalID: "external-id-1"}, }, @@ -201,8 +201,8 @@ func TestScrapeRunner_Run(t *testing.T) { jobsCfg: model.JobsConfig{ DiscoveryJobs: []model.DiscoveryJob{ { - Regions: []string{"us-east-1"}, - Type: "aws-namespace", + Regions: []string{"us-east-1"}, + Namespace: "aws-namespace", Roles: []model.Role{ {RoleArn: "aws-arn-1", ExternalID: "external-id-1"}, }, @@ -294,8 +294,8 @@ func TestScrapeRunner_Run(t *testing.T) { jobsCfg: model.JobsConfig{ DiscoveryJobs: []model.DiscoveryJob{ { - Regions: []string{"us-east-1"}, - Type: "aws-namespace", + Regions: []string{"us-east-1"}, + Namespace: "aws-namespace", Roles: []model.Role{ {RoleArn: "aws-arn-1", ExternalID: "external-id-1"}, }, @@ -325,8 +325,8 @@ func TestScrapeRunner_Run(t *testing.T) { jobsCfg: model.JobsConfig{ DiscoveryJobs: []model.DiscoveryJob{ { - Regions: []string{"us-east-1"}, - Type: "aws-namespace", + Regions: []string{"us-east-1"}, + Namespace: "aws-namespace", Roles: []model.Role{ {RoleArn: "aws-arn-1", ExternalID: "external-id-1"}, }, @@ -383,8 +383,8 @@ func TestScrapeRunner_Run(t *testing.T) { jobsCfg: model.JobsConfig{ DiscoveryJobs: []model.DiscoveryJob{ { - Regions: []string{"us-east-1"}, - Type: "aws-namespace", + Regions: []string{"us-east-1"}, + Namespace: "aws-namespace", Roles: []model.Role{ {RoleArn: "aws-arn-1", ExternalID: "external-id-1"}, }, @@ -452,8 +452,8 @@ func TestScrapeRunner_Run(t *testing.T) { jobsCfg: model.JobsConfig{ DiscoveryJobs: []model.DiscoveryJob{ { - Regions: []string{"us-east-1"}, - Type: "aws-namespace", + Regions: []string{"us-east-1"}, + Namespace: "aws-namespace", Roles: []model.Role{ {RoleArn: "aws-arn-1", ExternalID: "external-id-1"}, }, diff --git a/pkg/model/model.go b/pkg/model/model.go index ab19d650a..deb2dbd53 100644 --- a/pkg/model/model.go +++ b/pkg/model/model.go @@ -32,7 +32,7 @@ type JobsConfig struct { type DiscoveryJob struct { Regions []string - Type string + Namespace string Roles []Role SearchTags []SearchTag CustomTags []Tag