Skip to content

Commit

Permalink
Change discovery runtime model field from Type -> Namespace
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Eckhart <[email protected]>
  • Loading branch information
kgeckhart committed Dec 5, 2024
1 parent 49a296a commit 4a59163
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions pkg/clients/tagging/v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)),
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/clients/tagging/v1/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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}},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/clients/tagging/v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)),
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/clients/tagging/v2/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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}},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/job/cloudwatchrunner/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions pkg/job/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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...)
Expand Down
2 changes: 1 addition & 1 deletion pkg/job/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion pkg/job/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
24 changes: 12 additions & 12 deletions pkg/job/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
Expand Down Expand Up @@ -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"},
},
Expand Down Expand Up @@ -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"},
},
Expand Down Expand Up @@ -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"},
},
Expand Down Expand Up @@ -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"},
},
Expand Down Expand Up @@ -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"},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type JobsConfig struct {

type DiscoveryJob struct {
Regions []string
Type string
Namespace string
Roles []Role
SearchTags []SearchTag
CustomTags []Tag
Expand Down

0 comments on commit 4a59163

Please sign in to comment.