Skip to content

Commit 15f1631

Browse files
Change discovery runtime model field from Type -> Namespace (#1587)
Signed-off-by: Kyle Eckhart <[email protected]> Co-authored-by: Cristian Greco <[email protected]>
1 parent b95099a commit 15f1631

File tree

11 files changed

+37
-37
lines changed

11 files changed

+37
-37
lines changed

pkg/clients/tagging/v1/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func NewClient(
7575
}
7676

7777
func (c client) GetResources(ctx context.Context, job model.DiscoveryJob, region string) ([]*model.TaggedResource, error) {
78-
svc := config.SupportedServices.GetService(job.Type)
78+
svc := config.SupportedServices.GetService(job.Namespace)
7979
var resources []*model.TaggedResource
8080
shouldHaveDiscoveredResources := false
8181

@@ -112,7 +112,7 @@ func (c client) GetResources(ctx context.Context, job model.DiscoveryJob, region
112112
for _, resourceTagMapping := range page.ResourceTagMappingList {
113113
resource := model.TaggedResource{
114114
ARN: aws.StringValue(resourceTagMapping.ResourceARN),
115-
Namespace: job.Type,
115+
Namespace: job.Namespace,
116116
Region: region,
117117
Tags: make([]model.Tag, 0, len(resourceTagMapping.Tags)),
118118
}

pkg/clients/tagging/v1/filters.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ var ServiceFilters = map[string]ServiceFilter{
107107
for _, asg := range page.AutoScalingGroups {
108108
resource := model.TaggedResource{
109109
ARN: aws.StringValue(asg.AutoScalingGroupARN),
110-
Namespace: job.Type,
110+
Namespace: job.Namespace,
111111
Region: region,
112112
}
113113

@@ -194,7 +194,7 @@ var ServiceFilters = map[string]ServiceFilter{
194194
for _, ec2Spot := range page.SpotFleetRequestConfigs {
195195
resource := model.TaggedResource{
196196
ARN: aws.StringValue(ec2Spot.SpotFleetRequestId),
197-
Namespace: job.Type,
197+
Namespace: job.Namespace,
198198
Region: region,
199199
}
200200

@@ -227,7 +227,7 @@ var ServiceFilters = map[string]ServiceFilter{
227227
for _, ws := range page.Workspaces {
228228
resource := model.TaggedResource{
229229
ARN: aws.StringValue(ws.Arn),
230-
Namespace: job.Type,
230+
Namespace: job.Namespace,
231231
Region: region,
232232
}
233233

@@ -260,7 +260,7 @@ var ServiceFilters = map[string]ServiceFilter{
260260
for _, gwa := range page.Gateways {
261261
resource := model.TaggedResource{
262262
ARN: fmt.Sprintf("%s/%s", *gwa.GatewayId, *gwa.GatewayName),
263-
Namespace: job.Type,
263+
Namespace: job.Namespace,
264264
Region: region,
265265
}
266266

@@ -300,7 +300,7 @@ var ServiceFilters = map[string]ServiceFilter{
300300
for _, tgwa := range page.TransitGatewayAttachments {
301301
resource := model.TaggedResource{
302302
ARN: fmt.Sprintf("%s/%s", *tgwa.TransitGatewayId, *tgwa.TransitGatewayAttachmentId),
303-
Namespace: job.Type,
303+
Namespace: job.Namespace,
304304
Region: region,
305305
}
306306

@@ -354,7 +354,7 @@ var ServiceFilters = map[string]ServiceFilter{
354354
if protectedResource.Region == region || (protectedResource.Region == "" && region == "us-east-1") {
355355
taggedResource := &model.TaggedResource{
356356
ARN: protectedResourceArn,
357-
Namespace: job.Type,
357+
Namespace: job.Namespace,
358358
Region: region,
359359
Tags: []model.Tag{{Key: "ProtectionArn", Value: protectionArn}},
360360
}

pkg/clients/tagging/v2/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func NewClient(
7575
}
7676

7777
func (c client) GetResources(ctx context.Context, job model.DiscoveryJob, region string) ([]*model.TaggedResource, error) {
78-
svc := config.SupportedServices.GetService(job.Type)
78+
svc := config.SupportedServices.GetService(job.Namespace)
7979
var resources []*model.TaggedResource
8080
shouldHaveDiscoveredResources := false
8181

@@ -119,7 +119,7 @@ func (c client) GetResources(ctx context.Context, job model.DiscoveryJob, region
119119
for _, resourceTagMapping := range page.ResourceTagMappingList {
120120
resource := model.TaggedResource{
121121
ARN: *resourceTagMapping.ResourceARN,
122-
Namespace: job.Type,
122+
Namespace: job.Namespace,
123123
Region: region,
124124
Tags: make([]model.Tag, 0, len(resourceTagMapping.Tags)),
125125
}

pkg/clients/tagging/v2/filters.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ var ServiceFilters = map[string]ServiceFilter{
116116
for _, asg := range page.AutoScalingGroups {
117117
resource := model.TaggedResource{
118118
ARN: *asg.AutoScalingGroupARN,
119-
Namespace: job.Type,
119+
Namespace: job.Namespace,
120120
Region: region,
121121
}
122122

@@ -209,7 +209,7 @@ var ServiceFilters = map[string]ServiceFilter{
209209
for _, ec2Spot := range page.SpotFleetRequestConfigs {
210210
resource := model.TaggedResource{
211211
ARN: *ec2Spot.SpotFleetRequestId,
212-
Namespace: job.Type,
212+
Namespace: job.Namespace,
213213
Region: region,
214214
}
215215

@@ -244,7 +244,7 @@ var ServiceFilters = map[string]ServiceFilter{
244244
for _, ws := range page.Workspaces {
245245
resource := model.TaggedResource{
246246
ARN: *ws.Arn,
247-
Namespace: job.Type,
247+
Namespace: job.Namespace,
248248
Region: region,
249249
}
250250

@@ -279,7 +279,7 @@ var ServiceFilters = map[string]ServiceFilter{
279279
for _, gwa := range page.Gateways {
280280
resource := model.TaggedResource{
281281
ARN: fmt.Sprintf("%s/%s", *gwa.GatewayId, *gwa.GatewayName),
282-
Namespace: job.Type,
282+
Namespace: job.Namespace,
283283
Region: region,
284284
}
285285

@@ -320,7 +320,7 @@ var ServiceFilters = map[string]ServiceFilter{
320320
for _, tgwa := range page.TransitGatewayAttachments {
321321
resource := model.TaggedResource{
322322
ARN: fmt.Sprintf("%s/%s", *tgwa.TransitGatewayId, *tgwa.TransitGatewayAttachmentId),
323-
Namespace: job.Type,
323+
Namespace: job.Namespace,
324324
Region: region,
325325
}
326326

@@ -379,7 +379,7 @@ var ServiceFilters = map[string]ServiceFilter{
379379
if protectedResource.Region == region || (protectedResource.Region == "" && region == "us-east-1") {
380380
taggedResource := &model.TaggedResource{
381381
ARN: protectedResourceArn,
382-
Namespace: job.Type,
382+
Namespace: job.Namespace,
383383
Region: region,
384384
Tags: []model.Tag{{Key: "ProtectionArn", Value: protectionArn}},
385385
}

pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ func (c *ScrapeConf) toModelConfig() model.JobsConfig {
412412

413413
job := model.DiscoveryJob{}
414414
job.Regions = discoveryJob.Regions
415-
job.Type = svc.Namespace
415+
job.Namespace = svc.Namespace
416416
job.DimensionNameRequirements = discoveryJob.DimensionNameRequirements
417417
job.RecentlyActiveOnly = discoveryJob.RecentlyActiveOnly
418418
job.RoundingPeriod = discoveryJob.RoundingPeriod

pkg/job/cloudwatchrunner/discovery.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type DiscoveryJob struct {
2323
}
2424

2525
func (d DiscoveryJob) Namespace() string {
26-
return d.Job.Type
26+
return d.Job.Namespace
2727
}
2828

2929
func (d DiscoveryJob) CustomTags() []model.Tag {
@@ -32,7 +32,7 @@ func (d DiscoveryJob) CustomTags() []model.Tag {
3232

3333
func (d DiscoveryJob) listMetricsParams() listmetrics.ProcessingParams {
3434
return listmetrics.ProcessingParams{
35-
Namespace: d.Job.Type,
35+
Namespace: d.Job.Namespace,
3636
Metrics: d.Job.Metrics,
3737
RecentlyActiveOnly: d.Job.RecentlyActiveOnly,
3838
DimensionNameRequirements: d.Job.DimensionNameRequirements,

pkg/job/discovery.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ func runDiscoveryJob(
5757
}
5858

5959
if len(resources) == 0 {
60-
logger.Debug("No tagged resources", "region", region, "namespace", job.Type)
60+
logger.Debug("No tagged resources", "region", region, "namespace", job.Namespace)
6161
}
6262

63-
svc := config.SupportedServices.GetService(job.Type)
63+
svc := config.SupportedServices.GetService(job.Namespace)
6464
getMetricDatas := getMetricDataForQueries(ctx, logger, job, svc, clientCloudwatch, resources)
6565
if len(getMetricDatas) == 0 {
6666
logger.Info("No metrics data found")
@@ -106,7 +106,7 @@ func getMetricDataForQueries(
106106
defer wg.Done()
107107

108108
err := clientCloudwatch.ListMetrics(ctx, svc.Namespace, metric, discoveryJob.RecentlyActiveOnly, func(page []*model.Metric) {
109-
data := getFilteredMetricDatas(logger, discoveryJob.Type, discoveryJob.ExportedTagsOnMetrics, page, discoveryJob.DimensionNameRequirements, metric, assoc)
109+
data := getFilteredMetricDatas(logger, discoveryJob.Namespace, discoveryJob.ExportedTagsOnMetrics, page, discoveryJob.DimensionNameRequirements, metric, assoc)
110110

111111
mux.Lock()
112112
getMetricDatas = append(getMetricDatas, data...)

pkg/job/scrape.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func ScrapeAwsData(
4444
wg.Add(1)
4545
go func(discoveryJob model.DiscoveryJob, region string, role model.Role) {
4646
defer wg.Done()
47-
jobLogger := logger.With("job_type", discoveryJob.Type, "region", region, "arn", role.RoleArn)
47+
jobLogger := logger.With("namespace", discoveryJob.Namespace, "region", region, "arn", role.RoleArn)
4848
accountID, err := factory.GetAccountClient(region, role).GetAccount(ctx)
4949
if err != nil {
5050
jobLogger.Error("Couldn't get account Id", "err", err)

pkg/job/scraper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (s Scraper) Scrape(ctx context.Context) ([]model.TaggedResourceResult, []mo
108108

109109
var namespace string
110110
jobAction(s.logger, job, func(job model.DiscoveryJob) {
111-
namespace = job.Type
111+
namespace = job.Namespace
112112
}, func(job model.CustomNamespaceJob) {
113113
namespace = job.Namespace
114114
})

pkg/job/scraper_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ func TestScrapeRunner_Run(t *testing.T) {
9696
jobsCfg: model.JobsConfig{
9797
DiscoveryJobs: []model.DiscoveryJob{
9898
{
99-
Regions: []string{"us-east-1"},
100-
Type: "aws-namespace",
99+
Regions: []string{"us-east-1"},
100+
Namespace: "aws-namespace",
101101
Roles: []model.Role{
102102
{RoleArn: "aws-arn-1", ExternalID: "external-id-1"},
103103
},
@@ -202,8 +202,8 @@ func TestScrapeRunner_Run(t *testing.T) {
202202
jobsCfg: model.JobsConfig{
203203
DiscoveryJobs: []model.DiscoveryJob{
204204
{
205-
Regions: []string{"us-east-1"},
206-
Type: "aws-namespace",
205+
Regions: []string{"us-east-1"},
206+
Namespace: "aws-namespace",
207207
Roles: []model.Role{
208208
{RoleArn: "aws-arn-1", ExternalID: "external-id-1"},
209209
},
@@ -295,8 +295,8 @@ func TestScrapeRunner_Run(t *testing.T) {
295295
jobsCfg: model.JobsConfig{
296296
DiscoveryJobs: []model.DiscoveryJob{
297297
{
298-
Regions: []string{"us-east-1"},
299-
Type: "aws-namespace",
298+
Regions: []string{"us-east-1"},
299+
Namespace: "aws-namespace",
300300
Roles: []model.Role{
301301
{RoleArn: "aws-arn-1", ExternalID: "external-id-1"},
302302
},
@@ -326,8 +326,8 @@ func TestScrapeRunner_Run(t *testing.T) {
326326
jobsCfg: model.JobsConfig{
327327
DiscoveryJobs: []model.DiscoveryJob{
328328
{
329-
Regions: []string{"us-east-1"},
330-
Type: "aws-namespace",
329+
Regions: []string{"us-east-1"},
330+
Namespace: "aws-namespace",
331331
Roles: []model.Role{
332332
{RoleArn: "aws-arn-1", ExternalID: "external-id-1"},
333333
},
@@ -384,8 +384,8 @@ func TestScrapeRunner_Run(t *testing.T) {
384384
jobsCfg: model.JobsConfig{
385385
DiscoveryJobs: []model.DiscoveryJob{
386386
{
387-
Regions: []string{"us-east-1"},
388-
Type: "aws-namespace",
387+
Regions: []string{"us-east-1"},
388+
Namespace: "aws-namespace",
389389
Roles: []model.Role{
390390
{RoleArn: "aws-arn-1", ExternalID: "external-id-1"},
391391
},
@@ -453,8 +453,8 @@ func TestScrapeRunner_Run(t *testing.T) {
453453
jobsCfg: model.JobsConfig{
454454
DiscoveryJobs: []model.DiscoveryJob{
455455
{
456-
Regions: []string{"us-east-1"},
457-
Type: "aws-namespace",
456+
Regions: []string{"us-east-1"},
457+
Namespace: "aws-namespace",
458458
Roles: []model.Role{
459459
{RoleArn: "aws-arn-1", ExternalID: "external-id-1"},
460460
},

0 commit comments

Comments
 (0)