Skip to content

Commit

Permalink
Add tenant label in ecs meta metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
jradhakrishnan committed Aug 30, 2023
1 parent 7a3e423 commit 33d005d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/java/ai/asserts/aws/exporter/ECSTaskProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import static ai.asserts.aws.MetricNameUtil.SCRAPE_NAMESPACE_LABEL;
import static ai.asserts.aws.MetricNameUtil.SCRAPE_OPERATION_LABEL;
import static ai.asserts.aws.MetricNameUtil.SCRAPE_REGION_LABEL;
import static ai.asserts.aws.MetricNameUtil.TENANT;

/**
* Builds ECS Task scrape targets. Scraping ECS is best done using the ECS Sidecar.
Expand Down Expand Up @@ -111,6 +112,7 @@ public List<MetricFamilySamples> collect() {

target.getLogConfigs().forEach(logConfig -> {
Map<String, String> logInfoLabels = new TreeMap<>();
logInfoLabels.put(TENANT, labels.getTenant());
logInfoLabels.put(SCRAPE_ACCOUNT_ID_LABEL, labels.getAccountId());
logInfoLabels.put(SCRAPE_REGION_LABEL, labels.getRegion());
logInfoLabels.put("cluster", labels.getCluster());
Expand Down
14 changes: 13 additions & 1 deletion src/test/java/ai/asserts/aws/exporter/ECSTaskProviderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public void afterPropertiesSet() throws Exception {
@Test
public void collect() throws Exception {
Resource cluster1 = Resource.builder()
.tenant("acme")
.name("cluster1")
.region("region")
.account("account1")
Expand All @@ -124,6 +125,7 @@ public void collect() throws Exception {


Resource task1 = Resource.builder()
.tenant("acme")
.name("task1")
.build();

Expand All @@ -143,6 +145,7 @@ public void collect() throws Exception {
tasksByCluster.put(cluster1, ImmutableMap.of(task1, ImmutableList.of(mockStaticConfig, mockStaticConfig)));

Labels labels1 = Labels.builder()
.tenant("acme")
.accountId("account1")
.region("us-west-2")
.cluster("cluster")
Expand All @@ -162,6 +165,7 @@ public void collect() throws Exception {

expect(sampleBuilder.buildSingleSample(CONTAINER_LOG_INFO_METRIC,
ImmutableSortedMap.<String, String>naturalOrder()
.put("tenant", "acme")
.put("account_id", "account1")
.put("region", "us-west-2")
.put("cluster", "cluster")
Expand All @@ -174,6 +178,7 @@ public void collect() throws Exception {
.build(), 1.0D)).andReturn(Optional.of(mockSample));

Labels labels2 = Labels.builder()
.tenant("acme")
.accountId("account1")
.region("us-west-2")
.cluster("cluster")
Expand All @@ -192,6 +197,7 @@ public void collect() throws Exception {
.build()));
expect(sampleBuilder.buildSingleSample(CONTAINER_LOG_INFO_METRIC,
ImmutableSortedMap.<String, String>naturalOrder()
.put("tenant", "acme")
.put("account_id", "account1")
.put("region", "us-west-2")
.put("cluster", "cluster")
Expand Down Expand Up @@ -226,19 +232,22 @@ public void getService() {
@Test
public void getScrapeTargets() {
AWSAccount awsAccount = AWSAccount.builder()
.tenant("acme")
.accountId("account1")
.regions(ImmutableSet.of("region"))
.name("test-account")
.build();

Resource cluster1 = Resource.builder()
.tenant("acme")
.name("cluster1")
.region("region")
.account("account1")
.arn("cluster1-arn")
.build();

Resource task1 = Resource.builder()
.tenant("acme")
.name("task1")
.build();

Expand All @@ -265,7 +274,7 @@ void buildNewTargets(AWSAccount _account, ScrapeConfig _scrapeConfig,

testClass.getTasksByCluster().put(cluster1, ImmutableMap.of(task1, ImmutableList.of(mockStaticConfig)));

expect(scrapeConfigProvider.getScrapeConfig(null)).andReturn(scrapeConfig);
expect(scrapeConfigProvider.getScrapeConfig("acme")).andReturn(scrapeConfig);

expect(accountProvider.getAccounts()).andReturn(ImmutableSet.of(awsAccount));
expect(awsClientProvider.getECSClient("region", awsAccount)).andReturn(ecsClient);
Expand All @@ -279,6 +288,7 @@ void buildNewTargets(AWSAccount _account, ScrapeConfig _scrapeConfig,
@Test
public void discoverNewTargets() {
Resource cluster1 = Resource.builder()
.tenant("acme")
.name("cluster1")
.region("region")
.account("account1")
Expand Down Expand Up @@ -338,6 +348,7 @@ public void discoverNewTargets() {
public void buildNewTargets() {
expect(scrapeConfigProvider.getScrapeConfig("acme")).andReturn(scrapeConfig).anyTimes();
Resource cluster1 = Resource.builder()
.tenant("acme")
.name("cluster1")
.region("region")
.account("account1")
Expand All @@ -347,6 +358,7 @@ public void buildNewTargets() {
Resource service2 = Resource.builder().arn("service2-arn").build();

Resource cluster2 = Resource.builder()
.tenant("acme")
.name("cluster2")
.region("region")
.account("account1")
Expand Down

0 comments on commit 33d005d

Please sign in to comment.