Skip to content

Commit 361c60a

Browse files
authored
Update metric system with cherry-pick Remove hostname from metrics key
### What changes are proposed in this pull request? cherry-pick #18121 ### Why are the changes needed? Please clarify why the changes are needed. For instance, 1. If you propose a new API, clarify the use case for a new API. 2. If you fix a bug, describe the bug. ### Does this PR introduce any user facing changes? Please list the user-facing changes introduced by your change, including 1. change in user-facing APIs 2. addition or removal of property keys 3. webui pr-link: #18626 change-id: cid-31f20b47904c5f32c9c11c08f3155cfcdcbf4e16
1 parent e9f2913 commit 361c60a

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

core/common/src/main/java/alluxio/conf/PropertyKey.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,13 @@ public String toString() {
706706
.setScope(Scope.ALL)
707707
.setConsistencyCheckLevel(ConsistencyCheckLevel.IGNORE)
708708
.build();
709+
public static final PropertyKey METRICS_KEY_INCLUDING_UNIQUE_ID_ENABLED =
710+
booleanBuilder(Name.METRICS_KEY_INCLUDING_UNIQUE_ID_ENABLED)
711+
.setDefaultValue(false)
712+
.setDescription("Whether to include the unique id such as hostname in the metrcis key.")
713+
.setConsistencyCheckLevel(ConsistencyCheckLevel.WARN)
714+
.setScope(Scope.ALL)
715+
.build();
709716
public static final PropertyKey NETWORK_CONNECTION_AUTH_TIMEOUT =
710717
durationBuilder(Name.NETWORK_CONNECTION_AUTH_TIMEOUT)
711718
.setDefaultValue("30sec")
@@ -7832,6 +7839,8 @@ public static final class Name {
78327839
"alluxio.metrics.executor.task.warn.size";
78337840
public static final String METRICS_EXECUTOR_TASK_WARN_FREQUENCY =
78347841
"alluxio.metrics.executor.task.warn.frequency";
7842+
public static final String METRICS_KEY_INCLUDING_UNIQUE_ID_ENABLED =
7843+
"alluxio.metrics.key.including.unique.id.enabled";
78357844
public static final String NETWORK_CONNECTION_AUTH_TIMEOUT =
78367845
"alluxio.network.connection.auth.timeout";
78377846
public static final String NETWORK_CONNECTION_HEALTH_CHECK_TIMEOUT =

core/common/src/main/java/alluxio/metrics/MetricsSystem.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public final class MetricsSystem {
7474
private static final ConcurrentHashMap<String, String> CACHED_METRICS = new ConcurrentHashMap<>();
7575
private static int sResolveTimeout =
7676
(int) Configuration.getMs(PropertyKey.NETWORK_HOST_RESOLUTION_TIMEOUT_MS);
77+
private static boolean sUniqueIDEnabled =
78+
Configuration.getBoolean(PropertyKey.METRICS_KEY_INCLUDING_UNIQUE_ID_ENABLED);
7779
// A map from AlluxioURI to corresponding cached escaped path.
7880
private static final ConcurrentHashMap<AlluxioURI, String> CACHED_ESCAPED_PATH
7981
= new ConcurrentHashMap<>();
@@ -482,10 +484,18 @@ public static String getPluginMetricName(String name) {
482484
* @return the metric registry name
483485
*/
484486
private static String getMetricNameWithUniqueId(InstanceType instance, String name) {
487+
String metricsNameWithInstanceType = addInstanceTypeToMetricsName(instance, name);
488+
if (sUniqueIDEnabled) {
489+
return Joiner.on(".").join(metricsNameWithInstanceType, sSourceNameSupplier.get());
490+
}
491+
return metricsNameWithInstanceType;
492+
}
493+
494+
private static String addInstanceTypeToMetricsName(InstanceType instance, String name) {
485495
if (name.startsWith(instance.toString())) {
486-
return Joiner.on(".").join(name, sSourceNameSupplier.get());
496+
return name;
487497
}
488-
return Joiner.on(".").join(instance, name, sSourceNameSupplier.get());
498+
return Joiner.on(".").join(instance, name);
489499
}
490500

491501
/**

core/common/src/test/java/alluxio/metrics/MetricsSystemTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ public void getMetricNameTest() {
201201
assertEquals("Cluster.counter", MetricsSystem.getMetricName("Cluster.counter"));
202202
assertEquals("Master.timer", MetricsSystem.getMetricName("Master.timer"));
203203
String workerGaugeName = "Worker.gauge";
204-
assertNotEquals(workerGaugeName, MetricsSystem.getMetricName(workerGaugeName));
204+
assertEquals(workerGaugeName, MetricsSystem.getMetricName(workerGaugeName));
205205
assertTrue(MetricsSystem.getMetricName(workerGaugeName).startsWith(workerGaugeName));
206206
String clientCounterName = "Client.counter";
207-
assertNotEquals(clientCounterName, MetricsSystem.getMetricName(clientCounterName));
207+
assertEquals(clientCounterName, MetricsSystem.getMetricName(clientCounterName));
208208
assertTrue(MetricsSystem.getMetricName(clientCounterName).startsWith(clientCounterName));
209209
}
210210

0 commit comments

Comments
 (0)