Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change discovery runtime model field from Type -> Namespace #1587

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("Couldn't get account Id", "err", err)
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 @@ -96,8 +96,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 @@ -202,8 +202,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 @@ -295,8 +295,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 @@ -326,8 +326,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 @@ -384,8 +384,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 @@ -453,8 +453,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
Loading