Skip to content

Commit 7f72478

Browse files
committed
Fix metrics
1 parent d96fe2c commit 7f72478

File tree

5 files changed

+22
-17
lines changed

5 files changed

+22
-17
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ repositories {
3535
dependencies {
3636
errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")
3737
errorprone("com.google.errorprone:error_prone_core:2.3.1")
38-
compile group: 'com.uber.cadence', name: 'cadence-client', version: '2.7.8'
38+
compile group: 'com.uber.cadence', name: 'cadence-client', version: '3.0.0'
3939
compile group: 'commons-configuration', name: 'commons-configuration', version: '1.9'
4040
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
4141
compile group: 'com.uber.m3', name: 'tally-core', version: '0.10.0'

src/main/java/com/uber/cadence/samples/common/QueryWorkflowExecution.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717

1818
package com.uber.cadence.samples.common;
1919

20-
import static com.uber.cadence.samples.common.SampleConstants.DOMAIN;
21-
2220
import com.uber.cadence.WorkflowExecution;
2321
import com.uber.cadence.client.WorkflowClient;
2422
import com.uber.cadence.client.WorkflowStub;
23+
import com.uber.cadence.serviceclient.ClientOptions;
2524
import com.uber.cadence.serviceclient.IWorkflowService;
2625
import com.uber.cadence.serviceclient.WorkflowServiceTChannel;
2726
import java.util.Optional;
@@ -42,7 +41,7 @@ public static void main(String[] args) throws Exception {
4241
+ " <queryType> <workflowId> [<runId>]");
4342
System.exit(1);
4443
}
45-
IWorkflowService cadenceService = new WorkflowServiceTChannel();
44+
IWorkflowService cadenceService = new WorkflowServiceTChannel(ClientOptions.defaultInstance());
4645

4746
String queryType = args[0];
4847

@@ -53,7 +52,7 @@ public static void main(String[] args) throws Exception {
5352
String runId = args[1];
5453
workflowExecution.setRunId(runId);
5554
}
56-
WorkflowClient client = WorkflowClient.newInstance(cadenceService, DOMAIN);
55+
WorkflowClient client = WorkflowClient.newInstance(cadenceService);
5756
WorkflowStub workflow = client.newUntypedWorkflowStub(workflowExecution, Optional.empty());
5857
String result = workflow.query(queryType, String.class);
5958

src/main/java/com/uber/cadence/samples/common/RegisterDomain.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.uber.cadence.DomainAlreadyExistsError;
2323
import com.uber.cadence.RegisterDomainRequest;
24+
import com.uber.cadence.serviceclient.ClientOptions;
2425
import com.uber.cadence.serviceclient.IWorkflowService;
2526
import com.uber.cadence.serviceclient.WorkflowServiceTChannel;
2627
import java.io.IOException;
@@ -34,7 +35,7 @@
3435
public class RegisterDomain {
3536

3637
public static void main(String[] args) throws TException, IOException {
37-
IWorkflowService cadenceService = new WorkflowServiceTChannel();
38+
IWorkflowService cadenceService = new WorkflowServiceTChannel(ClientOptions.defaultInstance());
3839
RegisterDomainRequest request = new RegisterDomainRequest();
3940
request.setDescription("Java Samples");
4041
request.setEmitMetric(false);

src/main/java/com/uber/cadence/samples/common/WorkflowExecutionHistoryPrinter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.uber.cadence.WorkflowExecution;
2323
import com.uber.cadence.internal.common.WorkflowExecutionUtils;
24+
import com.uber.cadence.serviceclient.ClientOptions;
2425
import com.uber.cadence.serviceclient.IWorkflowService;
2526
import com.uber.cadence.serviceclient.WorkflowServiceTChannel;
2627

@@ -39,7 +40,7 @@ public static void main(String[] args) throws Exception {
3940
+ " <workflowId> <runId>");
4041
System.exit(1);
4142
}
42-
IWorkflowService cadenceService = new WorkflowServiceTChannel();
43+
IWorkflowService cadenceService = new WorkflowServiceTChannel(ClientOptions.defaultInstance());
4344
WorkflowExecution workflowExecution = new WorkflowExecution();
4445
String workflowId = args[0];
4546
workflowExecution.setWorkflowId(workflowId);

src/main/java/com/uber/cadence/samples/hello/HelloMetric.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
package com.uber.cadence.samples.hello;
1919

20-
import static com.uber.cadence.samples.common.SampleConstants.DOMAIN;
21-
2220
import com.uber.cadence.activity.ActivityMethod;
2321
import com.uber.cadence.client.WorkflowClient;
22+
import com.uber.cadence.serviceclient.ClientOptions;
23+
import com.uber.cadence.serviceclient.IWorkflowService;
24+
import com.uber.cadence.serviceclient.WorkflowServiceTChannel;
2425
import com.uber.cadence.worker.Worker;
26+
import com.uber.cadence.worker.WorkerFactory;
2527
import com.uber.cadence.worker.WorkerOptions;
2628
import com.uber.cadence.workflow.Workflow;
2729
import com.uber.cadence.workflow.WorkflowMethod;
@@ -91,21 +93,21 @@ public String composeGreeting(String greeting, String name) {
9193
}
9294

9395
public static void main(String[] args) throws IOException {
96+
final ClientOptions clientOptions =
97+
ClientOptions.newBuilder().setMetricsScope(createMetricScope()).build();
98+
// final ClientOptions clientOptions = ClientOptions.newBuilder().build();
99+
IWorkflowService service = new WorkflowServiceTChannel(clientOptions);
100+
final WorkflowClient workflowClient = WorkflowClient.newInstance(service);
94101
// Start a worker that hosts both workflow and activity implementations.
95-
Worker.Factory factory = new Worker.Factory(DOMAIN);
96-
PrometheusReporter.builder().registry(CollectorRegistry.defaultRegistry).build();
97-
final WorkerOptions workerOptions =
98-
new WorkerOptions.Builder().setMetricsScope(createMetricScope()).build();
99-
Worker worker = factory.newWorker(TASK_LIST, workerOptions);
102+
WorkerFactory factory = WorkerFactory.newInstance(workflowClient);
103+
Worker worker = factory.newWorker(TASK_LIST, WorkerOptions.defaultInstance());
100104
// Workflows are stateful. So you need a type to create instances.
101105
worker.registerWorkflowImplementationTypes(GreetingWorkflowImpl.class);
102106
// Activities are stateless and thread safe. So a shared instance is used.
103107
worker.registerActivitiesImplementations(new GreetingActivitiesImpl());
104108
// Start listening to the workflow and activity task lists.
105109
factory.start();
106110

107-
// Start a workflow execution. Usually this is done from another program.
108-
WorkflowClient workflowClient = WorkflowClient.newInstance(DOMAIN);
109111
// Get a workflow stub using the same task list the worker uses.
110112
GreetingWorkflow workflow = workflowClient.newWorkflowStub(GreetingWorkflow.class);
111113
// Execute a workflow waiting for it to complete.
@@ -117,7 +119,9 @@ private static Scope createMetricScope() throws IOException {
117119
CollectorRegistry registry = CollectorRegistry.defaultRegistry;
118120
HTTPServer httpServer = new HTTPServer(new InetSocketAddress(9098), registry);
119121
PrometheusReporter reporter = PrometheusReporter.builder().registry(registry).build();
120-
Scope scope = new RootScopeBuilder().reporter(reporter).reportEvery(Duration.ofSeconds(1));
122+
// Make sure to set separator to "_" for Prometheus. Default is "." and doesn't work.
123+
Scope scope =
124+
new RootScopeBuilder().separator("_").reporter(reporter).reportEvery(Duration.ofSeconds(1));
121125
return new PrometheusScope(scope);
122126
}
123127
}

0 commit comments

Comments
 (0)