Skip to content

Commit

Permalink
Change field and method name
Browse files Browse the repository at this point in the history
  • Loading branch information
jradhakrishnan committed Aug 22, 2023
1 parent fce9503 commit 13bf83f
Show file tree
Hide file tree
Showing 26 changed files with 32 additions and 32 deletions.
12 changes: 6 additions & 6 deletions src/main/java/ai/asserts/aws/TaskExecutorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ public class TaskExecutorUtil {
private final TaskThreadPool taskThreadPool;

private final AWSApiCallRateLimiter rateLimiter;
private static final ThreadLocal<AWSAccount> tenantName = new ThreadLocal<>();
private static final ThreadLocal<AWSAccount> accountDetails = new ThreadLocal<>();


public TaskExecutorUtil(@Qualifier("aws-api-calls-thread-pool") TaskThreadPool taskThreadPool, AWSApiCallRateLimiter rateLimiter) {
this.taskThreadPool = taskThreadPool;
this.rateLimiter = rateLimiter;
}

public <T> Future<T> executeTenantTask(AWSAccount tenant, TenantTask<T> task) {
public <T> Future<T> executeAccountTask(AWSAccount accountDetails, TenantTask<T> 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();
}
});
}
Expand All @@ -55,6 +55,6 @@ public <K> void awaitAll(List<Future<K>> futures, Consumer<K> consumer) {
}

