Enable/disable AWS SDK metrics via dynamic configuration

This commit is contained in:
Jon Chambers
2024-12-18 10:49:50 -05:00
committed by ravi-signal
parent 85a1550485
commit 4839a5ba70
5 changed files with 37 additions and 11 deletions

View File

@@ -66,7 +66,7 @@ public class DynamicConfiguration {
@JsonProperty
@Valid
DynamicMetricsConfiguration metricsConfiguration = new DynamicMetricsConfiguration(false);
DynamicMetricsConfiguration metricsConfiguration = new DynamicMetricsConfiguration(false, false);
@JsonProperty
@Valid

View File

@@ -6,8 +6,10 @@
package org.whispersystems.textsecuregcm.configuration.dynamic;
/**
* @param enableLettuceRemoteTag - whether the `remote` tag should be added. Note: although this is dynamic, meters are
* @param enableLettuceRemoteTag whether the `remote` tag should be added. Note: although this is dynamic, meters are
* cached after creation, so changes will only affect servers launched after the change.
* @param enableAwsSdkMetrics whether to record AWS SDK metrics. Note: although this is dynamic, meters are cached after
* creation, so changes will only affect servers launched after the change.
*/
public record DynamicMetricsConfiguration(boolean enableLettuceRemoteTag) {
public record DynamicMetricsConfiguration(boolean enableLettuceRemoteTag, boolean enableAwsSdkMetrics) {
}

View File

@@ -85,6 +85,8 @@ public class MetricsUtil {
.percentiles(.75, .95, .99, .999)
.build();
final String awsSdkMetricNamePrefix = MetricsUtil.name(MicrometerAwsSdkMetricPublisher.class);
return config
.meterFilter(new MeterFilter() {
@Override
@@ -108,7 +110,9 @@ public class MetricsUtil {
return MeterFilter.super.map(id);
}
})
.meterFilter(MeterFilter.denyNameStartsWith(MessageMetrics.DELIVERY_LATENCY_TIMER_NAME + ".percentile"));
.meterFilter(MeterFilter.denyNameStartsWith(MessageMetrics.DELIVERY_LATENCY_TIMER_NAME + ".percentile"))
.meterFilter(MeterFilter.deny(id -> !dynamicConfigurationManager.getConfiguration().getMetricsConfiguration().enableAwsSdkMetrics()
&& id.getName().startsWith(awsSdkMetricNamePrefix)));
}
public static void registerSystemResourceMetrics(final Environment environment) {

View File

@@ -8,6 +8,7 @@ import java.time.Duration;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import software.amazon.awssdk.metrics.MetricCollection;
@@ -102,13 +103,13 @@ public class MicrometerAwsSdkMetricPublisher implements MetricPublisher {
@Override
public void publish(final MetricCollection metricCollection) {
/* if (METRIC_COLLECTION_TYPE_API_CALL.equals(metricCollection.name())) {
if (METRIC_COLLECTION_TYPE_API_CALL.equals(metricCollection.name())) {
try {
recordMetricsExecutorService.submit(() -> recordApiCallMetrics(metricCollection));
} catch (final RejectedExecutionException ignored) {
// This can happen if clients make new calls to an upstream service while the server is shutting down
}
} */
}
}
private void recordApiCallMetrics(final MetricCollection apiCallMetricCollection) {