Skip to content

Commit

Permalink
Add metric tag to differentiate long-poll and normal request (#653)
Browse files Browse the repository at this point in the history
  • Loading branch information
longquanzheng authored Nov 23, 2021
1 parent 216a287 commit f90070c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ public class MetricsTag {
public static final String WORKER_TYPE = "WorkerType";
public static final String SIDE_EFFECT_ID = "SideEffectID";
public static final String CHILD_WORKFLOW_ID = "ChildWorkflowID";
public static final String REQUEST_TYPE = "RequestType";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Modifications copyright (C) 2017 Uber Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. A copy of the License is
* located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package com.uber.cadence.internal.metrics;

public class MetricsTagValue {
public static final String REQUEST_TYPE_NORMAL = "normal";
public static final String REQUEST_TYPE_LONG_POLL = "long-poll";
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
import com.uber.cadence.internal.Version;
import com.uber.cadence.internal.common.CheckedExceptionWrapper;
import com.uber.cadence.internal.common.InternalUtils;
import com.uber.cadence.internal.metrics.MetricsTag;
import com.uber.cadence.internal.metrics.MetricsType;
import com.uber.cadence.internal.metrics.ServiceMethod;
import com.uber.m3.tally.Scope;
Expand All @@ -109,6 +110,12 @@
import com.uber.tchannel.messages.ThriftRequest;
import com.uber.tchannel.messages.ThriftResponse;
import com.uber.tchannel.messages.generated.Meta;
import org.apache.thrift.TException;
import org.apache.thrift.async.AsyncMethodCallback;
import org.apache.thrift.transport.TTransportException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
Expand All @@ -119,11 +126,9 @@
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import org.apache.thrift.TException;
import org.apache.thrift.async.AsyncMethodCallback;
import org.apache.thrift.transport.TTransportException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.uber.cadence.internal.metrics.MetricsTagValue.REQUEST_TYPE_LONG_POLL;
import static com.uber.cadence.internal.metrics.MetricsTagValue.REQUEST_TYPE_NORMAL;

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

private <T> T measureRemoteCall(String scopeName, RemoteCall<T> call) throws TException {
return measureRemoteCallWithTags(scopeName, call, null);
}

private <T> T measureRemoteCallWithTags(String scopeName, RemoteCall<T> call, Map<String, String> tags) throws TException {
Scope scope = options.getMetricsScope().subScope(scopeName);
if (tags != null) {
scope = scope.tagged(tags);
}
scope.counter(MetricsType.CADENCE_REQUEST).inc(1);
Stopwatch sw = scope.timer(MetricsType.CADENCE_LATENCY).start();
try {
Expand Down Expand Up @@ -665,17 +677,21 @@ private StartWorkflowExecutionResponse startWorkflowExecution(
@Override
public GetWorkflowExecutionHistoryResponse GetWorkflowExecutionHistoryWithTimeout(
GetWorkflowExecutionHistoryRequest request, Long timeoutInMillis) throws TException {
return measureRemoteCall(
ServiceMethod.GET_WORKFLOW_EXECUTION_HISTORY,
() -> getWorkflowExecutionHistory(request, timeoutInMillis));
Map<String, String> tags = ImmutableMap.of(MetricsTag.REQUEST_TYPE, request.isWaitForNewEvent() ? REQUEST_TYPE_LONG_POLL : REQUEST_TYPE_NORMAL);
return measureRemoteCallWithTags(
ServiceMethod.GET_WORKFLOW_EXECUTION_HISTORY,
() -> getWorkflowExecutionHistory(request, timeoutInMillis),
tags);
}

@Override
public GetWorkflowExecutionHistoryResponse GetWorkflowExecutionHistory(
GetWorkflowExecutionHistoryRequest request) throws TException {
return measureRemoteCall(
ServiceMethod.GET_WORKFLOW_EXECUTION_HISTORY,
() -> getWorkflowExecutionHistory(request, null));
Map<String, String> tags = ImmutableMap.of(MetricsTag.REQUEST_TYPE, request.isWaitForNewEvent() ? REQUEST_TYPE_LONG_POLL : REQUEST_TYPE_NORMAL);
return measureRemoteCallWithTags(
ServiceMethod.GET_WORKFLOW_EXECUTION_HISTORY,
() -> getWorkflowExecutionHistory(request, null),
tags);
}

private GetWorkflowExecutionHistoryResponse getWorkflowExecutionHistory(
Expand Down

0 comments on commit f90070c

Please sign in to comment.