public AWSAccount getAccountDetails() {
return tenantName.get();
return accountDetails.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void update() {
continue;
}
accountRegion.getRegions().forEach(region ->
futures.add(taskExecutorUtil.executeTenantTask(accountRegion,
futures.add(taskExecutorUtil.executeAccountTask(accountRegion,
new CollectionBuilderTask<Sample>() {
@Override
public List<Sample> call() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Map<String, Map<String, Map<Integer, List<MetricQuery>>>> 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<Void>() {
taskExecutorUtil.executeAccountTask(accountRegion, new SimpleTenantTask<Void>() {
@Override
public Void call() {
buildQueries(scrapeConfig, region, accountRegion, account, queriesByAccount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void update() {
List<Future<List<Sample>>> futures = new ArrayList<>();
for (AWSAccount accountRegion : accountProvider.getAccounts()) {
accountRegion.getRegions().forEach(region ->
futures.add(taskExecutorUtil.executeTenantTask(accountRegion,
futures.add(taskExecutorUtil.executeAccountTask(accountRegion,
new CollectionBuilderTask<Sample>() {
@Override
public List<Sample> call() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void update() {
List<Future<List<Sample>>> futures = new ArrayList<>();
accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region ->
futures.add(
taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask<Sample>() {
taskExecutorUtil.executeAccountTask(account, new CollectionBuilderTask<Sample>() {
@Override
public List<Sample> call() {
return buildSamples(region, account, allSamples);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ public void update() {
List<Future<List<Sample>>> futures = new ArrayList<>();
List<Future<List<ResourceRelation>>> volumeFutures = new ArrayList<>();
accountProvider.getAccounts().forEach(awsAccount -> awsAccount.getRegions().forEach(region -> {
futures.add(taskExecutorUtil.executeTenantTask(awsAccount, new CollectionBuilderTask<Sample>() {
futures.add(taskExecutorUtil.executeAccountTask(awsAccount, new CollectionBuilderTask<Sample>() {
@Override
public List<Sample> call() {
return buildEC2InstanceMetrics(region, awsAccount);
}
}));
volumeFutures.add(
taskExecutorUtil.executeTenantTask(awsAccount,
taskExecutorUtil.executeAccountTask(awsAccount,
new CollectionBuilderTask<ResourceRelation>() {
@Override
public List<ResourceRelation> call() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ai/asserts/aws/exporter/ECSTaskProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void>() {
taskExecutorUtil.executeAccountTask(account, new SimpleTenantTask<Void>() {
@Override
public Void call() {
Map<Resource, List<Resource>> clusterWiseNewTasks = new HashMap<>();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ai/asserts/aws/exporter/EMRExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void update() {
List<Future<List<Sample>>> futures = new ArrayList<>();
accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region ->
futures.add(
taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask<Sample>() {
taskExecutorUtil.executeAccountTask(account, new CollectionBuilderTask<Sample>() {
@Override
public List<Sample> call() {
return buildSamples(region, account);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void update() {
List<Future<List<Sample>>> futures = new ArrayList<>();
accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region ->
futures.add(
taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask<Sample>() {
taskExecutorUtil.executeAccountTask(account, new CollectionBuilderTask<Sample>() {
@Override
public List<Sample> call() {
return buildSamples(region, account);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void update() {
List<Future<List<Sample>>> futures = new ArrayList<>();
accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region ->
futures.add(
taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask<Sample>() {
taskExecutorUtil.executeAccountTask(account, new CollectionBuilderTask<Sample>() {
@Override
public List<Sample> call() {
return buildMetricSamples(region, account);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void update() {
List<Sample> allSamples = new ArrayList<>();
List<Future<List<Sample>>> futures = new ArrayList<>();
accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region ->
futures.add(taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask<Sample>() {
futures.add(taskExecutorUtil.executeAccountTask(account, new CollectionBuilderTask<Sample>() {
@Override
public List<Sample> call() {
return buildSamples(region, account);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void updateRouting() {
List<Future<List<Sample>>> futures = new ArrayList<>();
for (AWSAccount accountRegion : accountProvider.getAccounts()) {
accountRegion.getRegions().forEach(region ->
futures.add(taskExecutorUtil.executeTenantTask(accountRegion,
futures.add(taskExecutorUtil.executeAccountTask(accountRegion,
new CollectionBuilderTask<Sample>() {
@Override
public List<Sample> call() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void run() {
Set<ResourceRelation> newRouting = new HashSet<>();
List<Future<Set<ResourceRelation>>> futures = new ArrayList<>();
accountProvider.getAccounts().forEach(awsAccount -> awsAccount.getRegions().forEach(region ->
futures.add(taskExecutorUtil.executeTenantTask(awsAccount,
futures.add(taskExecutorUtil.executeAccountTask(awsAccount,
new SimpleTenantTask<Set<ResourceRelation>>() {
@Override
public Set<ResourceRelation> call() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Set<ResourceRelation> getRoutings() {
List<Future<Pair<Set<ResourceRelation>, Set<Resource>>>> futures = new ArrayList<>();
for (AWSAccount accountRegion : accountProvider.getAccounts()) {
accountRegion.getRegions().forEach(region ->
futures.add(taskExecutorUtil.executeTenantTask(accountRegion,
futures.add(taskExecutorUtil.executeAccountTask(accountRegion,
new SimpleTenantTask<Pair<Set<ResourceRelation>, Set<Resource>>>() {
@Override
public Pair<Set<ResourceRelation>, Set<Resource>> call() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private List<MetricFamilySamples> getMetrics() {
String account = accountRegion.getAccountId();
Map<String, Map<String, LambdaFunction>> 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<Map<String, List<Sample>>>() {
@Override
public Map<String, List<Sample>> call() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private List<MetricFamilySamples> getMappings() {
ScrapeConfig scrapeConfig = scrapeConfigProvider.getScrapeConfig(accountRegion.getTenant());
Optional<NamespaceConfig> lambdaConfig = scrapeConfig.getLambdaConfig();
lambdaConfig.ifPresent(namespaceConfig -> accountRegion.getRegions().forEach(region ->
futures.add(taskExecutorUtil.executeTenantTask(accountRegion,
futures.add(taskExecutorUtil.executeAccountTask(accountRegion,
new SimpleTenantTask<Map<String, List<Sample>>>() {
@Override
public Map<String, List<Sample>> call() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ List<MetricFamilySamples> getInvokeConfigs() {
Map<String, Map<String, LambdaFunction>> byRegion =
new ConcurrentHashMap<>(byAccountByRegion.get(account));
byRegion.forEach((region, byARN) ->
futures.add(taskExecutorUtil.executeTenantTask(accountRegion,
futures.add(taskExecutorUtil.executeAccountTask(accountRegion,
new CollectionBuilderTask<Sample>() {
@Override
public List<Sample> call() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void update() {
List<Future<Pair<List<Sample>, List<Sample>>>> 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<Pair<List<Sample>, List<Sample>>>() {
@Override
public Pair<List<Sample>, List<Sample>> call() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<MetricFamilySamples>>() {
@Override
public List<MetricFamilySamples> call() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ai/asserts/aws/exporter/RDSExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void update() {
List<Sample> allSamples = new ArrayList<>();
List<Future<List<Sample>>> futures = new ArrayList<>();
accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region ->
futures.add(taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask<Sample>() {
futures.add(taskExecutorUtil.executeAccountTask(account, new CollectionBuilderTask<Sample>() {
@Override
public List<Sample> call() {
return buildSamples(region, account);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void update() {
List<Sample> allSamples = new ArrayList<>();
List<Future<List<Sample>>> futures = new ArrayList<>();
accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region ->
futures.add(taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask<Sample>() {
futures.add(taskExecutorUtil.executeAccountTask(account, new CollectionBuilderTask<Sample>() {
@Override
public List<Sample> call() {
return buildSamples(region, account);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void update() {
List<Future<List<Sample>>> futures = new ArrayList<>();
accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region ->
futures.add(
taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask<Sample>() {
taskExecutorUtil.executeAccountTask(account, new CollectionBuilderTask<Sample>() {
@Override
public List<Sample> call() {
return buildSamples(region, account);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void update() {
List<Future<List<Sample>>> futures = new ArrayList<>();
accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region ->
futures.add(
taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask<Sample>() {
taskExecutorUtil.executeAccountTask(account, new CollectionBuilderTask<Sample>() {
@Override
public List<Sample> call() {
return buildSamples(region, account);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void update() {
List<Future<List<Sample>>> futures = new ArrayList<>();
accountProvider.getAccounts().forEach(account -> account.getRegions().forEach(region ->
futures.add(
taskExecutorUtil.executeTenantTask(account, new CollectionBuilderTask<Sample>() {
taskExecutorUtil.executeAccountTask(account, new CollectionBuilderTask<Sample>() {
@Override
public List<Sample> call() {
return buildSamples(region, account);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void update() {
List<Future<List<Sample>>> 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<Sample>() {
@Override
public List<Sample> call() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private Map<String, Map<String, Map<String, LambdaFunction>>> 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<Map<String, Map<String, Map<String, LambdaFunction>>>>() {
@Override
public Map<String, Map<String, Map<String, LambdaFunction>>> call() {
Expand Down

0 comments on commit 13bf83f

Please sign in to comment.