Skip to content

Commit

Permalink
Replace tenant with asserts_customer in internal metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
jradhakrishnan committed Aug 30, 2023
1 parent 7a8a567 commit 3b16861
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/main/java/ai/asserts/aws/AWSApiCallRateLimiter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.concurrent.Callable;

import static ai.asserts.aws.MetricNameUtil.ASSERTS_ERROR_TYPE;
import static ai.asserts.aws.MetricNameUtil.ASSERTS_CUSTOMER;
import static ai.asserts.aws.MetricNameUtil.SCRAPE_ACCOUNT_ID_LABEL;
import static ai.asserts.aws.MetricNameUtil.SCRAPE_ERROR_COUNT_METRIC;
import static ai.asserts.aws.MetricNameUtil.SCRAPE_LATENCY_METRIC;
Expand Down Expand Up @@ -71,21 +72,27 @@ public <K extends AWSAPICall<V>, V> V doWithRateLimit(String api, SortedMap<Stri
tick = System.currentTimeMillis();
return k.makeCall();
} catch (Throwable e) {
log.error("Exception", e);
log.error("Exception in: " + regionKey, e);
SortedMap<String, String> errorLabels = new TreeMap<>(labels);
errorLabels.put(ASSERTS_ERROR_TYPE, e.getClass().getSimpleName());

// In SaaS mode, we don't want the exporter internal metrics to end up in the tenant's TSDB
errorLabels.remove(TENANT);
if (tenantName != null) {
errorLabels.put(TENANT, tenantName);
errorLabels.put(ASSERTS_CUSTOMER, tenantName);
}
metricCollector.recordCounterValue(SCRAPE_ERROR_COUNT_METRIC, errorLabels, 1);
throw new RuntimeException(e);
} finally {
tick = System.currentTimeMillis() - tick;
labels = new TreeMap<>(labels);

// In SaaS mode, we don't want the exporter internal metrics to end up in the tenant's TSDB
SortedMap<String, String> latencyLabels = new TreeMap<>(labels);
latencyLabels.remove(TENANT);
if (tenantName != null) {
labels.put(TENANT, tenantName);
latencyLabels.put(ASSERTS_CUSTOMER, tenantName);
}
metricCollector.recordLatency(SCRAPE_LATENCY_METRIC, labels, tick);
metricCollector.recordLatency(SCRAPE_LATENCY_METRIC, latencyLabels, tick);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/ai/asserts/aws/MetricNameUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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 ASSERTS_CUSTOMER = "asserts_customer";
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void setup() {
labels = new TreeMap<>();
labels.put("account_id", "account");
labels.put("region", "region");
labels.put("tenant", "acme");
labels.put("asserts_customer", "acme");
rateLimiter = new AWSApiCallRateLimiter(metricCollector,
(accountId) -> "acme", 1.0D);
}
Expand Down

0 comments on commit 3b16861

Please sign in to comment.