From dee040318ae28b230072eb9e5e0602dba67eb0a8 Mon Sep 17 00:00:00 2001 From: Ehren Kret Date: Thu, 30 Jul 2020 11:59:16 -0500 Subject: [PATCH] Add the host tag to datadog metric reporting --- .../textsecuregcm/WhisperServerService.java | 7 +++ .../metrics/SignalDatadogReporterFactory.java | 63 +++++++++++++++++++ .../io.dropwizard.metrics.ReporterFactory | 3 +- 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 service/src/main/java/org/whispersystems/textsecuregcm/metrics/SignalDatadogReporterFactory.java diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java index d6fbb6d7e..de341dc96 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java @@ -22,6 +22,7 @@ import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3Client; +import com.amazonaws.util.EC2MetadataUtils; import com.codahale.metrics.SharedMetricRegistries; import com.codahale.metrics.jdbi3.strategies.DefaultNameStrategy; import com.fasterxml.jackson.annotation.JsonAutoDetect; @@ -252,6 +253,7 @@ public class WhisperServerService extends Application tags = null; + + @Valid + @JsonProperty + private DynamicTagsCallbackFactory dynamicTagsCallback = null; + + @JsonProperty + private String prefix = null; + + @Valid + @NotNull + @JsonProperty + private EnumSet expansions = DatadogReporter.Expansion.ALL; + + @Valid + @NotNull + @JsonProperty + private MetricNameFormatterFactory metricNameFormatter = new DefaultMetricNameFormatterFactory(); + + @Valid + @NotNull + @JsonProperty + private AbstractTransportFactory transport = null; + + public ScheduledReporter build(MetricRegistry registry) { + return DatadogReporter.forRegistry(registry) + .withTransport(transport.build()) + .withHost(EC2MetadataUtils.getInstanceId()) + .withTags(tags) + .withPrefix(prefix) + .withExpansions(expansions) + .withMetricNameFormatter(metricNameFormatter.build()) + .withDynamicTagCallback(dynamicTagsCallback != null ? dynamicTagsCallback.build() : null) + .filter(getFilter()) + .convertDurationsTo(getDurationUnit()) + .convertRatesTo(getRateUnit()) + .build(); + } +} diff --git a/service/src/main/resources/META-INF/services/io.dropwizard.metrics.ReporterFactory b/service/src/main/resources/META-INF/services/io.dropwizard.metrics.ReporterFactory index bdc070f96..be127b6fd 100644 --- a/service/src/main/resources/META-INF/services/io.dropwizard.metrics.ReporterFactory +++ b/service/src/main/resources/META-INF/services/io.dropwizard.metrics.ReporterFactory @@ -1 +1,2 @@ -org.whispersystems.textsecuregcm.metrics.JsonMetricsReporterFactory \ No newline at end of file +org.whispersystems.textsecuregcm.metrics.JsonMetricsReporterFactory +org.whispersystems.textsecuregcm.metrics.SignalDatadogReporterFactory