diff --git a/temporal-sdk/src/main/java/io/temporal/internal/external/GenericWorkflowClientExternalImpl.java b/temporal-sdk/src/main/java/io/temporal/internal/external/GenericWorkflowClientExternalImpl.java index b95af4a91c..16bd922a2b 100644 --- a/temporal-sdk/src/main/java/io/temporal/internal/external/GenericWorkflowClientExternalImpl.java +++ b/temporal-sdk/src/main/java/io/temporal/internal/external/GenericWorkflowClientExternalImpl.java @@ -36,7 +36,7 @@ import io.temporal.api.workflowservice.v1.TerminateWorkflowExecutionRequest; import io.temporal.internal.common.GrpcRetryer; import io.temporal.internal.common.SignalWithStartWorkflowExecutionParameters; -import io.temporal.internal.metrics.MetricsTag; +import io.temporal.serviceclient.MetricsTag; import io.temporal.serviceclient.WorkflowServiceStubs; import java.util.Map; import java.util.Optional; diff --git a/temporal-sdk/src/main/java/io/temporal/internal/external/ManualActivityCompletionClientFactoryImpl.java b/temporal-sdk/src/main/java/io/temporal/internal/external/ManualActivityCompletionClientFactoryImpl.java index 3d0dfaf4ed..f6f36c7103 100644 --- a/temporal-sdk/src/main/java/io/temporal/internal/external/ManualActivityCompletionClientFactoryImpl.java +++ b/temporal-sdk/src/main/java/io/temporal/internal/external/ManualActivityCompletionClientFactoryImpl.java @@ -23,7 +23,7 @@ import com.uber.m3.util.ImmutableMap; import io.temporal.api.common.v1.WorkflowExecution; import io.temporal.common.converter.DataConverter; -import io.temporal.internal.metrics.MetricsTag; +import io.temporal.serviceclient.MetricsTag; import io.temporal.serviceclient.WorkflowServiceStubs; import java.util.Map; import java.util.Objects; diff --git a/temporal-sdk/src/main/java/io/temporal/internal/metrics/MetricsTag.java b/temporal-sdk/src/main/java/io/temporal/internal/metrics/MetricsTag.java deleted file mode 100644 index 18c089bdc2..0000000000 --- a/temporal-sdk/src/main/java/io/temporal/internal/metrics/MetricsTag.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2020 Temporal Technologies, Inc. All Rights Reserved. - * - * 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 io.temporal.internal.metrics; - -public class MetricsTag { - public static final String ACTIVITY_TYPE = "ActivityType"; - public static final String NAMESPACE = "Namespace"; - public static final String TASK_QUEUE = "TaskQueue"; - public static final String WORKFLOW_TYPE = "WorkflowType"; - public static final String SIGNAL_NAME = "SignalName"; - public static final String QUERY_TYPE = "QueryType"; - public static final String STATUS_CODE = "StatusCode"; - public static final String EXCEPTION = "Exception"; - public static final String OPERATION_NAME = "Operation"; -} diff --git a/temporal-sdk/src/main/java/io/temporal/internal/replay/ReplayWorkflowTaskHandler.java b/temporal-sdk/src/main/java/io/temporal/internal/replay/ReplayWorkflowTaskHandler.java index 256923d28e..b847f989d5 100644 --- a/temporal-sdk/src/main/java/io/temporal/internal/replay/ReplayWorkflowTaskHandler.java +++ b/temporal-sdk/src/main/java/io/temporal/internal/replay/ReplayWorkflowTaskHandler.java @@ -44,12 +44,12 @@ import io.temporal.failure.FailureConverter; import io.temporal.internal.common.ProtobufTimeUtils; import io.temporal.internal.common.WorkflowExecutionUtils; -import io.temporal.internal.metrics.MetricsTag; import io.temporal.internal.metrics.MetricsType; import io.temporal.internal.worker.LocalActivityWorker; import io.temporal.internal.worker.SingleWorkerOptions; import io.temporal.internal.worker.WorkflowExecutionException; import io.temporal.internal.worker.WorkflowTaskHandler; +import io.temporal.serviceclient.MetricsTag; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.workflow.Functions; import java.io.PrintWriter; diff --git a/temporal-sdk/src/main/java/io/temporal/internal/sync/POJOActivityTaskHandler.java b/temporal-sdk/src/main/java/io/temporal/internal/sync/POJOActivityTaskHandler.java index d06b314f9f..f0489a897e 100644 --- a/temporal-sdk/src/main/java/io/temporal/internal/sync/POJOActivityTaskHandler.java +++ b/temporal-sdk/src/main/java/io/temporal/internal/sync/POJOActivityTaskHandler.java @@ -39,10 +39,10 @@ import io.temporal.failure.TemporalFailure; import io.temporal.failure.TimeoutFailure; import io.temporal.internal.common.CheckedExceptionWrapper; -import io.temporal.internal.metrics.MetricsTag; import io.temporal.internal.metrics.MetricsType; import io.temporal.internal.replay.FailureWrapperException; import io.temporal.internal.worker.ActivityTaskHandler; +import io.temporal.serviceclient.MetricsTag; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.testing.SimulatedTimeoutFailure; import java.lang.reflect.InvocationTargetException; diff --git a/temporal-sdk/src/main/java/io/temporal/internal/sync/WorkflowClientInternal.java b/temporal-sdk/src/main/java/io/temporal/internal/sync/WorkflowClientInternal.java index d60da5c80e..576a313e59 100644 --- a/temporal-sdk/src/main/java/io/temporal/internal/sync/WorkflowClientInternal.java +++ b/temporal-sdk/src/main/java/io/temporal/internal/sync/WorkflowClientInternal.java @@ -19,12 +19,9 @@ package io.temporal.internal.sync; -import static io.temporal.internal.metrics.MetricsTag.NAMESPACE; - import com.google.common.base.Strings; import com.google.common.reflect.TypeToken; import com.uber.m3.tally.Scope; -import com.uber.m3.util.ImmutableMap; import io.temporal.api.common.v1.WorkflowExecution; import io.temporal.client.ActivityCompletionClient; import io.temporal.client.BatchRequest; @@ -38,6 +35,7 @@ import io.temporal.internal.external.ManualActivityCompletionClientFactory; import io.temporal.internal.external.ManualActivityCompletionClientFactoryImpl; import io.temporal.internal.sync.WorkflowInvocationHandler.InvocationType; +import io.temporal.serviceclient.MetricsTag; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.workflow.Functions; import io.temporal.workflow.QueryMethod; @@ -83,7 +81,7 @@ private WorkflowClientInternal( workflowServiceStubs .getOptions() .getMetricsScope() - .tagged(new ImmutableMap.Builder(1).put(NAMESPACE, namespace).build()); + .tagged(MetricsTag.defaultTags(namespace)); this.genericClient = new GenericWorkflowClientExternalImpl( workflowServiceStubs, options.getNamespace(), options.getIdentity(), metricsScope); diff --git a/temporal-sdk/src/main/java/io/temporal/internal/worker/ActivityWorker.java b/temporal-sdk/src/main/java/io/temporal/internal/worker/ActivityWorker.java index 10a90d835a..c821e4ab61 100644 --- a/temporal-sdk/src/main/java/io/temporal/internal/worker/ActivityWorker.java +++ b/temporal-sdk/src/main/java/io/temporal/internal/worker/ActivityWorker.java @@ -38,10 +38,10 @@ import io.temporal.internal.common.ProtobufTimeUtils; import io.temporal.internal.common.RpcRetryOptions; import io.temporal.internal.logging.LoggerTag; -import io.temporal.internal.metrics.MetricsTag; import io.temporal.internal.metrics.MetricsType; import io.temporal.internal.replay.FailureWrapperException; import io.temporal.internal.worker.ActivityTaskHandler.Result; +import io.temporal.serviceclient.MetricsTag; import io.temporal.serviceclient.WorkflowServiceStubs; import java.util.HashMap; import java.util.Map; diff --git a/temporal-sdk/src/main/java/io/temporal/internal/worker/LocalActivityWorker.java b/temporal-sdk/src/main/java/io/temporal/internal/worker/LocalActivityWorker.java index 70db003ec2..6f4535ab4a 100644 --- a/temporal-sdk/src/main/java/io/temporal/internal/worker/LocalActivityWorker.java +++ b/temporal-sdk/src/main/java/io/temporal/internal/worker/LocalActivityWorker.java @@ -27,9 +27,9 @@ import io.temporal.api.workflowservice.v1.PollActivityTaskQueueResponse; import io.temporal.common.RetryOptions; import io.temporal.internal.common.ProtobufTimeUtils; -import io.temporal.internal.metrics.MetricsTag; import io.temporal.internal.metrics.MetricsType; import io.temporal.internal.replay.ExecuteLocalActivityParameters; +import io.temporal.serviceclient.MetricsTag; import io.temporal.workflow.Functions; import java.time.Duration; import java.util.Map; diff --git a/temporal-sdk/src/main/java/io/temporal/internal/worker/WorkflowWorker.java b/temporal-sdk/src/main/java/io/temporal/internal/worker/WorkflowWorker.java index 32d9ad33dd..29d973e021 100644 --- a/temporal-sdk/src/main/java/io/temporal/internal/worker/WorkflowWorker.java +++ b/temporal-sdk/src/main/java/io/temporal/internal/worker/WorkflowWorker.java @@ -45,8 +45,8 @@ import io.temporal.internal.common.WorkflowExecutionHistory; import io.temporal.internal.common.WorkflowExecutionUtils; import io.temporal.internal.logging.LoggerTag; -import io.temporal.internal.metrics.MetricsTag; import io.temporal.internal.metrics.MetricsType; +import io.temporal.serviceclient.MetricsTag; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.workflow.Functions; import java.util.List; diff --git a/temporal-sdk/src/main/java/io/temporal/worker/Worker.java b/temporal-sdk/src/main/java/io/temporal/worker/Worker.java index d0eb5f3c47..c0568f9920 100644 --- a/temporal-sdk/src/main/java/io/temporal/worker/Worker.java +++ b/temporal-sdk/src/main/java/io/temporal/worker/Worker.java @@ -30,7 +30,6 @@ import io.temporal.common.converter.DataConverter; import io.temporal.internal.common.InternalUtils; import io.temporal.internal.common.WorkflowExecutionHistory; -import io.temporal.internal.metrics.MetricsTag; import io.temporal.internal.replay.WorkflowExecutorCache; import io.temporal.internal.sync.SyncActivityWorker; import io.temporal.internal.sync.SyncWorkflowWorker; @@ -38,6 +37,7 @@ import io.temporal.internal.worker.PollerOptions; import io.temporal.internal.worker.SingleWorkerOptions; import io.temporal.internal.worker.Suspendable; +import io.temporal.serviceclient.MetricsTag; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.workflow.Functions.Func; import io.temporal.workflow.WorkflowMethod; diff --git a/temporal-sdk/src/main/java/io/temporal/worker/WorkerFactory.java b/temporal-sdk/src/main/java/io/temporal/worker/WorkerFactory.java index 3a1d8765a5..dd2635316e 100644 --- a/temporal-sdk/src/main/java/io/temporal/worker/WorkerFactory.java +++ b/temporal-sdk/src/main/java/io/temporal/worker/WorkerFactory.java @@ -28,12 +28,12 @@ import io.temporal.client.WorkflowClient; import io.temporal.common.converter.DataConverter; import io.temporal.internal.common.InternalUtils; -import io.temporal.internal.metrics.MetricsTag; import io.temporal.internal.replay.WorkflowExecutorCache; import io.temporal.internal.worker.PollWorkflowTaskDispatcher; import io.temporal.internal.worker.Poller; import io.temporal.internal.worker.PollerOptions; import io.temporal.internal.worker.WorkflowPollTaskFactory; +import io.temporal.serviceclient.MetricsTag; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -106,10 +106,7 @@ private WorkerFactory(WorkflowClient workflowClient, WorkerFactoryOptions factor .getWorkflowServiceStubs() .getOptions() .getMetricsScope() - .tagged( - new ImmutableMap.Builder(1) - .put(MetricsTag.NAMESPACE, workflowClient.getOptions().getNamespace()) - .build()); + .tagged(MetricsTag.defaultTags(workflowClient.getOptions().getNamespace())); this.cache = new WorkflowExecutorCache( diff --git a/temporal-sdk/src/test/java/io/temporal/internal/replay/ReplayWorkflowRunTaskHandlerCacheTests.java b/temporal-sdk/src/test/java/io/temporal/internal/replay/ReplayWorkflowRunTaskHandlerCacheTests.java index f0e98eb24a..ff3c305a00 100644 --- a/temporal-sdk/src/test/java/io/temporal/internal/replay/ReplayWorkflowRunTaskHandlerCacheTests.java +++ b/temporal-sdk/src/test/java/io/temporal/internal/replay/ReplayWorkflowRunTaskHandlerCacheTests.java @@ -38,11 +38,11 @@ import io.temporal.api.query.v1.WorkflowQuery; import io.temporal.api.workflowservice.v1.PollWorkflowTaskQueueResponse; import io.temporal.common.reporter.TestStatsReporter; -import io.temporal.internal.metrics.MetricsTag; import io.temporal.internal.metrics.MetricsType; import io.temporal.internal.testservice.TestWorkflowService; import io.temporal.internal.worker.SingleWorkerOptions; import io.temporal.internal.worker.WorkflowExecutionException; +import io.temporal.serviceclient.MetricsTag; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.testUtils.HistoryUtils; import io.temporal.worker.WorkflowImplementationOptions; diff --git a/temporal-sdk/src/test/java/io/temporal/internal/sync/DeterministicRunnerTest.java b/temporal-sdk/src/test/java/io/temporal/internal/sync/DeterministicRunnerTest.java index 73d7630d19..b64db22c20 100644 --- a/temporal-sdk/src/test/java/io/temporal/internal/sync/DeterministicRunnerTest.java +++ b/temporal-sdk/src/test/java/io/temporal/internal/sync/DeterministicRunnerTest.java @@ -37,12 +37,12 @@ import io.temporal.common.RetryOptions; import io.temporal.common.converter.DataConverter; import io.temporal.failure.CanceledFailure; -import io.temporal.internal.metrics.MetricsTag; import io.temporal.internal.metrics.MetricsType; import io.temporal.internal.replay.ReplayWorkflowContext; import io.temporal.internal.replay.WorkflowExecutorCache; import io.temporal.internal.replay.WorkflowRunTaskHandler; import io.temporal.internal.replay.WorkflowTaskResult; +import io.temporal.serviceclient.MetricsTag; import io.temporal.testUtils.HistoryUtils; import io.temporal.workflow.Async; import io.temporal.workflow.CancellationScope; diff --git a/temporal-sdk/src/test/java/io/temporal/worker/StickyWorkerTest.java b/temporal-sdk/src/test/java/io/temporal/worker/StickyWorkerTest.java index 871b335a1e..f8baea71e8 100644 --- a/temporal-sdk/src/test/java/io/temporal/worker/StickyWorkerTest.java +++ b/temporal-sdk/src/test/java/io/temporal/worker/StickyWorkerTest.java @@ -33,9 +33,9 @@ import io.temporal.client.WorkflowClientOptions; import io.temporal.client.WorkflowOptions; import io.temporal.common.reporter.TestStatsReporter; -import io.temporal.internal.metrics.MetricsTag; import io.temporal.internal.metrics.MetricsType; import io.temporal.internal.replay.WorkflowExecutorCache; +import io.temporal.serviceclient.MetricsTag; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.serviceclient.WorkflowServiceStubsOptions; import io.temporal.testing.TestEnvironmentOptions; @@ -158,8 +158,8 @@ public void whenStickyIsEnabledThenTheWorkflowIsCachedSignals() throws Exception // Verify the workflow succeeded without having to recover from a failure Map tags = - new ImmutableMap.Builder(2) - .put(MetricsTag.NAMESPACE, NAMESPACE) + new ImmutableMap.Builder(9) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, taskQueueName) .put(MetricsTag.WORKFLOW_TYPE, "GreetingSignalWorkflow") .build(); @@ -258,8 +258,8 @@ public void whenStickyIsEnabledThenTheWorkflowIsCachedActivities() throws Except // Verify the workflow succeeded without having to recover from a failure Map tags = - new ImmutableMap.Builder(2) - .put(MetricsTag.NAMESPACE, NAMESPACE) + new ImmutableMap.Builder(9) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, taskQueueName) .put(MetricsTag.WORKFLOW_TYPE, "ActivitiesWorkflow") .build(); @@ -299,8 +299,8 @@ public void whenStickyIsEnabledThenTheWorkflowIsCachedChildWorkflows() throws Ex // Verify the workflow succeeded without having to recover from a failure Map tags = - new ImmutableMap.Builder(2) - .put(MetricsTag.NAMESPACE, NAMESPACE) + new ImmutableMap.Builder(9) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, taskQueueName) .put(MetricsTag.WORKFLOW_TYPE, "GreetingParentWorkflow") .build(); @@ -348,8 +348,8 @@ public void whenStickyIsEnabledThenTheWorkflowIsCachedMutableSideEffect() throws // Verify the workflow succeeded without having to recover from a failure Map tags = - new ImmutableMap.Builder(2) - .put(MetricsTag.NAMESPACE, NAMESPACE) + new ImmutableMap.Builder(9) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, taskQueueName) .put(MetricsTag.WORKFLOW_TYPE, "TestMutableSideEffectWorkflow") .build(); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/MetricsTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/MetricsTest.java index 087e53b54a..1a47e181ad 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/MetricsTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/MetricsTest.java @@ -24,6 +24,7 @@ import static io.temporal.serviceclient.MetricsType.TEMPORAL_REQUEST; import static io.temporal.serviceclient.MetricsType.TEMPORAL_REQUEST_FAILURE; import static io.temporal.serviceclient.MetricsType.TEMPORAL_REQUEST_LATENCY; +import static io.temporal.workflow.WorkflowTest.NAMESPACE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -46,7 +47,7 @@ import io.temporal.common.interceptors.WorkflowInterceptor; import io.temporal.common.interceptors.WorkflowOutboundCallsInterceptor; import io.temporal.common.reporter.TestStatsReporter; -import io.temporal.internal.metrics.MetricsTag; +import io.temporal.serviceclient.MetricsTag; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.testing.TestEnvironmentOptions; import io.temporal.testing.TestWorkflowEnvironment; @@ -122,10 +123,12 @@ public void execute() { @ActivityInterface public interface TestActivity { + int runActivity(int input); } static class TestActivityImpl implements TestActivity { + @Override public int runActivity(int input) { return input; @@ -168,6 +171,7 @@ public interface ReceiveSignalObjectChildWorkflow { public static class ReceiveSignalObjectChildWorkflowImpl implements ReceiveSignalObjectChildWorkflow { + private String receivedSignal = "Initial State"; // Keep workflow open so that we can send signal CompletablePromise promise = Workflow.newPromise(); @@ -197,6 +201,7 @@ public interface SendSignalObjectWorkflow { } public static class SendSignalObjectWorkflowImpl implements SendSignalObjectWorkflow { + @Override public String execute() { ReceiveSignalObjectChildWorkflow child = @@ -260,8 +265,8 @@ public void testWorkflowMetrics() throws InterruptedException { Thread.sleep(REPORTING_FLUSH_TIME); ImmutableMap.Builder tagsB = - new ImmutableMap.Builder(2) - .put(MetricsTag.NAMESPACE, WorkflowTest.NAMESPACE) + new ImmutableMap.Builder(9) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, TASK_QUEUE); reporter.assertCounter("temporal_worker_start", tagsB.build(), 3); reporter.assertCounter("temporal_poller_start", tagsB.build()); @@ -273,15 +278,15 @@ public void testWorkflowMetrics() throws InterruptedException { tagsB.put(MetricsTag.OPERATION_NAME, "PollWorkflowTaskQueue").build()); ImmutableMap tags = - new ImmutableMap.Builder(2) - .put(MetricsTag.NAMESPACE, WorkflowTest.NAMESPACE) + new ImmutableMap.Builder(9) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, "sticky") .build(); reporter.assertCounter("temporal_poller_start", tags); tags = - new ImmutableMap.Builder(2) - .put(MetricsTag.NAMESPACE, WorkflowTest.NAMESPACE) + new ImmutableMap.Builder(9) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.WORKFLOW_TYPE, "TestWorkflow") .put(MetricsTag.TASK_QUEUE, TASK_QUEUE) .build(); @@ -289,8 +294,8 @@ public void testWorkflowMetrics() throws InterruptedException { reporter.assertCounter("test_started", tags, 1); reporter.assertCounter("test_done", tags, 1); tags = - new ImmutableMap.Builder(2) - .put(MetricsTag.NAMESPACE, WorkflowTest.NAMESPACE) + new ImmutableMap.Builder(9) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.WORKFLOW_TYPE, "TestChildWorkflow") .put(MetricsTag.TASK_QUEUE, TASK_QUEUE) .build(); @@ -300,8 +305,8 @@ public void testWorkflowMetrics() throws InterruptedException { reporter.assertTimerMinDuration("test_timer", tags, Duration.ofSeconds(3)); Map activityCompletionTags = - new ImmutableMap.Builder(5) - .put(MetricsTag.NAMESPACE, WorkflowTest.NAMESPACE) + new ImmutableMap.Builder(9) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, TASK_QUEUE) .put(MetricsTag.ACTIVITY_TYPE, "RunActivity") .put(MetricsTag.WORKFLOW_TYPE, "TestWorkflow") @@ -310,8 +315,8 @@ public void testWorkflowMetrics() throws InterruptedException { reporter.assertCounter(TEMPORAL_REQUEST, activityCompletionTags, 1); tagsB = - new ImmutableMap.Builder(3) - .put(MetricsTag.NAMESPACE, WorkflowTest.NAMESPACE) + new ImmutableMap.Builder(9) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, TASK_QUEUE); tags = @@ -323,8 +328,8 @@ public void testWorkflowMetrics() throws InterruptedException { reporter.assertTimer(TEMPORAL_REQUEST_LATENCY, tags); Map workflowTaskCompletionTags = - new ImmutableMap.Builder(4) - .put(MetricsTag.NAMESPACE, WorkflowTest.NAMESPACE) + new ImmutableMap.Builder(9) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, TASK_QUEUE) .put(MetricsTag.WORKFLOW_TYPE, "TestWorkflow") .put(MetricsTag.OPERATION_NAME, "RespondWorkflowTaskCompleted") @@ -363,8 +368,8 @@ public void testCorruptedSignalMetrics() throws InterruptedException { Thread.sleep(REPORTING_FLUSH_TIME); Map tags = - new ImmutableMap.Builder(2) - .put(MetricsTag.NAMESPACE, WorkflowTest.NAMESPACE) + new ImmutableMap.Builder(9) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, TASK_QUEUE) .put(MetricsTag.WORKFLOW_TYPE, "ReceiveSignalObjectChildWorkflow") .build(); @@ -414,12 +419,14 @@ public void testTemporalFailureMetric() throws InterruptedException { Thread.sleep(REPORTING_FLUSH_TIME); Map tags = - new ImmutableMap.Builder(2) + new ImmutableMap.Builder(9) + .putAll(MetricsTag.defaultTags(MetricsTag.DEFAULT_VALUE)) .put(MetricsTag.OPERATION_NAME, "DescribeNamespace") .build(); reporter.assertCounter(TEMPORAL_REQUEST, tags, 1); tags = - new ImmutableMap.Builder(2) + new ImmutableMap.Builder(9) + .putAll(MetricsTag.defaultTags(MetricsTag.DEFAULT_VALUE)) .put(MetricsTag.OPERATION_NAME, "DescribeNamespace") .put(MetricsTag.STATUS_CODE, "UNIMPLEMENTED") .build(); @@ -449,13 +456,15 @@ public void testTemporalInvalidRequestMetric() throws InterruptedException { Thread.sleep(REPORTING_FLUSH_TIME); Map tags = - new ImmutableMap.Builder(2) + new ImmutableMap.Builder(9) + .putAll(MetricsTag.defaultTags(MetricsTag.DEFAULT_VALUE)) .put(MetricsTag.OPERATION_NAME, "StartWorkflowExecution") .build(); reporter.assertCounter(TEMPORAL_REQUEST, tags, 1); tags = - new ImmutableMap.Builder(2) + new ImmutableMap.Builder(9) + .putAll(MetricsTag.defaultTags(MetricsTag.DEFAULT_VALUE)) .put(MetricsTag.OPERATION_NAME, "StartWorkflowExecution") .put(MetricsTag.STATUS_CODE, "INVALID_ARGUMENT") .build(); diff --git a/temporal-serviceclient/src/main/java/io/temporal/serviceclient/GrpcMetricsInterceptor.java b/temporal-serviceclient/src/main/java/io/temporal/serviceclient/GrpcMetricsInterceptor.java index 9c2e339b62..af7d1c258f 100644 --- a/temporal-serviceclient/src/main/java/io/temporal/serviceclient/GrpcMetricsInterceptor.java +++ b/temporal-serviceclient/src/main/java/io/temporal/serviceclient/GrpcMetricsInterceptor.java @@ -47,7 +47,7 @@ class GrpcMetricsInterceptor implements ClientInterceptor { private final Map, Map> methodTags = new HashMap<>(); GrpcMetricsInterceptor(Scope scope) { - this.defaultScope = scope; + this.defaultScope = scope.tagged(MetricsTag.defaultTags(MetricsTag.DEFAULT_VALUE)); ServiceDescriptor descriptor = WorkflowServiceGrpc.getServiceDescriptor(); String serviceName = descriptor.getName(); Collection> methods = descriptor.getMethods(); diff --git a/temporal-serviceclient/src/main/java/io/temporal/serviceclient/MetricsTag.java b/temporal-serviceclient/src/main/java/io/temporal/serviceclient/MetricsTag.java index 1d3d4b45e2..cb9edf06dc 100644 --- a/temporal-serviceclient/src/main/java/io/temporal/serviceclient/MetricsTag.java +++ b/temporal-serviceclient/src/main/java/io/temporal/serviceclient/MetricsTag.java @@ -20,14 +20,21 @@ package io.temporal.serviceclient; import com.uber.m3.tally.Scope; +import com.uber.m3.util.ImmutableMap; import io.grpc.CallOptions; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; public class MetricsTag { + public static final String ACTIVITY_TYPE = "ActivityType"; public static final String NAMESPACE = "Namespace"; public static final String TASK_QUEUE = "TaskQueue"; public static final String WORKFLOW_TYPE = "WorkflowType"; + public static final String SIGNAL_NAME = "SignalName"; public static final String QUERY_TYPE = "QueryType"; public static final String STATUS_CODE = "StatusCode"; + public static final String EXCEPTION = "Exception"; public static final String OPERATION_NAME = "Operation"; /** Used to pass metrics scope to the interceptor */ @@ -37,4 +44,28 @@ public class MetricsTag { /** Indicates to interceptors that GetWorkflowExecutionHistory is a long poll. */ public static final CallOptions.Key HISTORY_LONG_POLL_CALL_OPTIONS_KEY = CallOptions.Key.create("history-long-poll"); + + public static final String DEFAULT_VALUE = "none"; + + private static final ConcurrentMap> tagsByNamespace = + new ConcurrentHashMap<>(); + + /** Returns a set of default metric tags for a given namespace. */ + public static Map defaultTags(String namespace) { + return tagsByNamespace.computeIfAbsent(namespace, MetricsTag::tags); + } + + private static Map tags(String namespace) { + return new ImmutableMap.Builder(9) + .put(NAMESPACE, namespace) + .put(ACTIVITY_TYPE, DEFAULT_VALUE) + .put(OPERATION_NAME, DEFAULT_VALUE) + .put(SIGNAL_NAME, DEFAULT_VALUE) + .put(QUERY_TYPE, DEFAULT_VALUE) + .put(TASK_QUEUE, DEFAULT_VALUE) + .put(STATUS_CODE, DEFAULT_VALUE) + .put(EXCEPTION, DEFAULT_VALUE) + .put(WORKFLOW_TYPE, DEFAULT_VALUE) + .build(); + } }