Skip to content

Commit

Permalink
cherry-pick Remove hostname from metrics key
Browse files Browse the repository at this point in the history
  • Loading branch information
jja725 committed Jun 12, 2024
1 parent 3e520f1 commit 272aee5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
9 changes: 9 additions & 0 deletions core/common/src/main/java/alluxio/conf/PropertyKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 =
Expand Down
14 changes: 12 additions & 2 deletions core/common/src/main/java/alluxio/metrics/MetricsSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public final class MetricsSystem {
private static final ConcurrentHashMap<String, String> 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<AlluxioURI, String> CACHED_ESCAPED_PATH
= new ConcurrentHashMap<>();
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit 272aee5

Please sign in to comment.