Skip to content

Commit

Permalink
Put init source to MetricsSystem.init
Browse files Browse the repository at this point in the history
  • Loading branch information
LuQQiu committed Feb 12, 2020
1 parent fb44a91 commit 8bb0883
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 32 deletions.
66 changes: 34 additions & 32 deletions core/common/src/main/java/alluxio/metrics/MetricsSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public final class MetricsSystem {
private static final Logger LOG = LoggerFactory.getLogger(MetricsSystem.class);

private static final ConcurrentHashMap<String, String> CACHED_METRICS = new ConcurrentHashMap<>();
private static final AlluxioConfiguration
CONF = new InstancedConfiguration(ConfigurationUtils.defaults());
private static int sResolveTimeout =
(int) new InstancedConfiguration(ConfigurationUtils.defaults())
.getMs(PropertyKey.NETWORK_HOST_RESOLUTION_TIMEOUT_MS);
Expand Down Expand Up @@ -145,8 +143,9 @@ public static InstanceType fromString(String text) {
private static final int MINIMAL_POLL_PERIOD = 1;

/**
* Starts sinks specified in the configuration. This is an no-op if the sinks have already been
* started. Note: This has to be called after Alluxio configuration is initialized.
* Starts sinks specified in the configuration.
* This is an no-op if the sinks have already been started.
* Note: This has to be called after Alluxio configuration is initialized.
*
* @param metricsConfFile the location of the metrics configuration file
*/
Expand All @@ -165,6 +164,37 @@ public static void startSinks(String metricsConfFile) {
startSinksFromConfig(config);
}

/**
* Initialize the {@link MetricsSystem}.
* This should be called after setting the {@link CommonUtils#PROCESS_TYPE}
* and before creating any metric in the current process.
*/
public static void init() {
PropertyKey sourceKey = null;
switch (CommonUtils.PROCESS_TYPE.get()) {
case MASTER:
sourceKey = PropertyKey.MASTER_HOSTNAME;
break;
case WORKER:
sourceKey = PropertyKey.WORKER_HOSTNAME;
break;
case CLIENT:
sourceKey = PropertyKey.USER_APP_ID;
break;
case JOB_MASTER:
sourceKey = PropertyKey.JOB_MASTER_HOSTNAME;
break;
case JOB_WORKER:
sourceKey = PropertyKey.JOB_WORKER_HOSTNAME;
break;
default:
break;
}
AlluxioConfiguration conf = new InstancedConfiguration(ConfigurationUtils.defaults());
sSourceName = sourceKey != null && conf.isSet(sourceKey)
? conf.get(sourceKey) : NetworkAddressUtils.getLocalHostMetricName(sResolveTimeout);
}

/**
* Starts sinks from a given metrics configuration. This is made public for unit test.
*
Expand Down Expand Up @@ -347,34 +377,6 @@ public static String getJobWorkerMetricName(String name) {
* @return the metric registry name
*/
private static String getMetricNameWithUniqueId(InstanceType instance, String name) {
if (sSourceName == null) {
switch (instance) {
case CLIENT:
if (CONF.isSet(PropertyKey.USER_APP_ID)) {
sSourceName = CONF.get(PropertyKey.USER_APP_ID);
} else {
sSourceName = NetworkAddressUtils.getLocalHostMetricName(sResolveTimeout);
}
break;
case WORKER:
if (CONF.isSet(PropertyKey.WORKER_HOSTNAME)) {
sSourceName = CONF.get(PropertyKey.WORKER_HOSTNAME);
} else {
sSourceName = NetworkAddressUtils.getLocalHostMetricName(sResolveTimeout);
}
break;
case JOB_WORKER:
if (CONF.isSet(PropertyKey.JOB_WORKER_HOSTNAME)) {
sSourceName = CONF.get(PropertyKey.JOB_WORKER_HOSTNAME);
} else {
sSourceName = NetworkAddressUtils.getLocalHostMetricName(sResolveTimeout);
}
break;
default:
sSourceName = NetworkAddressUtils.getLocalHostMetricName(sResolveTimeout);
break;
}
}
if (name.startsWith(instance.toString())) {
return Joiner.on(".").join(name, sSourceName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import alluxio.ProcessUtils;
import alluxio.RuntimeConstants;
import alluxio.metrics.MetricsSystem;
import alluxio.util.CommonUtils;

import org.slf4j.Logger;
Expand Down Expand Up @@ -40,6 +41,7 @@ public static void main(String[] args) {
}

CommonUtils.PROCESS_TYPE.set(CommonUtils.ProcessType.MASTER);
MetricsSystem.init();
MasterProcess process;
try {
process = AlluxioMasterProcess.Factory.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import alluxio.ProcessUtils;
import alluxio.RuntimeConstants;
import alluxio.conf.ServerConfiguration;
import alluxio.metrics.MetricsSystem;
import alluxio.util.CommonUtils;
import alluxio.util.ConfigurationUtils;

Expand Down Expand Up @@ -47,6 +48,7 @@ public static void main(String[] args) {
}

CommonUtils.PROCESS_TYPE.set(CommonUtils.ProcessType.PROXY);
MetricsSystem.init();
ProxyProcess process;
try {
process = ProxyProcess.Factory.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import alluxio.conf.PropertyKey;
import alluxio.RuntimeConstants;
import alluxio.master.MasterInquireClient;
import alluxio.metrics.MetricsSystem;
import alluxio.retry.RetryUtils;
import alluxio.security.user.ServerUserState;
import alluxio.util.CommonUtils;
Expand Down Expand Up @@ -54,6 +55,7 @@ public static void main(String[] args) {
}

CommonUtils.PROCESS_TYPE.set(CommonUtils.ProcessType.WORKER);
MetricsSystem.init();
MasterInquireClient masterInquireClient =
MasterInquireClient.Factory.create(ServerConfiguration.global(), ServerUserState.global());
try {
Expand Down
2 changes: 2 additions & 0 deletions job/server/src/main/java/alluxio/master/AlluxioJobMaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import alluxio.ProcessUtils;
import alluxio.RuntimeConstants;
import alluxio.metrics.MetricsSystem;
import alluxio.util.CommonUtils;

import org.slf4j.Logger;
Expand Down Expand Up @@ -40,6 +41,7 @@ public static void main(String[] args) {
}

CommonUtils.PROCESS_TYPE.set(alluxio.util.CommonUtils.ProcessType.JOB_MASTER);
MetricsSystem.init();
AlluxioJobMasterProcess process;
try {
process = AlluxioJobMasterProcess.Factory.create();
Expand Down
2 changes: 2 additions & 0 deletions job/server/src/main/java/alluxio/worker/AlluxioJobWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import alluxio.conf.PropertyKey;
import alluxio.RuntimeConstants;
import alluxio.master.MasterInquireClient;
import alluxio.metrics.MetricsSystem;
import alluxio.retry.RetryUtils;
import alluxio.security.user.ServerUserState;
import alluxio.util.CommonUtils;
Expand Down Expand Up @@ -61,6 +62,7 @@ public static void main(String[] args) {
}

CommonUtils.PROCESS_TYPE.set(CommonUtils.ProcessType.JOB_WORKER);
MetricsSystem.init();
MasterInquireClient masterInquireClient =
MasterInquireClient.Factory.create(ServerConfiguration.global(), ServerUserState.global());
try {
Expand Down

0 comments on commit 8bb0883

Please sign in to comment.