Skip to content

Commit

Permalink
Remove hostname from metrics key
Browse files Browse the repository at this point in the history
### What changes are proposed in this pull request?

Remove hostname from metrics key

### Why are the changes needed?

For easy aggregation on prometheus and grafana side

### Does this PR introduce any user facing changes?

Add a flag to disable this for compatibility

			pr-link: #18121
			change-id: cid-ba6c2f9fae625747192044168fce7dc026c66b9c
  • Loading branch information
beinan authored Sep 11, 2023
1 parent 466fc05 commit 6165c0d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
10 changes: 10 additions & 0 deletions dora/core/common/src/main/java/alluxio/conf/PropertyKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,14 @@ 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 @@ -7042,6 +7050,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 dora/core/common/src/main/java/alluxio/metrics/MetricsSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,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 @@ -483,10 +485,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 6165c0d

Please sign in to comment.