From 272aee5357e9e92ff8e32895e3b6f8e09f17eee3 Mon Sep 17 00:00:00 2001 From: Jianjian Date: Wed, 12 Jun 2024 12:44:09 -0700 Subject: [PATCH] cherry-pick `Remove hostname from metrics key` --- .../src/main/java/alluxio/conf/PropertyKey.java | 9 +++++++++ .../main/java/alluxio/metrics/MetricsSystem.java | 14 ++++++++++++-- .../java/alluxio/metrics/MetricsSystemTest.java | 4 ++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/core/common/src/main/java/alluxio/conf/PropertyKey.java b/core/common/src/main/java/alluxio/conf/PropertyKey.java index ca03396c0300..d1cee4bac0da 100755 --- a/core/common/src/main/java/alluxio/conf/PropertyKey.java +++ b/core/common/src/main/java/alluxio/conf/PropertyKey.java @@ -706,6 +706,13 @@ public String toString() { .setScope(Scope.ALL) .setConsistencyCheckLevel(ConsistencyCheckLevel.IGNORE) .build(); + public static final PropertyKey METRICS_KEY_INCLUDING_UNIQUE_ID_ENABLED = + booleanBuilder(Name.METRICS_KEY_INCLUDING_UNIQUE_ID_ENABLED) + .setDefaultValue(false) + .setDescription("Whether to include the unique id such as hostname in the metrcis key.") + .setConsistencyCheckLevel(ConsistencyCheckLevel.WARN) + .setScope(Scope.ALL) + .build(); public static final PropertyKey NETWORK_CONNECTION_AUTH_TIMEOUT = durationBuilder(Name.NETWORK_CONNECTION_AUTH_TIMEOUT) .setDefaultValue("30sec") @@ -7810,6 +7817,8 @@ public static final class Name { "alluxio.metrics.executor.task.warn.size"; public static final String METRICS_EXECUTOR_TASK_WARN_FREQUENCY = "alluxio.metrics.executor.task.warn.frequency"; + public static final String METRICS_KEY_INCLUDING_UNIQUE_ID_ENABLED = + "alluxio.metrics.key.including.unique.id.enabled"; public static final String NETWORK_CONNECTION_AUTH_TIMEOUT = "alluxio.network.connection.auth.timeout"; public static final String NETWORK_CONNECTION_HEALTH_CHECK_TIMEOUT = diff --git a/core/common/src/main/java/alluxio/metrics/MetricsSystem.java b/core/common/src/main/java/alluxio/metrics/MetricsSystem.java index 780f91c9a3a9..d661be813f62 100644 --- a/core/common/src/main/java/alluxio/metrics/MetricsSystem.java +++ b/core/common/src/main/java/alluxio/metrics/MetricsSystem.java @@ -74,6 +74,8 @@ public final class MetricsSystem { private static final ConcurrentHashMap CACHED_METRICS = new ConcurrentHashMap<>(); private static int sResolveTimeout = (int) Configuration.getMs(PropertyKey.NETWORK_HOST_RESOLUTION_TIMEOUT_MS); + private static boolean sUniqueIDEnabled = + Configuration.getBoolean(PropertyKey.METRICS_KEY_INCLUDING_UNIQUE_ID_ENABLED); // A map from AlluxioURI to corresponding cached escaped path. private static final ConcurrentHashMap CACHED_ESCAPED_PATH = new ConcurrentHashMap<>(); @@ -482,10 +484,18 @@ public static String getPluginMetricName(String name) { * @return the metric registry name */ private static String getMetricNameWithUniqueId(InstanceType instance, String name) { + String metricsNameWithInstanceType = addInstanceTypeToMetricsName(instance, name); + if (sUniqueIDEnabled) { + return Joiner.on(".").join(metricsNameWithInstanceType, sSourceNameSupplier.get()); + } + return metricsNameWithInstanceType; + } + + private static String addInstanceTypeToMetricsName(InstanceType instance, String name) { if (name.startsWith(instance.toString())) { - return Joiner.on(".").join(name, sSourceNameSupplier.get()); + return name; } - return Joiner.on(".").join(instance, name, sSourceNameSupplier.get()); + return Joiner.on(".").join(instance, name); } /** diff --git a/core/common/src/test/java/alluxio/metrics/MetricsSystemTest.java b/core/common/src/test/java/alluxio/metrics/MetricsSystemTest.java index 5f46aa55ccad..3b59eeb64324 100644 --- a/core/common/src/test/java/alluxio/metrics/MetricsSystemTest.java +++ b/core/common/src/test/java/alluxio/metrics/MetricsSystemTest.java @@ -201,10 +201,10 @@ public void getMetricNameTest() { assertEquals("Cluster.counter", MetricsSystem.getMetricName("Cluster.counter")); assertEquals("Master.timer", MetricsSystem.getMetricName("Master.timer")); String workerGaugeName = "Worker.gauge"; - assertNotEquals(workerGaugeName, MetricsSystem.getMetricName(workerGaugeName)); + assertEquals(workerGaugeName, MetricsSystem.getMetricName(workerGaugeName)); assertTrue(MetricsSystem.getMetricName(workerGaugeName).startsWith(workerGaugeName)); String clientCounterName = "Client.counter"; - assertNotEquals(clientCounterName, MetricsSystem.getMetricName(clientCounterName)); + assertEquals(clientCounterName, MetricsSystem.getMetricName(clientCounterName)); assertTrue(MetricsSystem.getMetricName(clientCounterName).startsWith(clientCounterName)); }