Skip to content

Commit f90070c

Browse files
Add metric tag to differentiate long-poll and normal request (#653)
1 parent 216a287 commit f90070c

File tree

3 files changed

+51
-11
lines changed

3 files changed

+51
-11
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ public class MetricsTag {
3232
public static final String WORKER_TYPE = "WorkerType";
3333
public static final String SIDE_EFFECT_ID = "SideEffectID";
3434
public static final String CHILD_WORKFLOW_ID = "ChildWorkflowID";
35+
public static final String REQUEST_TYPE = "RequestType";
3536
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
public class MetricsTagValue {
21+
public static final String REQUEST_TYPE_NORMAL = "normal";
22+
public static final String REQUEST_TYPE_LONG_POLL = "long-poll";
23+
}

src/main/java/com/uber/cadence/serviceclient/WorkflowServiceTChannel.java

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
import com.uber.cadence.internal.Version;
9797
import com.uber.cadence.internal.common.CheckedExceptionWrapper;
9898
import com.uber.cadence.internal.common.InternalUtils;
99+
import com.uber.cadence.internal.metrics.MetricsTag;
99100
import com.uber.cadence.internal.metrics.MetricsType;
100101
import com.uber.cadence.internal.metrics.ServiceMethod;
101102
import com.uber.m3.tally.Scope;
@@ -109,6 +110,12 @@
109110
import com.uber.tchannel.messages.ThriftRequest;
110111
import com.uber.tchannel.messages.ThriftResponse;
111112
import com.uber.tchannel.messages.generated.Meta;
113+
import org.apache.thrift.TException;
114+
import org.apache.thrift.async.AsyncMethodCallback;
115+
import org.apache.thrift.transport.TTransportException;
116+
import org.slf4j.Logger;
117+
import org.slf4j.LoggerFactory;
118+
112119
import java.net.InetAddress;
113120
import java.net.InetSocketAddress;
114121
import java.net.UnknownHostException;
@@ -119,11 +126,9 @@
119126
import java.util.UUID;
120127
import java.util.concurrent.CompletableFuture;
121128
import java.util.concurrent.ExecutionException;
122-
import org.apache.thrift.TException;
123-
import org.apache.thrift.async.AsyncMethodCallback;
124-
import org.apache.thrift.transport.TTransportException;
125-
import org.slf4j.Logger;
126-
import org.slf4j.LoggerFactory;
129+
130+
import static com.uber.cadence.internal.metrics.MetricsTagValue.REQUEST_TYPE_LONG_POLL;
131+
import static com.uber.cadence.internal.metrics.MetricsTagValue.REQUEST_TYPE_NORMAL;
127132

128133
public class WorkflowServiceTChannel implements IWorkflowService {
129134
private static final Logger log = LoggerFactory.getLogger(WorkflowServiceTChannel.class);
@@ -355,7 +360,14 @@ interface RemoteCall<T> {
355360
}
356361

357362
private <T> T measureRemoteCall(String scopeName, RemoteCall<T> call) throws TException {
363+
return measureRemoteCallWithTags(scopeName, call, null);
364+
}
365+
366+
private <T> T measureRemoteCallWithTags(String scopeName, RemoteCall<T> call, Map<String, String> tags) throws TException {
358367
Scope scope = options.getMetricsScope().subScope(scopeName);
368+
if (tags != null) {
369+
scope = scope.tagged(tags);
370+
}
359371
scope.counter(MetricsType.CADENCE_REQUEST).inc(1);
360372
Stopwatch sw = scope.timer(MetricsType.CADENCE_LATENCY).start();
361373
try {
@@ -665,17 +677,21 @@ private StartWorkflowExecutionResponse startWorkflowExecution(
665677
@Override
666678
public GetWorkflowExecutionHistoryResponse GetWorkflowExecutionHistoryWithTimeout(
667679
GetWorkflowExecutionHistoryRequest request, Long timeoutInMillis) throws TException {
668-
return measureRemoteCall(
669-
ServiceMethod.GET_WORKFLOW_EXECUTION_HISTORY,
670-
() -> getWorkflowExecutionHistory(request, timeoutInMillis));
680+
Map<String, String> tags = ImmutableMap.of(MetricsTag.REQUEST_TYPE, request.isWaitForNewEvent() ? REQUEST_TYPE_LONG_POLL : REQUEST_TYPE_NORMAL);
681+
return measureRemoteCallWithTags(
682+
ServiceMethod.GET_WORKFLOW_EXECUTION_HISTORY,
683+
() -> getWorkflowExecutionHistory(request, timeoutInMillis),
684+
tags);
671685
}
672686

673687
@Override
674688
public GetWorkflowExecutionHistoryResponse GetWorkflowExecutionHistory(
675689
GetWorkflowExecutionHistoryRequest request) throws TException {
676-
return measureRemoteCall(
677-
ServiceMethod.GET_WORKFLOW_EXECUTION_HISTORY,
678-
() -> getWorkflowExecutionHistory(request, null));
690+
Map<String, String> tags = ImmutableMap.of(MetricsTag.REQUEST_TYPE, request.isWaitForNewEvent() ? REQUEST_TYPE_LONG_POLL : REQUEST_TYPE_NORMAL);
691+
return measureRemoteCallWithTags(
692+
ServiceMethod.GET_WORKFLOW_EXECUTION_HISTORY,
693+
() -> getWorkflowExecutionHistory(request, null),
694+
tags);
679695
}
680696

681697
private GetWorkflowExecutionHistoryResponse getWorkflowExecutionHistory(

0 commit comments

Comments
 (0)