Skip to content

Commit

Permalink
[ALLUXIO-3204] Allow users to set app id (#7370)
Browse files Browse the repository at this point in the history
* Allow users to set app id.

* Clarify the app id invariants.
  • Loading branch information
calvinjia committed Jun 12, 2018
1 parent bb82f12 commit f124281
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
Expand Up @@ -89,7 +89,7 @@ public final class FileSystemContext implements Closeable {
private MetricsMasterClient mMetricsMasterClient;
private ClientMasterSync mClientMasterSync;

private final long mId;
private final String mAppId;

// The netty data server channel pools.
private final ConcurrentHashMap<SocketAddress, NettyChannelPool>
Expand Down Expand Up @@ -165,11 +165,11 @@ private FileSystemContext(Subject subject) {
mParentSubject = subject;
mExecutorService = Executors.newFixedThreadPool(1,
ThreadFactoryUtils.build("metrics-master-heartbeat-%d", true));
mId = IdUtils.createFileSystemContextId();
LOG.info("Created filesystem context with id {}."
+ " This ID will be used for identifying the information "
+ "aggregated by the master, such as metrics",
mId);
mAppId = Configuration.containsKey(PropertyKey.USER_APP_ID)
? Configuration.get(PropertyKey.USER_APP_ID) : IdUtils.createFileSystemContextId();
LOG.info("Created filesystem context with id {}. This ID will be used for identifying info "
+ "from the client, such as metrics. It can be set manually through the {} property",
mAppId, PropertyKey.Name.USER_APP_ID);
mClosed = new AtomicBoolean(false);
}

Expand Down Expand Up @@ -246,8 +246,8 @@ public synchronized void reset() throws IOException {
/**
* @return the unique id of the context
*/
public long getId() {
return mId;
public String getId() {
return mAppId;
}

/**
Expand Down
Expand Up @@ -56,7 +56,7 @@ public ClientMasterSync(MetricsMasterClient masterClient, FileSystemContext cont
public void heartbeat() throws InterruptedException {
List<alluxio.thrift.Metric> metrics = new ArrayList<>();
for (Metric metric : MetricsSystem.allClientMetrics()) {
metric.setInstanceId(Long.toString(mContext.getId()));
metric.setInstanceId(mContext.getId());
metrics.add(metric.toThrift());
}
try {
Expand Down
Expand Up @@ -83,7 +83,7 @@ protected void afterConnect() {
public synchronized void heartbeat(final List<Metric> metrics) throws IOException {
connect();
try {
mClient.metricsHeartbeat(Long.toString(FileSystemContext.get().getId()),
mClient.metricsHeartbeat(FileSystemContext.get().getId(),
NetworkAddressUtils.getClientHostName(), new MetricsHeartbeatTOptions(metrics));
} catch (AlluxioTException e) {
throw AlluxioStatusException.fromThrift(e);
Expand Down
10 changes: 10 additions & 0 deletions core/common/src/main/java/alluxio/PropertyKey.java
Expand Up @@ -2458,6 +2458,15 @@ public String toString() {
.setConsistencyCheckLevel(ConsistencyCheckLevel.WARN)
.setScope(Scope.CLIENT)
.build();
public static final PropertyKey USER_APP_ID =
new Builder(Name.USER_APP_ID)
.setScope(Scope.CLIENT)
.setDescription("The custom id to use for labeling this client's info, such as metrics. "
+ "If unset, a random long will be used. This value is displayed in the client logs "
+ "on initialization. Note that using the same app id will cause client info to be "
+ "aggregated, so different applications must set their own ids or leave this value "
+ "unset to use a randomly generated id.")
.build();
public static final PropertyKey USER_NETWORK_NETTY_CHANNEL =
new Builder(Name.USER_NETWORK_NETTY_CHANNEL)
.setDescription("Type of netty channels.")
Expand Down Expand Up @@ -3401,6 +3410,7 @@ public static final class Name {
"alluxio.user.metrics.collection.enabled";
public static final String USER_METRICS_HEARTBEAT_INTERVAL_MS =
"alluxio.user.metrics.heartbeat.interval";
public static final String USER_APP_ID = "alluxio.user.app.id";
public static final String USER_NETWORK_NETTY_CHANNEL = "alluxio.user.network.netty.channel";
public static final String USER_NETWORK_NETTY_TIMEOUT_MS =
"alluxio.user.network.netty.timeout";
Expand Down
6 changes: 3 additions & 3 deletions core/common/src/main/java/alluxio/util/IdUtils.java
Expand Up @@ -93,9 +93,9 @@ public static long createMountId() {
}

/**
* @return a positive random long
* @return app suffixed by a positive random long
*/
public static long createFileSystemContextId() {
return Math.abs(sRandom.nextLong());
public static String createFileSystemContextId() {
return "app-" + Math.abs(sRandom.nextLong());
}
}

0 comments on commit f124281

Please sign in to comment.