From c6b81edbe74354852e9b7b616262006425b97667 Mon Sep 17 00:00:00 2001 From: jradhakrishnan Date: Tue, 22 Aug 2023 16:49:26 +0530 Subject: [PATCH 1/3] Add default constructor to fix deserialization error --- .../java/ai/asserts/aws/account/AWSAccount.java | 16 +++++++++------- .../account/SingleInstanceAccountProvider.java | 4 +++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/ai/asserts/aws/account/AWSAccount.java b/src/main/java/ai/asserts/aws/account/AWSAccount.java index bbed880e..12908639 100644 --- a/src/main/java/ai/asserts/aws/account/AWSAccount.java +++ b/src/main/java/ai/asserts/aws/account/AWSAccount.java @@ -9,6 +9,7 @@ import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.SuperBuilder; @@ -21,22 +22,23 @@ @EqualsAndHashCode @ToString @SuperBuilder +@NoArgsConstructor public class AWSAccount { @Setter private String tenant; // Use different json field name to match property from API Response @JsonProperty("accountID") - private final String accountId; - private final String name; + private String accountId; + private String name; @ToString.Exclude - private final String accessId; + private String accessId; @ToString.Exclude - private final String secretKey; + private String secretKey; // Use different json field name to match property from API Response @JsonProperty("assumeRoleARN") - private final String assumeRole; - private final String externalId; - private final boolean paused; + private String assumeRole; + private String externalId; + private boolean paused; @Builder.Default private final Set regions = new TreeSet<>(); diff --git a/src/main/java/ai/asserts/aws/account/SingleInstanceAccountProvider.java b/src/main/java/ai/asserts/aws/account/SingleInstanceAccountProvider.java index 03f4f6ab..8d94ed17 100644 --- a/src/main/java/ai/asserts/aws/account/SingleInstanceAccountProvider.java +++ b/src/main/java/ai/asserts/aws/account/SingleInstanceAccountProvider.java @@ -15,6 +15,7 @@ import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.ToString; import lombok.experimental.SuperBuilder; import lombok.extern.slf4j.Slf4j; @@ -97,8 +98,8 @@ private Set getAccountsInternal() { AWSAccount ac = new AWSAccount(tenantName, accountId, null, null, null, regions); accountRegions.putIfAbsent(ac.getAccountId(), ac); - log.info("Scraping AWS Accounts {}", accountRegions); } + log.info("Scraping AWS Accounts {}", accountRegions); return Sets.newHashSet(accountRegions.values()); } @@ -111,6 +112,7 @@ String getTenantName() { @Getter @SuperBuilder @ToString + @NoArgsConstructor public static class CloudwatchConfigs { List cloudWatchConfigs; } From fce9503b82f5e7dd0c1885226355be99c5c1a20d Mon Sep 17 00:00:00 2001 From: jradhakrishnan Date: Tue, 22 Aug 2023 16:50:22 +0530 Subject: [PATCH 2/3] Set `AWSAccount` in context instead of just tenant name --- .../java/ai/asserts/aws/MetricNameUtil.java | 2 + .../java/ai/asserts/aws/TaskExecutorUtil.java | 7 +-- .../aws/cloudwatch/alarms/AlarmFetcher.java | 2 +- .../cloudwatch/query/MetricQueryProvider.java | 2 +- .../exporter/ApiGatewayToLambdaBuilder.java | 9 ++-- .../aws/exporter/DynamoDBExporter.java | 2 +- .../aws/exporter/EC2ToEBSVolumeExporter.java | 11 +++-- .../asserts/aws/exporter/ECSTaskProvider.java | 2 +- .../ai/asserts/aws/exporter/ECSTaskUtil.java | 5 +- .../ai/asserts/aws/exporter/EMRExporter.java | 2 +- .../exporter/KinesisAnalyticsExporter.java | 2 +- .../aws/exporter/KinesisFirehoseExporter.java | 2 +- .../aws/exporter/KinesisStreamExporter.java | 2 +- .../aws/exporter/LBToASGRelationBuilder.java | 2 +- .../aws/exporter/LBToECSRoutingBuilder.java | 2 +- .../exporter/LBToLambdaRoutingBuilder.java | 2 +- .../aws/exporter/LambdaCapacityExporter.java | 2 +- .../exporter/LambdaEventSourceExporter.java | 2 +- .../exporter/LambdaInvokeConfigExporter.java | 2 +- .../aws/exporter/LoadBalancerExporter.java | 2 +- .../aws/exporter/MetricSampleBuilder.java | 24 +++++++++- .../aws/exporter/MetricScrapeTask.java | 2 +- .../ai/asserts/aws/exporter/RDSExporter.java | 2 +- .../aws/exporter/RedshiftExporter.java | 2 +- .../aws/exporter/S3BucketExporter.java | 2 +- .../aws/exporter/SNSTopicExporter.java | 2 +- .../aws/exporter/SQSQueueExporter.java | 2 +- .../exporter/TargetGroupLBMapProvider.java | 2 +- .../aws/lambda/LambdaFunctionBuilder.java | 2 +- .../aws/lambda/LambdaFunctionScraper.java | 2 +- .../asserts/aws/resource/ResourceMapper.java | 48 +++++++++---------- .../asserts/aws/exporter/ECSTaskUtilTest.java | 8 +++- .../aws/exporter/MetricSampleBuilderTest.java | 15 ++++-- .../aws/lambda/LambdaFunctionBuilderTest.java | 6 ++- .../aws/resource/ResourceMapperTest.java | 5 +- 35 files changed, 116 insertions(+), 72 deletions(-) diff --git a/src/main/java/ai/asserts/aws/MetricNameUtil.java b/src/main/java/ai/asserts/aws/MetricNameUtil.java index 33483c7e..b596cc4b 100644 --- a/src/main/java/ai/asserts/aws/MetricNameUtil.java +++ b/src/main/java/ai/asserts/aws/MetricNameUtil.java @@ -19,6 +19,8 @@ public class MetricNameUtil { public static final String SCRAPE_LATENCY_METRIC = "aws_exporter_milliseconds"; public static final String ASSERTS_ERROR_TYPE = "asserts_error_type"; public static final String TENANT = "tenant"; + public static final String ENV = "asserts_env"; + public static final String SITE = "asserts_site"; public static final String SCRAPE_ERROR_COUNT_METRIC = "aws_exporter_error_total"; public static final String SCRAPE_OPERATION_LABEL = "operation"; public static final String SCRAPE_REGION_LABEL = "region"; diff --git a/src/main/java/ai/asserts/aws/TaskExecutorUtil.java b/src/main/java/ai/asserts/aws/TaskExecutorUtil.java index 9fe345c2..b0accf3a 100644 --- a/src/main/java/ai/asserts/aws/TaskExecutorUtil.java +++ b/src/main/java/ai/asserts/aws/TaskExecutorUtil.java @@ -4,6 +4,7 @@ */ package ai.asserts.aws; +import ai.asserts.aws.account.AWSAccount; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; @@ -21,7 +22,7 @@ public class TaskExecutorUtil { private final TaskThreadPool taskThreadPool; private final AWSApiCallRateLimiter rateLimiter; - private static final ThreadLocal tenantName = new ThreadLocal<>(); + private static final ThreadLocal tenantName = new ThreadLocal<>(); public TaskExecutorUtil(@Qualifier("aws-api-calls-thread-pool") TaskThreadPool taskThreadPool, AWSApiCallRateLimiter rateLimiter) { @@ -29,7 +30,7 @@ public TaskExecutorUtil(@Qualifier("aws-api-calls-thread-pool") TaskThreadPool t this.rateLimiter = rateLimiter; } - public Future executeTenantTask(String tenant, TenantTask task) { + public Future executeTenantTask(AWSAccount tenant, TenantTask task) { return taskThreadPool.getExecutorService().submit(() -> { tenantName.set(tenant); try { @@ -53,7 +54,7 @@ public void awaitAll(List> futures, Consumer consumer) { }); } - public String getTenant() { + public AWSAccount getAccountDetails() { return tenantName.get(); } } diff --git a/src/main/java/ai/asserts/aws/cloudwatch/alarms/AlarmFetcher.java b/src/main/java/ai/asserts/aws/cloudwatch/alarms/AlarmFetcher.java index 63badc1d..dc3026a7 100644 --- a/src/main/java/ai/asserts/aws/cloudwatch/alarms/AlarmFetcher.java +++ b/src/main/java/ai/asserts/aws/cloudwatch/alarms/AlarmFetcher.java @@ -103,7 +103,7 @@ public void update() { continue; } accountRegion.getRegions().forEach(region -> - futures.add(taskExecutorUtil.executeTenantTask(accountRegion.getTenant(), + futures.add(taskExecutorUtil.executeTenantTask(accountRegion, new CollectionBuilderTask() { @Override public List call() { diff --git a/src/main/java/ai/asserts/aws/cloudwatch/query/MetricQueryProvider.java b/src/main/java/ai/asserts/aws/cloudwatch/query/MetricQueryProvider.java index 9d02e3f8..a4a436f0 100644 --- a/src/main/java/ai/asserts/aws/cloudwatch/query/MetricQueryProvider.java +++ b/src/main/java/ai/asserts/aws/cloudwatch/query/MetricQueryProvider.java @@ -102,7 +102,7 @@ Map>>> getQueriesInternal() { log.info("Will discover metrics and build metric queries for tenant {}, account {}", accountRegion.getTenant(), accountRegion.getAccountId()); accountRegion.getRegions().forEach(region -> futures.add( - taskExecutorUtil.executeTenantTask(accountRegion.getTenant(), new SimpleTenantTask() { + taskExecutorUtil.executeTenantTask(accountRegion, new SimpleTenantTask() { @Override public Void call() { buildQueries(scrapeConfig, region, accountRegion, account, queriesByAccount); diff --git a/src/main/java/ai/asserts/aws/exporter/ApiGatewayToLambdaBuilder.java b/src/main/java/ai/asserts/aws/exporter/ApiGatewayToLambdaBuilder.java index 3400038c..da08bcdc 100644 --- a/src/main/java/ai/asserts/aws/exporter/ApiGatewayToLambdaBuilder.java +++ b/src/main/java/ai/asserts/aws/exporter/ApiGatewayToLambdaBuilder.java @@ -96,7 +96,7 @@ public void update() { List>> futures = new ArrayList<>(); for (AWSAccount accountRegion : accountProvider.getAccounts()) { accountRegion.getRegions().forEach(region -> - futures.add(taskExecutorUtil.executeTenantTask(accountRegion.getTenant(), + futures.add(taskExecutorUtil.executeTenantTask(accountRegion, new CollectionBuilderTask() { @Override public List call() { @@ -182,10 +182,11 @@ private void captureIntegrations(ApiGatewayClient client, Set } Matcher matcher = LAMBDA_URI_PATTERN.matcher(uri); if (matcher.matches()) { + String tenant = taskExecutorUtil.getAccountDetails().getTenant(); ResourceRelation resourceRelation = ResourceRelation.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(tenant) .from(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(tenant) .type(ApiGateway) .name(restApi.name()) .id(restApi.id()) @@ -193,7 +194,7 @@ private void captureIntegrations(ApiGatewayClient client, Set .account(accountId) .build()) .to(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(tenant) .type(LambdaFunction) .name(matcher.group(4)) .region(matcher.group(2)) diff --git a/src/main/java/ai/asserts/aws/exporter/DynamoDBExporter.java b/src/main/java/ai/asserts/aws/exporter/DynamoDBExporter.java index 5b05f492..b1eab7ae 100644 --- a/src/main/java/ai/asserts/aws/exporter/DynamoDBExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/DynamoDBExporter.java @@ -83,7 +83,7 @@ public void update() { List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region -> futures.add( - taskExecutorUtil.executeTenantTask(account.getTenant(), new CollectionBuilderTask() { + taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask() { @Override public List call() { return buildSamples(region, account, allSamples); diff --git a/src/main/java/ai/asserts/aws/exporter/EC2ToEBSVolumeExporter.java b/src/main/java/ai/asserts/aws/exporter/EC2ToEBSVolumeExporter.java index 8ab3def2..f69e9582 100644 --- a/src/main/java/ai/asserts/aws/exporter/EC2ToEBSVolumeExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/EC2ToEBSVolumeExporter.java @@ -103,14 +103,14 @@ public void update() { List>> futures = new ArrayList<>(); List>> volumeFutures = new ArrayList<>(); accountProvider.getAccounts().forEach(awsAccount -> awsAccount.getRegions().forEach(region -> { - futures.add(taskExecutorUtil.executeTenantTask(awsAccount.getTenant(), new CollectionBuilderTask() { + futures.add(taskExecutorUtil.executeTenantTask(awsAccount, new CollectionBuilderTask() { @Override public List call() { return buildEC2InstanceMetrics(region, awsAccount); } })); volumeFutures.add( - taskExecutorUtil.executeTenantTask(awsAccount.getTenant(), + taskExecutorUtil.executeTenantTask(awsAccount, new CollectionBuilderTask() { @Override public List call() { @@ -156,17 +156,18 @@ private List buildResourceRelations(AWSAccount awsAccount, Str newAttachedVolumes.addAll(resp.volumes().stream() .flatMap(volume -> volume.attachments().stream()) .map(volumeAttachment -> { + String tenant = taskExecutorUtil.getAccountDetails().getTenant(); Resource ec2Instance = Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(tenant) .account(accountId) .region(region) .type(EC2Instance) .name(volumeAttachment.instanceId()) .build(); return ResourceRelation.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(tenant) .from(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(tenant) .account(accountId) .region(region) .type(EBSVolume) diff --git a/src/main/java/ai/asserts/aws/exporter/ECSTaskProvider.java b/src/main/java/ai/asserts/aws/exporter/ECSTaskProvider.java index 95103689..01e10ed3 100644 --- a/src/main/java/ai/asserts/aws/exporter/ECSTaskProvider.java +++ b/src/main/java/ai/asserts/aws/exporter/ECSTaskProvider.java @@ -147,7 +147,7 @@ public void run() { for (AWSAccount account : accountProvider.getAccounts()) { ScrapeConfig scrapeConfig = scrapeConfigProvider.getScrapeConfig(account.getTenant()); for (String region : account.getRegions()) { - taskExecutorUtil.executeTenantTask(account.getTenant(), new SimpleTenantTask() { + taskExecutorUtil.executeTenantTask(account, new SimpleTenantTask() { @Override public Void call() { Map> clusterWiseNewTasks = new HashMap<>(); diff --git a/src/main/java/ai/asserts/aws/exporter/ECSTaskUtil.java b/src/main/java/ai/asserts/aws/exporter/ECSTaskUtil.java index 5693112a..318b32f9 100644 --- a/src/main/java/ai/asserts/aws/exporter/ECSTaskUtil.java +++ b/src/main/java/ai/asserts/aws/exporter/ECSTaskUtil.java @@ -236,9 +236,10 @@ private LabelsBuilder getLabelsBuilder(AWSAccount account, Resource cluster, Opt LabelsBuilder labelsBuilder; taskSubnetMap.computeIfAbsent(taskResource.getName(), k -> getSubnetDetails(task, taskResource)); + String tenant = taskExecutorUtil.getAccountDetails().getTenant(); if (service.isPresent()) { labelsBuilder = Labels.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(tenant) .workload(service.get()) .taskId(taskResource.getName()) .pod(service.get() + "-" + taskResource.getName()) @@ -254,7 +255,7 @@ private LabelsBuilder getLabelsBuilder(AWSAccount account, Resource cluster, Opt .metricsPath("/metrics"); } else { labelsBuilder = Labels.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(tenant) .workload(taskDefResource.getName()) .taskId(taskResource.getName()) .pod(taskDefResource.getName() + "-" + taskResource.getName()) diff --git a/src/main/java/ai/asserts/aws/exporter/EMRExporter.java b/src/main/java/ai/asserts/aws/exporter/EMRExporter.java index 52557dd2..74d0d951 100644 --- a/src/main/java/ai/asserts/aws/exporter/EMRExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/EMRExporter.java @@ -71,7 +71,7 @@ public void update() { List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region -> futures.add( - taskExecutorUtil.executeTenantTask(account.getTenant(), new CollectionBuilderTask() { + taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask() { @Override public List call() { return buildSamples(region, account); diff --git a/src/main/java/ai/asserts/aws/exporter/KinesisAnalyticsExporter.java b/src/main/java/ai/asserts/aws/exporter/KinesisAnalyticsExporter.java index 022c7767..675d0c44 100644 --- a/src/main/java/ai/asserts/aws/exporter/KinesisAnalyticsExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/KinesisAnalyticsExporter.java @@ -77,7 +77,7 @@ public void update() { List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region -> futures.add( - taskExecutorUtil.executeTenantTask(account.getTenant(), new CollectionBuilderTask() { + taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask() { @Override public List call() { return buildSamples(region, account); diff --git a/src/main/java/ai/asserts/aws/exporter/KinesisFirehoseExporter.java b/src/main/java/ai/asserts/aws/exporter/KinesisFirehoseExporter.java index 8567290c..73e0ce3d 100644 --- a/src/main/java/ai/asserts/aws/exporter/KinesisFirehoseExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/KinesisFirehoseExporter.java @@ -90,7 +90,7 @@ public void update() { List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region -> futures.add( - taskExecutorUtil.executeTenantTask(account.getTenant(), new CollectionBuilderTask() { + taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask() { @Override public List call() { return buildMetricSamples(region, account); diff --git a/src/main/java/ai/asserts/aws/exporter/KinesisStreamExporter.java b/src/main/java/ai/asserts/aws/exporter/KinesisStreamExporter.java index f0c64b21..34698bba 100644 --- a/src/main/java/ai/asserts/aws/exporter/KinesisStreamExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/KinesisStreamExporter.java @@ -82,7 +82,7 @@ public void update() { List allSamples = new ArrayList<>(); List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region -> - futures.add(taskExecutorUtil.executeTenantTask(account.getTenant(), new CollectionBuilderTask() { + futures.add(taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask() { @Override public List call() { return buildSamples(region, account); diff --git a/src/main/java/ai/asserts/aws/exporter/LBToASGRelationBuilder.java b/src/main/java/ai/asserts/aws/exporter/LBToASGRelationBuilder.java index 12028e34..b0fccd69 100644 --- a/src/main/java/ai/asserts/aws/exporter/LBToASGRelationBuilder.java +++ b/src/main/java/ai/asserts/aws/exporter/LBToASGRelationBuilder.java @@ -97,7 +97,7 @@ public void updateRouting() { List>> futures = new ArrayList<>(); for (AWSAccount accountRegion : accountProvider.getAccounts()) { accountRegion.getRegions().forEach(region -> - futures.add(taskExecutorUtil.executeTenantTask(accountRegion.getTenant(), + futures.add(taskExecutorUtil.executeTenantTask(accountRegion, new CollectionBuilderTask() { @Override public List call() { diff --git a/src/main/java/ai/asserts/aws/exporter/LBToECSRoutingBuilder.java b/src/main/java/ai/asserts/aws/exporter/LBToECSRoutingBuilder.java index 0c205d33..488c093f 100644 --- a/src/main/java/ai/asserts/aws/exporter/LBToECSRoutingBuilder.java +++ b/src/main/java/ai/asserts/aws/exporter/LBToECSRoutingBuilder.java @@ -69,7 +69,7 @@ public void run() { Set newRouting = new HashSet<>(); List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(awsAccount -> awsAccount.getRegions().forEach(region -> - futures.add(taskExecutorUtil.executeTenantTask(awsAccount.getTenant(), + futures.add(taskExecutorUtil.executeTenantTask(awsAccount, new SimpleTenantTask>() { @Override public Set call() { diff --git a/src/main/java/ai/asserts/aws/exporter/LBToLambdaRoutingBuilder.java b/src/main/java/ai/asserts/aws/exporter/LBToLambdaRoutingBuilder.java index 3ecbbe06..ba690152 100644 --- a/src/main/java/ai/asserts/aws/exporter/LBToLambdaRoutingBuilder.java +++ b/src/main/java/ai/asserts/aws/exporter/LBToLambdaRoutingBuilder.java @@ -55,7 +55,7 @@ public Set getRoutings() { List, Set>>> futures = new ArrayList<>(); for (AWSAccount accountRegion : accountProvider.getAccounts()) { accountRegion.getRegions().forEach(region -> - futures.add(taskExecutorUtil.executeTenantTask(accountRegion.getTenant(), + futures.add(taskExecutorUtil.executeTenantTask(accountRegion, new SimpleTenantTask, Set>>() { @Override public Pair, Set> call() { diff --git a/src/main/java/ai/asserts/aws/exporter/LambdaCapacityExporter.java b/src/main/java/ai/asserts/aws/exporter/LambdaCapacityExporter.java index 495c2b53..8d0a3b59 100644 --- a/src/main/java/ai/asserts/aws/exporter/LambdaCapacityExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/LambdaCapacityExporter.java @@ -115,7 +115,7 @@ private List getMetrics() { Map> byRegion = byAccountByRegion.getOrDefault(account, Collections.emptyMap()); byRegion.forEach((region, functions) -> futures.add(taskExecutorUtil.executeTenantTask( - accountRegion.getTenant(), new SimpleTenantTask>>() { + accountRegion, new SimpleTenantTask>>() { @Override public Map> call() { return buildSamples(region, accountRegion, account, accountLimitMetric, diff --git a/src/main/java/ai/asserts/aws/exporter/LambdaEventSourceExporter.java b/src/main/java/ai/asserts/aws/exporter/LambdaEventSourceExporter.java index 510032a5..65e096d0 100644 --- a/src/main/java/ai/asserts/aws/exporter/LambdaEventSourceExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/LambdaEventSourceExporter.java @@ -95,7 +95,7 @@ private List getMappings() { ScrapeConfig scrapeConfig = scrapeConfigProvider.getScrapeConfig(accountRegion.getTenant()); Optional lambdaConfig = scrapeConfig.getLambdaConfig(); lambdaConfig.ifPresent(namespaceConfig -> accountRegion.getRegions().forEach(region -> - futures.add(taskExecutorUtil.executeTenantTask(accountRegion.getTenant(), + futures.add(taskExecutorUtil.executeTenantTask(accountRegion, new SimpleTenantTask>>() { @Override public Map> call() { diff --git a/src/main/java/ai/asserts/aws/exporter/LambdaInvokeConfigExporter.java b/src/main/java/ai/asserts/aws/exporter/LambdaInvokeConfigExporter.java index 8cd68fce..e8f119b0 100644 --- a/src/main/java/ai/asserts/aws/exporter/LambdaInvokeConfigExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/LambdaInvokeConfigExporter.java @@ -108,7 +108,7 @@ List getInvokeConfigs() { Map> byRegion = new ConcurrentHashMap<>(byAccountByRegion.get(account)); byRegion.forEach((region, byARN) -> - futures.add(taskExecutorUtil.executeTenantTask(accountRegion.getTenant(), + futures.add(taskExecutorUtil.executeTenantTask(accountRegion, new CollectionBuilderTask() { @Override public List call() { diff --git a/src/main/java/ai/asserts/aws/exporter/LoadBalancerExporter.java b/src/main/java/ai/asserts/aws/exporter/LoadBalancerExporter.java index d91a6d5c..3fa63c2f 100644 --- a/src/main/java/ai/asserts/aws/exporter/LoadBalancerExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/LoadBalancerExporter.java @@ -84,7 +84,7 @@ public void update() { List, List>>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(awsAccount -> awsAccount.getRegions().forEach(region -> { ScrapeConfig scrapeConfig = scrapeConfigProvider.getScrapeConfig(awsAccount.getTenant()); - futures.add(taskExecutorUtil.executeTenantTask(awsAccount.getTenant(), + futures.add(taskExecutorUtil.executeTenantTask(awsAccount, new SimpleTenantTask, List>>() { @Override public Pair, List> call() { diff --git a/src/main/java/ai/asserts/aws/exporter/MetricSampleBuilder.java b/src/main/java/ai/asserts/aws/exporter/MetricSampleBuilder.java index ad2d22b6..08cdb458 100644 --- a/src/main/java/ai/asserts/aws/exporter/MetricSampleBuilder.java +++ b/src/main/java/ai/asserts/aws/exporter/MetricSampleBuilder.java @@ -6,6 +6,7 @@ import ai.asserts.aws.MetricNameUtil; import ai.asserts.aws.TaskExecutorUtil; +import ai.asserts.aws.account.AWSAccount; import ai.asserts.aws.cloudwatch.query.MetricQuery; import io.prometheus.client.Collector.MetricFamilySamples; import io.prometheus.client.Collector.MetricFamilySamples.Sample; @@ -20,8 +21,12 @@ import java.util.Optional; import java.util.TreeMap; +import static ai.asserts.aws.MetricNameUtil.ENV; +import static ai.asserts.aws.MetricNameUtil.SCRAPE_REGION_LABEL; +import static ai.asserts.aws.MetricNameUtil.SITE; import static ai.asserts.aws.MetricNameUtil.TENANT; import static io.prometheus.client.Collector.Type.GAUGE; +import static org.springframework.util.StringUtils.hasLength; @Component @Slf4j @@ -38,7 +43,13 @@ public List buildSamples(String account, String region, MetricQuery metr String metricName = metricNameUtil.exportedMetricName(metricQuery.getMetric(), metricQuery.getMetricStat()); if (metricDataResult.timestamps().size() > 0) { Map labels = labelBuilder.buildLabels(account, region, metricQuery); - labels.putIfAbsent(TENANT, taskExecutorUtil.getTenant()); + labels.putIfAbsent(TENANT, taskExecutorUtil.getAccountDetails().getTenant()); + if (hasLength(taskExecutorUtil.getAccountDetails().getName())) { + labels.putIfAbsent(ENV, taskExecutorUtil.getAccountDetails().getName()); + } else { + labels.putIfAbsent(ENV, account); + } + labels.putIfAbsent(SITE, region); labels.entrySet().removeIf(entry -> entry.getValue() == null); for (int i = 0; i < metricDataResult.timestamps().size(); i++) { Sample sample = new Sample( @@ -55,7 +66,16 @@ public List buildSamples(String account, String region, MetricQuery metr public Optional buildSingleSample(String metricName, Map labels, Double metric) { labels = new TreeMap<>(labels); - labels.putIfAbsent(TENANT, taskExecutorUtil.getTenant()); + AWSAccount accountDetails = taskExecutorUtil.getAccountDetails(); + labels.putIfAbsent(TENANT, accountDetails.getTenant()); + if (hasLength(accountDetails.getName())) { + labels.putIfAbsent(ENV, accountDetails.getName()); + } else { + labels.putIfAbsent(ENV, accountDetails.getAccountId()); + } + if (labels.containsKey(SCRAPE_REGION_LABEL)) { + labels.putIfAbsent(SITE, labels.get(SCRAPE_REGION_LABEL)); + } labels.entrySet().removeIf(entry -> entry.getValue() == null); return Optional.of(new Sample( metricName, diff --git a/src/main/java/ai/asserts/aws/exporter/MetricScrapeTask.java b/src/main/java/ai/asserts/aws/exporter/MetricScrapeTask.java index 1ddbf1e8..f3aff0c9 100644 --- a/src/main/java/ai/asserts/aws/exporter/MetricScrapeTask.java +++ b/src/main/java/ai/asserts/aws/exporter/MetricScrapeTask.java @@ -101,7 +101,7 @@ public void update() { if (intervalSeconds <= 60 || System.currentTimeMillis() - lastRunTime > intervalSeconds * 1000L) { lastRunTime = System.currentTimeMillis(); try { - cache = taskExecutorUtil.executeTenantTask(account.getTenant(), + cache = taskExecutorUtil.executeTenantTask(account, new SimpleTenantTask>() { @Override public List call() { diff --git a/src/main/java/ai/asserts/aws/exporter/RDSExporter.java b/src/main/java/ai/asserts/aws/exporter/RDSExporter.java index f91b193b..c259a383 100644 --- a/src/main/java/ai/asserts/aws/exporter/RDSExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/RDSExporter.java @@ -88,7 +88,7 @@ public void update() { List allSamples = new ArrayList<>(); List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region -> - futures.add(taskExecutorUtil.executeTenantTask(account.getTenant(), new CollectionBuilderTask() { + futures.add(taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask() { @Override public List call() { return buildSamples(region, account); diff --git a/src/main/java/ai/asserts/aws/exporter/RedshiftExporter.java b/src/main/java/ai/asserts/aws/exporter/RedshiftExporter.java index 37f82097..58be8457 100644 --- a/src/main/java/ai/asserts/aws/exporter/RedshiftExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/RedshiftExporter.java @@ -79,7 +79,7 @@ public void update() { List allSamples = new ArrayList<>(); List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region -> - futures.add(taskExecutorUtil.executeTenantTask(account.getTenant(), new CollectionBuilderTask() { + futures.add(taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask() { @Override public List call() { return buildSamples(region, account); diff --git a/src/main/java/ai/asserts/aws/exporter/S3BucketExporter.java b/src/main/java/ai/asserts/aws/exporter/S3BucketExporter.java index 6201c508..423b0b21 100644 --- a/src/main/java/ai/asserts/aws/exporter/S3BucketExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/S3BucketExporter.java @@ -84,7 +84,7 @@ public void update() { List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region -> futures.add( - taskExecutorUtil.executeTenantTask(account.getTenant(), new CollectionBuilderTask() { + taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask() { @Override public List call() { return buildSamples(region, account); diff --git a/src/main/java/ai/asserts/aws/exporter/SNSTopicExporter.java b/src/main/java/ai/asserts/aws/exporter/SNSTopicExporter.java index 5b41f75d..93e3146a 100644 --- a/src/main/java/ai/asserts/aws/exporter/SNSTopicExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/SNSTopicExporter.java @@ -88,7 +88,7 @@ public void update() { List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region -> futures.add( - taskExecutorUtil.executeTenantTask(account.getTenant(), new CollectionBuilderTask() { + taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask() { @Override public List call() { return buildSamples(region, account); diff --git a/src/main/java/ai/asserts/aws/exporter/SQSQueueExporter.java b/src/main/java/ai/asserts/aws/exporter/SQSQueueExporter.java index ec12c2c0..ad6e0217 100644 --- a/src/main/java/ai/asserts/aws/exporter/SQSQueueExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/SQSQueueExporter.java @@ -91,7 +91,7 @@ public void update() { List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region -> futures.add( - taskExecutorUtil.executeTenantTask(account.getTenant(), new CollectionBuilderTask() { + taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask() { @Override public List call() { return buildSamples(region, account); diff --git a/src/main/java/ai/asserts/aws/exporter/TargetGroupLBMapProvider.java b/src/main/java/ai/asserts/aws/exporter/TargetGroupLBMapProvider.java index bef095a0..f75f0bdc 100644 --- a/src/main/java/ai/asserts/aws/exporter/TargetGroupLBMapProvider.java +++ b/src/main/java/ai/asserts/aws/exporter/TargetGroupLBMapProvider.java @@ -110,7 +110,7 @@ public void update() { List>> futures = new ArrayList<>(); for (AWSAccount accountRegion : accountProvider.getAccounts()) { accountRegion.getRegions() - .forEach(region -> futures.add(taskExecutorUtil.executeTenantTask(accountRegion.getTenant(), + .forEach(region -> futures.add(taskExecutorUtil.executeTenantTask(accountRegion, new CollectionBuilderTask() { @Override public List call() { diff --git a/src/main/java/ai/asserts/aws/lambda/LambdaFunctionBuilder.java b/src/main/java/ai/asserts/aws/lambda/LambdaFunctionBuilder.java index 165af9cf..6c1fd2de 100644 --- a/src/main/java/ai/asserts/aws/lambda/LambdaFunctionBuilder.java +++ b/src/main/java/ai/asserts/aws/lambda/LambdaFunctionBuilder.java @@ -31,7 +31,7 @@ public LambdaFunction buildFunction(String region, FunctionConfiguration functio Optional resourceFromARN = resourceMapper.map(functionConfiguration.functionArn()); LambdaFunction.LambdaFunctionBuilder builder = LambdaFunction.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .region(region) .name(functionConfiguration.functionName()) .arn(functionConfiguration.functionArn()) diff --git a/src/main/java/ai/asserts/aws/lambda/LambdaFunctionScraper.java b/src/main/java/ai/asserts/aws/lambda/LambdaFunctionScraper.java index 66055eb9..23e2ec13 100644 --- a/src/main/java/ai/asserts/aws/lambda/LambdaFunctionScraper.java +++ b/src/main/java/ai/asserts/aws/lambda/LambdaFunctionScraper.java @@ -147,7 +147,7 @@ private Map>> discoverFunctions( .filter(ns -> lambda.getNamespace().equals(ns.getName())) .findFirst(); lambdaNSOpt.ifPresent(lambdaNS -> accountRegion.getRegions().forEach(region -> - futures.add(taskExecutorUtil.executeTenantTask(accountRegion.getTenant(), + futures.add(taskExecutorUtil.executeTenantTask(accountRegion, new SimpleTenantTask>>>() { @Override public Map>> call() { diff --git a/src/main/java/ai/asserts/aws/resource/ResourceMapper.java b/src/main/java/ai/asserts/aws/resource/ResourceMapper.java index c7d93059..555f2500 100644 --- a/src/main/java/ai/asserts/aws/resource/ResourceMapper.java +++ b/src/main/java/ai/asserts/aws/resource/ResourceMapper.java @@ -86,7 +86,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = REDSHIFT_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(Redshift) .arn(arn) .region(matcher.group(1)) @@ -102,7 +102,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = KINESIS_FIREHOSE_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(KinesisDataFirehose) .arn(arn) .region(matcher.group(1)) @@ -118,7 +118,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = KINESIS_ANALYTICS_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(KinesisAnalytics) .arn(arn) .region(matcher.group(1)) @@ -134,7 +134,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = KINESIS_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(Kinesis) .arn(arn) .region(matcher.group(1)) @@ -150,7 +150,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = EC2_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(EC2Instance) .arn(arn) .region(matcher.group(1)) @@ -166,7 +166,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = ALARM_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(Alarm) .arn(arn) .region(matcher.group(1)) @@ -182,7 +182,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = SQS_QUEUE_ARN_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(SQSQueue) .arn(arn) .region(matcher.group(1)) @@ -198,7 +198,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = DYNAMODB_TABLE_ARN_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(DynamoDBTable) .arn(arn) .region(matcher.group(1)) @@ -214,7 +214,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = LAMBDA_ARN_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(LambdaFunction) .arn(arn) .region(matcher.group(1)) @@ -230,7 +230,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = S3_ARN_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(S3Bucket) .arn(arn) .region(matcher.group(1)) @@ -246,7 +246,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = SNS_ARN_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(SNSTopic) .arn(arn) .region(matcher.group(1)) @@ -262,7 +262,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = EVENTBUS_ARN_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(EventBus) .arn(arn) .region(matcher.group(1)) @@ -278,7 +278,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = ECS_CLUSTER_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(ECSCluster) .arn(arn) .region(matcher.group(1)) @@ -294,7 +294,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = ECS_SERVICE_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(ECSService) .arn(arn) .region(matcher.group(1)) @@ -318,7 +318,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Resource.ResourceBuilder builder = Resource.builder(); String[] nameAndVersion = matcher.group(3).split(":"); return Optional.of(builder - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(ECSTaskDef) .arn(arn) .region(matcher.group(1)) @@ -335,7 +335,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = ECS_TASK_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(ECSTask) .arn(arn) .region(matcher.group(1)) @@ -357,7 +357,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = LB_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(LoadBalancer) .arn(arn) .region(matcher.group(1)) @@ -375,7 +375,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = TARGET_GROUP_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(TargetGroup) .arn(arn) .region(matcher.group(1)) @@ -392,7 +392,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = SQS_URL.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(SQSQueue) .arn(String.format("arn:aws:sqs:%s:%s:%s", matcher.group(1), matcher.group(2), matcher.group(3))) @@ -409,7 +409,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = ASG_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(AutoScalingGroup) .arn(arn) .region(matcher.group(1)) @@ -426,7 +426,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = APIGATEWAY_METHOD_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(APIGatewayMethod) .arn(arn) .region(matcher.group(1)) @@ -449,7 +449,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = APIGATEWAY_STAGE_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(APIGatewayStage) .arn(arn) .region(matcher.group(1)) @@ -472,7 +472,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = APIGATEWAY_RESOURCE_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(APIGatewayResource) .arn(arn) .region(matcher.group(1)) @@ -495,7 +495,7 @@ public ResourceMapper(TaskExecutorUtil taskExecutorUtil) { Matcher matcher = APIGATEWAY_PATTERN.matcher(arn); if (matcher.matches()) { return Optional.of(Resource.builder() - .tenant(taskExecutorUtil.getTenant()) + .tenant(taskExecutorUtil.getAccountDetails().getTenant()) .type(ApiGateway) .arn(arn) .region(matcher.group(1)) diff --git a/src/test/java/ai/asserts/aws/exporter/ECSTaskUtilTest.java b/src/test/java/ai/asserts/aws/exporter/ECSTaskUtilTest.java index 727fe3c3..4bbe1f38 100644 --- a/src/test/java/ai/asserts/aws/exporter/ECSTaskUtilTest.java +++ b/src/test/java/ai/asserts/aws/exporter/ECSTaskUtilTest.java @@ -87,9 +87,15 @@ public void setup() { scrapeConfig = mock(ScrapeConfig.class); ec2Client = mock(Ec2Client.class); + AWSApiCallRateLimiter rateLimiter = new AWSApiCallRateLimiter(metricCollector, (account) -> "acme"); TaskExecutorUtil taskExecutorUtil = new TaskExecutorUtil(new TestTaskThreadPool(), - rateLimiter); + rateLimiter) { + @Override + public AWSAccount getAccountDetails() { + return account; + } + }; defaultEnvName = "dev"; diff --git a/src/test/java/ai/asserts/aws/exporter/MetricSampleBuilderTest.java b/src/test/java/ai/asserts/aws/exporter/MetricSampleBuilderTest.java index a286d67f..7b468d4f 100644 --- a/src/test/java/ai/asserts/aws/exporter/MetricSampleBuilderTest.java +++ b/src/test/java/ai/asserts/aws/exporter/MetricSampleBuilderTest.java @@ -6,6 +6,7 @@ import ai.asserts.aws.MetricNameUtil; import ai.asserts.aws.TaskExecutorUtil; +import ai.asserts.aws.account.AWSAccount; import ai.asserts.aws.cloudwatch.query.MetricQuery; import ai.asserts.aws.model.MetricStat; import com.google.common.collect.ImmutableList; @@ -41,7 +42,11 @@ public void setup() { labelBuilder = mock(LabelBuilder.class); TaskExecutorUtil taskExecutorUtil = mock(TaskExecutorUtil.class); testClass = new MetricSampleBuilder(metricNameUtil, labelBuilder, taskExecutorUtil); - expect(taskExecutorUtil.getTenant()).andReturn("acme").anyTimes(); + expect(taskExecutorUtil.getAccountDetails()).andReturn(AWSAccount.builder() + .name("dev") + .tenant("acme") + .accountId("account") + .build()).anyTimes(); } @Test @@ -66,8 +71,8 @@ void buildSamples() { .timestamps(instant, instant.plusSeconds(60)) .values(1.0D, 2.0D) .build()); - List labelNames = Arrays.asList("label1", "label2", "tenant"); - List labelValues = Arrays.asList("value1", "value2", "acme"); + List labelNames = Arrays.asList("asserts_env", "asserts_site", "label1", "label2", "tenant"); + List labelValues = Arrays.asList("dev", "region", "value1", "value2", "acme"); assertEquals(ImmutableList.of( new Sample("metric", labelNames, labelValues, 1.0D), new Sample("metric", labelNames, labelValues, 2.0D) @@ -77,8 +82,8 @@ void buildSamples() { @Test void buildSingleSample() { - List labelNames = Arrays.asList("label1", "label2", "tenant"); - List labelValues = Arrays.asList("value1", "value2", "acme"); + List labelNames = Arrays.asList("asserts_env", "label1", "label2", "tenant"); + List labelValues = Arrays.asList("dev", "value1", "value2", "acme"); SortedMap labels = new TreeMap<>( ImmutableSortedMap.of("label1", "value1", "label2", "value2")); replayAll(); diff --git a/src/test/java/ai/asserts/aws/lambda/LambdaFunctionBuilderTest.java b/src/test/java/ai/asserts/aws/lambda/LambdaFunctionBuilderTest.java index 205be103..a0e94925 100644 --- a/src/test/java/ai/asserts/aws/lambda/LambdaFunctionBuilderTest.java +++ b/src/test/java/ai/asserts/aws/lambda/LambdaFunctionBuilderTest.java @@ -5,6 +5,7 @@ package ai.asserts.aws.lambda; import ai.asserts.aws.TaskExecutorUtil; +import ai.asserts.aws.account.AWSAccount; import ai.asserts.aws.resource.Resource; import ai.asserts.aws.resource.ResourceMapper; import org.easymock.EasyMockSupport; @@ -36,7 +37,10 @@ public void setup() { public void buildFunction() { expect(resourceMapper.map("fn1:arn")).andReturn(Optional.of(fnResource)); expect(fnResource.getAccount()).andReturn(SCRAPE_ACCOUNT_ID_LABEL); - expect(taskExecutorUtil.getTenant()).andReturn("acme"); + expect(taskExecutorUtil.getAccountDetails()).andReturn(AWSAccount.builder() + .tenant("acme") + .accountId(SCRAPE_ACCOUNT_ID_LABEL) + .build()); replayAll(); assertEquals( diff --git a/src/test/java/ai/asserts/aws/resource/ResourceMapperTest.java b/src/test/java/ai/asserts/aws/resource/ResourceMapperTest.java index c61ffa60..746a340e 100644 --- a/src/test/java/ai/asserts/aws/resource/ResourceMapperTest.java +++ b/src/test/java/ai/asserts/aws/resource/ResourceMapperTest.java @@ -2,6 +2,7 @@ package ai.asserts.aws.resource; import ai.asserts.aws.TaskExecutorUtil; +import ai.asserts.aws.account.AWSAccount; import org.easymock.EasyMockSupport; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -40,7 +41,9 @@ public class ResourceMapperTest extends EasyMockSupport { public void setup() { TaskExecutorUtil taskExecutorUtil = mock(TaskExecutorUtil.class); testClass = new ResourceMapper(taskExecutorUtil); - expect(taskExecutorUtil.getTenant()).andReturn("acme").anyTimes(); + expect(taskExecutorUtil.getAccountDetails()).andReturn(AWSAccount.builder() + .tenant("acme") + .build()).anyTimes(); } @Test From 13bf83f7dc82a08e239fdf2925fd68fb83fc7cd3 Mon Sep 17 00:00:00 2001 From: jradhakrishnan Date: Tue, 22 Aug 2023 17:08:37 +0530 Subject: [PATCH 3/3] Change field and method name --- src/main/java/ai/asserts/aws/TaskExecutorUtil.java | 12 ++++++------ .../asserts/aws/cloudwatch/alarms/AlarmFetcher.java | 2 +- .../aws/cloudwatch/query/MetricQueryProvider.java | 2 +- .../aws/exporter/ApiGatewayToLambdaBuilder.java | 2 +- .../ai/asserts/aws/exporter/DynamoDBExporter.java | 2 +- .../asserts/aws/exporter/EC2ToEBSVolumeExporter.java | 4 ++-- .../ai/asserts/aws/exporter/ECSTaskProvider.java | 2 +- .../java/ai/asserts/aws/exporter/EMRExporter.java | 2 +- .../aws/exporter/KinesisAnalyticsExporter.java | 2 +- .../aws/exporter/KinesisFirehoseExporter.java | 2 +- .../asserts/aws/exporter/KinesisStreamExporter.java | 2 +- .../asserts/aws/exporter/LBToASGRelationBuilder.java | 2 +- .../asserts/aws/exporter/LBToECSRoutingBuilder.java | 2 +- .../aws/exporter/LBToLambdaRoutingBuilder.java | 2 +- .../asserts/aws/exporter/LambdaCapacityExporter.java | 2 +- .../aws/exporter/LambdaEventSourceExporter.java | 2 +- .../aws/exporter/LambdaInvokeConfigExporter.java | 2 +- .../asserts/aws/exporter/LoadBalancerExporter.java | 2 +- .../ai/asserts/aws/exporter/MetricScrapeTask.java | 2 +- .../java/ai/asserts/aws/exporter/RDSExporter.java | 2 +- .../ai/asserts/aws/exporter/RedshiftExporter.java | 2 +- .../ai/asserts/aws/exporter/S3BucketExporter.java | 2 +- .../ai/asserts/aws/exporter/SNSTopicExporter.java | 2 +- .../ai/asserts/aws/exporter/SQSQueueExporter.java | 2 +- .../aws/exporter/TargetGroupLBMapProvider.java | 2 +- .../ai/asserts/aws/lambda/LambdaFunctionScraper.java | 2 +- 26 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/main/java/ai/asserts/aws/TaskExecutorUtil.java b/src/main/java/ai/asserts/aws/TaskExecutorUtil.java index b0accf3a..803213c0 100644 --- a/src/main/java/ai/asserts/aws/TaskExecutorUtil.java +++ b/src/main/java/ai/asserts/aws/TaskExecutorUtil.java @@ -22,7 +22,7 @@ public class TaskExecutorUtil { private final TaskThreadPool taskThreadPool; private final AWSApiCallRateLimiter rateLimiter; - private static final ThreadLocal tenantName = new ThreadLocal<>(); + private static final ThreadLocal accountDetails = new ThreadLocal<>(); public TaskExecutorUtil(@Qualifier("aws-api-calls-thread-pool") TaskThreadPool taskThreadPool, AWSApiCallRateLimiter rateLimiter) { @@ -30,16 +30,16 @@ public TaskExecutorUtil(@Qualifier("aws-api-calls-thread-pool") TaskThreadPool t this.rateLimiter = rateLimiter; } - public Future executeTenantTask(AWSAccount tenant, TenantTask task) { + public Future executeAccountTask(AWSAccount accountDetails, TenantTask task) { return taskThreadPool.getExecutorService().submit(() -> { - tenantName.set(tenant); + TaskExecutorUtil.accountDetails.set(accountDetails); try { return rateLimiter.call(task); } catch (Exception e) { - log.error("Failed to execute tenant task for tenant:" + tenant, e); + log.error("Failed to execute tenant task for tenant:" + accountDetails, e); return task.getReturnValueWhenError(); } finally { - tenantName.remove(); + TaskExecutorUtil.accountDetails.remove(); } }); } @@ -55,6 +55,6 @@ public void awaitAll(List> futures, Consumer consumer) { } public AWSAccount getAccountDetails() { - return tenantName.get(); + return accountDetails.get(); } } diff --git a/src/main/java/ai/asserts/aws/cloudwatch/alarms/AlarmFetcher.java b/src/main/java/ai/asserts/aws/cloudwatch/alarms/AlarmFetcher.java index dc3026a7..88312b8f 100644 --- a/src/main/java/ai/asserts/aws/cloudwatch/alarms/AlarmFetcher.java +++ b/src/main/java/ai/asserts/aws/cloudwatch/alarms/AlarmFetcher.java @@ -103,7 +103,7 @@ public void update() { continue; } accountRegion.getRegions().forEach(region -> - futures.add(taskExecutorUtil.executeTenantTask(accountRegion, + futures.add(taskExecutorUtil.executeAccountTask(accountRegion, new CollectionBuilderTask() { @Override public List call() { diff --git a/src/main/java/ai/asserts/aws/cloudwatch/query/MetricQueryProvider.java b/src/main/java/ai/asserts/aws/cloudwatch/query/MetricQueryProvider.java index a4a436f0..1bd76915 100644 --- a/src/main/java/ai/asserts/aws/cloudwatch/query/MetricQueryProvider.java +++ b/src/main/java/ai/asserts/aws/cloudwatch/query/MetricQueryProvider.java @@ -102,7 +102,7 @@ Map>>> getQueriesInternal() { log.info("Will discover metrics and build metric queries for tenant {}, account {}", accountRegion.getTenant(), accountRegion.getAccountId()); accountRegion.getRegions().forEach(region -> futures.add( - taskExecutorUtil.executeTenantTask(accountRegion, new SimpleTenantTask() { + taskExecutorUtil.executeAccountTask(accountRegion, new SimpleTenantTask() { @Override public Void call() { buildQueries(scrapeConfig, region, accountRegion, account, queriesByAccount); diff --git a/src/main/java/ai/asserts/aws/exporter/ApiGatewayToLambdaBuilder.java b/src/main/java/ai/asserts/aws/exporter/ApiGatewayToLambdaBuilder.java index da08bcdc..aeec9375 100644 --- a/src/main/java/ai/asserts/aws/exporter/ApiGatewayToLambdaBuilder.java +++ b/src/main/java/ai/asserts/aws/exporter/ApiGatewayToLambdaBuilder.java @@ -96,7 +96,7 @@ public void update() { List>> futures = new ArrayList<>(); for (AWSAccount accountRegion : accountProvider.getAccounts()) { accountRegion.getRegions().forEach(region -> - futures.add(taskExecutorUtil.executeTenantTask(accountRegion, + futures.add(taskExecutorUtil.executeAccountTask(accountRegion, new CollectionBuilderTask() { @Override public List call() { diff --git a/src/main/java/ai/asserts/aws/exporter/DynamoDBExporter.java b/src/main/java/ai/asserts/aws/exporter/DynamoDBExporter.java index b1eab7ae..f6139e8a 100644 --- a/src/main/java/ai/asserts/aws/exporter/DynamoDBExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/DynamoDBExporter.java @@ -83,7 +83,7 @@ public void update() { List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region -> futures.add( - taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask() { + taskExecutorUtil.executeAccountTask(account, new CollectionBuilderTask() { @Override public List call() { return buildSamples(region, account, allSamples); diff --git a/src/main/java/ai/asserts/aws/exporter/EC2ToEBSVolumeExporter.java b/src/main/java/ai/asserts/aws/exporter/EC2ToEBSVolumeExporter.java index f69e9582..a6f0ea15 100644 --- a/src/main/java/ai/asserts/aws/exporter/EC2ToEBSVolumeExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/EC2ToEBSVolumeExporter.java @@ -103,14 +103,14 @@ public void update() { List>> futures = new ArrayList<>(); List>> volumeFutures = new ArrayList<>(); accountProvider.getAccounts().forEach(awsAccount -> awsAccount.getRegions().forEach(region -> { - futures.add(taskExecutorUtil.executeTenantTask(awsAccount, new CollectionBuilderTask() { + futures.add(taskExecutorUtil.executeAccountTask(awsAccount, new CollectionBuilderTask() { @Override public List call() { return buildEC2InstanceMetrics(region, awsAccount); } })); volumeFutures.add( - taskExecutorUtil.executeTenantTask(awsAccount, + taskExecutorUtil.executeAccountTask(awsAccount, new CollectionBuilderTask() { @Override public List call() { diff --git a/src/main/java/ai/asserts/aws/exporter/ECSTaskProvider.java b/src/main/java/ai/asserts/aws/exporter/ECSTaskProvider.java index 01e10ed3..323858d8 100644 --- a/src/main/java/ai/asserts/aws/exporter/ECSTaskProvider.java +++ b/src/main/java/ai/asserts/aws/exporter/ECSTaskProvider.java @@ -147,7 +147,7 @@ public void run() { for (AWSAccount account : accountProvider.getAccounts()) { ScrapeConfig scrapeConfig = scrapeConfigProvider.getScrapeConfig(account.getTenant()); for (String region : account.getRegions()) { - taskExecutorUtil.executeTenantTask(account, new SimpleTenantTask() { + taskExecutorUtil.executeAccountTask(account, new SimpleTenantTask() { @Override public Void call() { Map> clusterWiseNewTasks = new HashMap<>(); diff --git a/src/main/java/ai/asserts/aws/exporter/EMRExporter.java b/src/main/java/ai/asserts/aws/exporter/EMRExporter.java index 74d0d951..0dc4cae3 100644 --- a/src/main/java/ai/asserts/aws/exporter/EMRExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/EMRExporter.java @@ -71,7 +71,7 @@ public void update() { List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region -> futures.add( - taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask() { + taskExecutorUtil.executeAccountTask(account, new CollectionBuilderTask() { @Override public List call() { return buildSamples(region, account); diff --git a/src/main/java/ai/asserts/aws/exporter/KinesisAnalyticsExporter.java b/src/main/java/ai/asserts/aws/exporter/KinesisAnalyticsExporter.java index 675d0c44..cec82520 100644 --- a/src/main/java/ai/asserts/aws/exporter/KinesisAnalyticsExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/KinesisAnalyticsExporter.java @@ -77,7 +77,7 @@ public void update() { List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region -> futures.add( - taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask() { + taskExecutorUtil.executeAccountTask(account, new CollectionBuilderTask() { @Override public List call() { return buildSamples(region, account); diff --git a/src/main/java/ai/asserts/aws/exporter/KinesisFirehoseExporter.java b/src/main/java/ai/asserts/aws/exporter/KinesisFirehoseExporter.java index 73e0ce3d..39cd25a9 100644 --- a/src/main/java/ai/asserts/aws/exporter/KinesisFirehoseExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/KinesisFirehoseExporter.java @@ -90,7 +90,7 @@ public void update() { List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region -> futures.add( - taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask() { + taskExecutorUtil.executeAccountTask(account, new CollectionBuilderTask() { @Override public List call() { return buildMetricSamples(region, account); diff --git a/src/main/java/ai/asserts/aws/exporter/KinesisStreamExporter.java b/src/main/java/ai/asserts/aws/exporter/KinesisStreamExporter.java index 34698bba..4ab863e7 100644 --- a/src/main/java/ai/asserts/aws/exporter/KinesisStreamExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/KinesisStreamExporter.java @@ -82,7 +82,7 @@ public void update() { List allSamples = new ArrayList<>(); List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region -> - futures.add(taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask() { + futures.add(taskExecutorUtil.executeAccountTask(account, new CollectionBuilderTask() { @Override public List call() { return buildSamples(region, account); diff --git a/src/main/java/ai/asserts/aws/exporter/LBToASGRelationBuilder.java b/src/main/java/ai/asserts/aws/exporter/LBToASGRelationBuilder.java index b0fccd69..3ba5ed8c 100644 --- a/src/main/java/ai/asserts/aws/exporter/LBToASGRelationBuilder.java +++ b/src/main/java/ai/asserts/aws/exporter/LBToASGRelationBuilder.java @@ -97,7 +97,7 @@ public void updateRouting() { List>> futures = new ArrayList<>(); for (AWSAccount accountRegion : accountProvider.getAccounts()) { accountRegion.getRegions().forEach(region -> - futures.add(taskExecutorUtil.executeTenantTask(accountRegion, + futures.add(taskExecutorUtil.executeAccountTask(accountRegion, new CollectionBuilderTask() { @Override public List call() { diff --git a/src/main/java/ai/asserts/aws/exporter/LBToECSRoutingBuilder.java b/src/main/java/ai/asserts/aws/exporter/LBToECSRoutingBuilder.java index 488c093f..df862be1 100644 --- a/src/main/java/ai/asserts/aws/exporter/LBToECSRoutingBuilder.java +++ b/src/main/java/ai/asserts/aws/exporter/LBToECSRoutingBuilder.java @@ -69,7 +69,7 @@ public void run() { Set newRouting = new HashSet<>(); List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(awsAccount -> awsAccount.getRegions().forEach(region -> - futures.add(taskExecutorUtil.executeTenantTask(awsAccount, + futures.add(taskExecutorUtil.executeAccountTask(awsAccount, new SimpleTenantTask>() { @Override public Set call() { diff --git a/src/main/java/ai/asserts/aws/exporter/LBToLambdaRoutingBuilder.java b/src/main/java/ai/asserts/aws/exporter/LBToLambdaRoutingBuilder.java index ba690152..3c3daf3c 100644 --- a/src/main/java/ai/asserts/aws/exporter/LBToLambdaRoutingBuilder.java +++ b/src/main/java/ai/asserts/aws/exporter/LBToLambdaRoutingBuilder.java @@ -55,7 +55,7 @@ public Set getRoutings() { List, Set>>> futures = new ArrayList<>(); for (AWSAccount accountRegion : accountProvider.getAccounts()) { accountRegion.getRegions().forEach(region -> - futures.add(taskExecutorUtil.executeTenantTask(accountRegion, + futures.add(taskExecutorUtil.executeAccountTask(accountRegion, new SimpleTenantTask, Set>>() { @Override public Pair, Set> call() { diff --git a/src/main/java/ai/asserts/aws/exporter/LambdaCapacityExporter.java b/src/main/java/ai/asserts/aws/exporter/LambdaCapacityExporter.java index 8d0a3b59..b4fcec7b 100644 --- a/src/main/java/ai/asserts/aws/exporter/LambdaCapacityExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/LambdaCapacityExporter.java @@ -114,7 +114,7 @@ private List getMetrics() { String account = accountRegion.getAccountId(); Map> byRegion = byAccountByRegion.getOrDefault(account, Collections.emptyMap()); - byRegion.forEach((region, functions) -> futures.add(taskExecutorUtil.executeTenantTask( + byRegion.forEach((region, functions) -> futures.add(taskExecutorUtil.executeAccountTask( accountRegion, new SimpleTenantTask>>() { @Override public Map> call() { diff --git a/src/main/java/ai/asserts/aws/exporter/LambdaEventSourceExporter.java b/src/main/java/ai/asserts/aws/exporter/LambdaEventSourceExporter.java index 65e096d0..8a0a7384 100644 --- a/src/main/java/ai/asserts/aws/exporter/LambdaEventSourceExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/LambdaEventSourceExporter.java @@ -95,7 +95,7 @@ private List getMappings() { ScrapeConfig scrapeConfig = scrapeConfigProvider.getScrapeConfig(accountRegion.getTenant()); Optional lambdaConfig = scrapeConfig.getLambdaConfig(); lambdaConfig.ifPresent(namespaceConfig -> accountRegion.getRegions().forEach(region -> - futures.add(taskExecutorUtil.executeTenantTask(accountRegion, + futures.add(taskExecutorUtil.executeAccountTask(accountRegion, new SimpleTenantTask>>() { @Override public Map> call() { diff --git a/src/main/java/ai/asserts/aws/exporter/LambdaInvokeConfigExporter.java b/src/main/java/ai/asserts/aws/exporter/LambdaInvokeConfigExporter.java index e8f119b0..a9dcc032 100644 --- a/src/main/java/ai/asserts/aws/exporter/LambdaInvokeConfigExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/LambdaInvokeConfigExporter.java @@ -108,7 +108,7 @@ List getInvokeConfigs() { Map> byRegion = new ConcurrentHashMap<>(byAccountByRegion.get(account)); byRegion.forEach((region, byARN) -> - futures.add(taskExecutorUtil.executeTenantTask(accountRegion, + futures.add(taskExecutorUtil.executeAccountTask(accountRegion, new CollectionBuilderTask() { @Override public List call() { diff --git a/src/main/java/ai/asserts/aws/exporter/LoadBalancerExporter.java b/src/main/java/ai/asserts/aws/exporter/LoadBalancerExporter.java index 3fa63c2f..ad8c974d 100644 --- a/src/main/java/ai/asserts/aws/exporter/LoadBalancerExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/LoadBalancerExporter.java @@ -84,7 +84,7 @@ public void update() { List, List>>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(awsAccount -> awsAccount.getRegions().forEach(region -> { ScrapeConfig scrapeConfig = scrapeConfigProvider.getScrapeConfig(awsAccount.getTenant()); - futures.add(taskExecutorUtil.executeTenantTask(awsAccount, + futures.add(taskExecutorUtil.executeAccountTask(awsAccount, new SimpleTenantTask, List>>() { @Override public Pair, List> call() { diff --git a/src/main/java/ai/asserts/aws/exporter/MetricScrapeTask.java b/src/main/java/ai/asserts/aws/exporter/MetricScrapeTask.java index f3aff0c9..eb9ee698 100644 --- a/src/main/java/ai/asserts/aws/exporter/MetricScrapeTask.java +++ b/src/main/java/ai/asserts/aws/exporter/MetricScrapeTask.java @@ -101,7 +101,7 @@ public void update() { if (intervalSeconds <= 60 || System.currentTimeMillis() - lastRunTime > intervalSeconds * 1000L) { lastRunTime = System.currentTimeMillis(); try { - cache = taskExecutorUtil.executeTenantTask(account, + cache = taskExecutorUtil.executeAccountTask(account, new SimpleTenantTask>() { @Override public List call() { diff --git a/src/main/java/ai/asserts/aws/exporter/RDSExporter.java b/src/main/java/ai/asserts/aws/exporter/RDSExporter.java index c259a383..3b7a4da2 100644 --- a/src/main/java/ai/asserts/aws/exporter/RDSExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/RDSExporter.java @@ -88,7 +88,7 @@ public void update() { List allSamples = new ArrayList<>(); List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region -> - futures.add(taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask() { + futures.add(taskExecutorUtil.executeAccountTask(account, new CollectionBuilderTask() { @Override public List call() { return buildSamples(region, account); diff --git a/src/main/java/ai/asserts/aws/exporter/RedshiftExporter.java b/src/main/java/ai/asserts/aws/exporter/RedshiftExporter.java index 58be8457..c936ac00 100644 --- a/src/main/java/ai/asserts/aws/exporter/RedshiftExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/RedshiftExporter.java @@ -79,7 +79,7 @@ public void update() { List allSamples = new ArrayList<>(); List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region -> - futures.add(taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask() { + futures.add(taskExecutorUtil.executeAccountTask(account, new CollectionBuilderTask() { @Override public List call() { return buildSamples(region, account); diff --git a/src/main/java/ai/asserts/aws/exporter/S3BucketExporter.java b/src/main/java/ai/asserts/aws/exporter/S3BucketExporter.java index 423b0b21..b7519b4a 100644 --- a/src/main/java/ai/asserts/aws/exporter/S3BucketExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/S3BucketExporter.java @@ -84,7 +84,7 @@ public void update() { List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region -> futures.add( - taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask() { + taskExecutorUtil.executeAccountTask(account, new CollectionBuilderTask() { @Override public List call() { return buildSamples(region, account); diff --git a/src/main/java/ai/asserts/aws/exporter/SNSTopicExporter.java b/src/main/java/ai/asserts/aws/exporter/SNSTopicExporter.java index 93e3146a..68fc9629 100644 --- a/src/main/java/ai/asserts/aws/exporter/SNSTopicExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/SNSTopicExporter.java @@ -88,7 +88,7 @@ public void update() { List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region -> futures.add( - taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask() { + taskExecutorUtil.executeAccountTask(account, new CollectionBuilderTask() { @Override public List call() { return buildSamples(region, account); diff --git a/src/main/java/ai/asserts/aws/exporter/SQSQueueExporter.java b/src/main/java/ai/asserts/aws/exporter/SQSQueueExporter.java index ad6e0217..47336a2c 100644 --- a/src/main/java/ai/asserts/aws/exporter/SQSQueueExporter.java +++ b/src/main/java/ai/asserts/aws/exporter/SQSQueueExporter.java @@ -91,7 +91,7 @@ public void update() { List>> futures = new ArrayList<>(); accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region -> futures.add( - taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask() { + taskExecutorUtil.executeAccountTask(account, new CollectionBuilderTask() { @Override public List call() { return buildSamples(region, account); diff --git a/src/main/java/ai/asserts/aws/exporter/TargetGroupLBMapProvider.java b/src/main/java/ai/asserts/aws/exporter/TargetGroupLBMapProvider.java index f75f0bdc..4a5672a0 100644 --- a/src/main/java/ai/asserts/aws/exporter/TargetGroupLBMapProvider.java +++ b/src/main/java/ai/asserts/aws/exporter/TargetGroupLBMapProvider.java @@ -110,7 +110,7 @@ public void update() { List>> futures = new ArrayList<>(); for (AWSAccount accountRegion : accountProvider.getAccounts()) { accountRegion.getRegions() - .forEach(region -> futures.add(taskExecutorUtil.executeTenantTask(accountRegion, + .forEach(region -> futures.add(taskExecutorUtil.executeAccountTask(accountRegion, new CollectionBuilderTask() { @Override public List call() { diff --git a/src/main/java/ai/asserts/aws/lambda/LambdaFunctionScraper.java b/src/main/java/ai/asserts/aws/lambda/LambdaFunctionScraper.java index 23e2ec13..35c8ecec 100644 --- a/src/main/java/ai/asserts/aws/lambda/LambdaFunctionScraper.java +++ b/src/main/java/ai/asserts/aws/lambda/LambdaFunctionScraper.java @@ -147,7 +147,7 @@ private Map>> discoverFunctions( .filter(ns -> lambda.getNamespace().equals(ns.getName())) .findFirst(); lambdaNSOpt.ifPresent(lambdaNS -> accountRegion.getRegions().forEach(region -> - futures.add(taskExecutorUtil.executeTenantTask(accountRegion, + futures.add(taskExecutorUtil.executeAccountTask(accountRegion, new SimpleTenantTask>>>() { @Override public Map>> call() {