Skip to content

Commit 927329c

Browse files
Cdnc 1692 emit version (#745)
* emitting java client version that is used for a specific domain.
1 parent 365c46d commit 927329c

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
7+
* use this file except in compliance with the License. A copy of the License is
8+
* located at
9+
*
10+
* http://aws.amazon.com/apache2.0
11+
*
12+
* or in the "license" file accompanying this file. This file is distributed on
13+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+
* express or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
18+
package com.uber.cadence.internal.metrics;
19+
20+
import com.uber.cadence.internal.Version;
21+
import com.uber.m3.tally.Scope;
22+
import com.uber.m3.util.ImmutableMap;
23+
import java.io.IOException;
24+
import java.io.InputStream;
25+
import java.util.Map;
26+
import java.util.Properties;
27+
28+
public class ClientVersionEmitter implements Runnable {
29+
30+
private Scope metricScope;
31+
32+
public ClientVersionEmitter(Scope metricScope, String domain) {
33+
if (domain == null) {
34+
domain = "UNKNOWN";
35+
}
36+
37+
Properties prop = new Properties();
38+
InputStream in = Version.class.getResourceAsStream("/com/uber/cadence/version.properties");
39+
String version = "";
40+
try {
41+
prop.load(in);
42+
version = prop.getProperty("cadence-client-version");
43+
} catch (IOException exception) {
44+
version = "UNKNOWN";
45+
}
46+
47+
Map<String, String> tags =
48+
new ImmutableMap.Builder<String, String>(2)
49+
.put(MetricsTag.VERSION, version)
50+
.put(MetricsTag.DOMAIN, domain)
51+
.build();
52+
53+
if (metricScope == null) {
54+
this.metricScope = NoopScope.getInstance();
55+
} else {
56+
this.metricScope = metricScope.tagged(tags);
57+
}
58+
}
59+
60+
@Override
61+
public void run() {
62+
metricScope.counter(MetricsType.JAVA_CLIENT_VERSION).inc(1);
63+
}
64+
}

src/main/java/com/uber/cadence/internal/metrics/MetricsTag.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ public class MetricsTag {
3333
public static final String SIDE_EFFECT_ID = "SideEffectID";
3434
public static final String CHILD_WORKFLOW_ID = "ChildWorkflowID";
3535
public static final String REQUEST_TYPE = "RequestType";
36+
public static final String VERSION = "Version";
3637
}

src/main/java/com/uber/cadence/internal/metrics/MetricsType.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,6 @@ public class MetricsType {
170170
public static final String REPLAY_SKIPPED_COUNTER = CADENCE_METRICS_PREFIX + "replay-skipped";
171171
public static final String REPLAY_SUCCESS_COUNTER = CADENCE_METRICS_PREFIX + "replay-succeed";
172172
public static final String REPLAY_LATENCY = CADENCE_METRICS_PREFIX + "replay-latency";
173+
174+
public static final String JAVA_CLIENT_VERSION = CADENCE_METRICS_PREFIX + "java-client-version";
173175
}

src/main/java/com/uber/cadence/internal/sync/WorkflowClientInternal.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.uber.cadence.internal.external.GenericWorkflowClientExternalImpl;
3232
import com.uber.cadence.internal.external.ManualActivityCompletionClientFactory;
3333
import com.uber.cadence.internal.external.ManualActivityCompletionClientFactoryImpl;
34+
import com.uber.cadence.internal.metrics.ClientVersionEmitter;
3435
import com.uber.cadence.internal.sync.WorkflowInvocationHandler.InvocationType;
3536
import com.uber.cadence.serviceclient.IWorkflowService;
3637
import com.uber.cadence.workflow.Functions;
@@ -43,6 +44,9 @@
4344
import java.util.Objects;
4445
import java.util.Optional;
4546
import java.util.concurrent.CompletableFuture;
47+
import java.util.concurrent.Executors;
48+
import java.util.concurrent.TimeUnit;
49+
4650
import org.apache.thrift.TException;
4751

4852
public final class WorkflowClientInternal implements WorkflowClient {
@@ -52,6 +56,7 @@ public final class WorkflowClientInternal implements WorkflowClient {
5256
private final WorkflowClientInterceptor[] interceptors;
5357
private final IWorkflowService workflowService;
5458
private final WorkflowClientOptions clientOptions;
59+
private static boolean emittingClientVersion = false;
5560

5661
/**
5762
* Creates client that connects to an instance of the Cadence Service.
@@ -64,6 +69,8 @@ public static WorkflowClient newInstance(
6469
IWorkflowService service, WorkflowClientOptions options) {
6570
Objects.requireNonNull(service);
6671
Objects.requireNonNull(options);
72+
73+
emitClientVersion(options);
6774
return new WorkflowClientInternal(service, options);
6875
}
6976

@@ -400,4 +407,18 @@ public static <A1, A2, A3, A4, A5, A6, R> CompletableFuture<R> execute(
400407
A6 arg6) {
401408
return execute(() -> workflow.apply(arg1, arg2, arg3, arg4, arg5, arg6));
402409
}
410+
411+
private synchronized static void emitClientVersion(WorkflowClientOptions options) {
412+
if (emittingClientVersion) {
413+
return;
414+
}
415+
416+
emittingClientVersion = true;
417+
Executors.newSingleThreadScheduledExecutor()
418+
.scheduleAtFixedRate(
419+
new ClientVersionEmitter(options.getMetricsScope(), options.getDomain()),
420+
30,
421+
60,
422+
TimeUnit.SECONDS);
423+
}
403424
}

0 commit comments

Comments
 (0)