From de11ebb2b82d9234cb832c445d31a6c40de93876 Mon Sep 17 00:00:00 2001 From: Vitaly Date: Wed, 21 Oct 2020 15:08:17 -0700 Subject: [PATCH 1/4] Add default metric tags to the metric scope --- .../internal/metrics/DefaultMetricsTags.java | 44 +++++++++++++++++++ .../internal/sync/WorkflowClientInternal.java | 8 +--- .../io/temporal/worker/WorkerFactory.java | 7 ++- .../io/temporal/worker/StickyWorkerTest.java | 17 +++---- .../io/temporal/workflow/MetricsTest.java | 38 +++++++++------- 5 files changed, 80 insertions(+), 34 deletions(-) create mode 100644 temporal-sdk/src/main/java/io/temporal/internal/metrics/DefaultMetricsTags.java diff --git a/temporal-sdk/src/main/java/io/temporal/internal/metrics/DefaultMetricsTags.java b/temporal-sdk/src/main/java/io/temporal/internal/metrics/DefaultMetricsTags.java new file mode 100644 index 0000000000..5c794f1d82 --- /dev/null +++ b/temporal-sdk/src/main/java/io/temporal/internal/metrics/DefaultMetricsTags.java @@ -0,0 +1,44 @@ +/* + * 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; + +import static io.temporal.internal.metrics.MetricsTag.NAMESPACE; + +import com.uber.m3.util.ImmutableMap; +import java.util.Map; + +public class DefaultMetricsTags { + + public static final String DEFAULT_VALUE = "none"; + + public static Map defaultTags(String namespace) { + return new ImmutableMap.Builder(9) + .put(NAMESPACE, namespace) + .put(MetricsTag.ACTIVITY_TYPE, DEFAULT_VALUE) + .put(MetricsTag.OPERATION_NAME, DEFAULT_VALUE) + .put(MetricsTag.SIGNAL_NAME, DEFAULT_VALUE) + .put(MetricsTag.QUERY_TYPE, DEFAULT_VALUE) + .put(MetricsTag.TASK_QUEUE, DEFAULT_VALUE) + .put(MetricsTag.STATUS_CODE, DEFAULT_VALUE) + .put(MetricsTag.EXCEPTION, DEFAULT_VALUE) + .put(MetricsTag.WORKFLOW_TYPE, DEFAULT_VALUE) + .build(); + } +} 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..08d58a267c 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,11 @@ package io.temporal.internal.sync; -import static io.temporal.internal.metrics.MetricsTag.NAMESPACE; +import static io.temporal.internal.metrics.DefaultMetricsTags.defaultTags; 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; @@ -80,10 +79,7 @@ private WorkflowClientInternal( // For metrics only String namespace = options.getNamespace() == null ? "default" : options.getNamespace(); metricsScope = - workflowServiceStubs - .getOptions() - .getMetricsScope() - .tagged(new ImmutableMap.Builder(1).put(NAMESPACE, namespace).build()); + workflowServiceStubs.getOptions().getMetricsScope().tagged(defaultTags(namespace)); this.genericClient = new GenericWorkflowClientExternalImpl( workflowServiceStubs, options.getNamespace(), options.getIdentity(), metricsScope); 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..3160ba7fbb 100644 --- a/temporal-sdk/src/main/java/io/temporal/worker/WorkerFactory.java +++ b/temporal-sdk/src/main/java/io/temporal/worker/WorkerFactory.java @@ -19,6 +19,8 @@ package io.temporal.worker; +import static io.temporal.internal.metrics.DefaultMetricsTags.defaultTags; + import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -106,10 +108,7 @@ private WorkerFactory(WorkflowClient workflowClient, WorkerFactoryOptions factor .getWorkflowServiceStubs() .getOptions() .getMetricsScope() - .tagged( - new ImmutableMap.Builder(1) - .put(MetricsTag.NAMESPACE, workflowClient.getOptions().getNamespace()) - .build()); + .tagged(defaultTags(workflowClient.getOptions().getNamespace())); this.cache = new WorkflowExecutorCache( 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..7b250950d9 100644 --- a/temporal-sdk/src/test/java/io/temporal/worker/StickyWorkerTest.java +++ b/temporal-sdk/src/test/java/io/temporal/worker/StickyWorkerTest.java @@ -33,6 +33,7 @@ import io.temporal.client.WorkflowClientOptions; import io.temporal.client.WorkflowOptions; import io.temporal.common.reporter.TestStatsReporter; +import io.temporal.internal.metrics.DefaultMetricsTags; import io.temporal.internal.metrics.MetricsTag; import io.temporal.internal.metrics.MetricsType; import io.temporal.internal.replay.WorkflowExecutorCache; @@ -158,8 +159,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(DefaultMetricsTags.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, taskQueueName) .put(MetricsTag.WORKFLOW_TYPE, "GreetingSignalWorkflow") .build(); @@ -258,8 +259,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(DefaultMetricsTags.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, taskQueueName) .put(MetricsTag.WORKFLOW_TYPE, "ActivitiesWorkflow") .build(); @@ -299,8 +300,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(DefaultMetricsTags.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, taskQueueName) .put(MetricsTag.WORKFLOW_TYPE, "GreetingParentWorkflow") .build(); @@ -348,8 +349,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(DefaultMetricsTags.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..25d06f1279 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,6 +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.DefaultMetricsTags; import io.temporal.internal.metrics.MetricsTag; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.testing.TestEnvironmentOptions; @@ -122,10 +124,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 +172,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 +202,7 @@ public interface SendSignalObjectWorkflow { } public static class SendSignalObjectWorkflowImpl implements SendSignalObjectWorkflow { + @Override public String execute() { ReceiveSignalObjectChildWorkflow child = @@ -260,8 +266,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(DefaultMetricsTags.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 +279,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(DefaultMetricsTags.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(DefaultMetricsTags.defaultTags(NAMESPACE)) .put(MetricsTag.WORKFLOW_TYPE, "TestWorkflow") .put(MetricsTag.TASK_QUEUE, TASK_QUEUE) .build(); @@ -289,8 +295,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(DefaultMetricsTags.defaultTags(NAMESPACE)) .put(MetricsTag.WORKFLOW_TYPE, "TestChildWorkflow") .put(MetricsTag.TASK_QUEUE, TASK_QUEUE) .build(); @@ -300,8 +306,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(DefaultMetricsTags.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, TASK_QUEUE) .put(MetricsTag.ACTIVITY_TYPE, "RunActivity") .put(MetricsTag.WORKFLOW_TYPE, "TestWorkflow") @@ -310,8 +316,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(DefaultMetricsTags.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, TASK_QUEUE); tags = @@ -323,8 +329,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(DefaultMetricsTags.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, TASK_QUEUE) .put(MetricsTag.WORKFLOW_TYPE, "TestWorkflow") .put(MetricsTag.OPERATION_NAME, "RespondWorkflowTaskCompleted") @@ -363,8 +369,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(DefaultMetricsTags.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, TASK_QUEUE) .put(MetricsTag.WORKFLOW_TYPE, "ReceiveSignalObjectChildWorkflow") .build(); From 527da8bc423af44ba13bfca5b4701f0785ffdc4b Mon Sep 17 00:00:00 2001 From: Vitaly Date: Wed, 21 Oct 2020 20:46:43 -0700 Subject: [PATCH 2/4] Add default tags in the Grpc interceptor --- .../GenericWorkflowClientExternalImpl.java | 2 +- ...alActivityCompletionClientFactoryImpl.java | 2 +- .../internal/metrics/DefaultMetricsTags.java | 44 ------------------- .../temporal/internal/metrics/MetricsTag.java | 32 -------------- .../replay/ReplayWorkflowTaskHandler.java | 2 +- .../sync/POJOActivityTaskHandler.java | 2 +- .../internal/sync/WorkflowClientInternal.java | 8 ++-- .../internal/worker/ActivityWorker.java | 2 +- .../internal/worker/LocalActivityWorker.java | 2 +- .../internal/worker/WorkflowWorker.java | 2 +- .../main/java/io/temporal/worker/Worker.java | 2 +- .../io/temporal/worker/WorkerFactory.java | 6 +-- ...eplayWorkflowRunTaskHandlerCacheTests.java | 2 +- .../sync/DeterministicRunnerTest.java | 2 +- .../io/temporal/worker/StickyWorkerTest.java | 11 +++-- .../io/temporal/workflow/MetricsTest.java | 31 +++++++------ .../serviceclient/GrpcMetricsInterceptor.java | 2 +- .../io/temporal/serviceclient/MetricsTag.java | 21 +++++++++ 18 files changed, 61 insertions(+), 114 deletions(-) delete mode 100644 temporal-sdk/src/main/java/io/temporal/internal/metrics/DefaultMetricsTags.java delete mode 100644 temporal-sdk/src/main/java/io/temporal/internal/metrics/MetricsTag.java 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/DefaultMetricsTags.java b/temporal-sdk/src/main/java/io/temporal/internal/metrics/DefaultMetricsTags.java deleted file mode 100644 index 5c794f1d82..0000000000 --- a/temporal-sdk/src/main/java/io/temporal/internal/metrics/DefaultMetricsTags.java +++ /dev/null @@ -1,44 +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; - -import static io.temporal.internal.metrics.MetricsTag.NAMESPACE; - -import com.uber.m3.util.ImmutableMap; -import java.util.Map; - -public class DefaultMetricsTags { - - public static final String DEFAULT_VALUE = "none"; - - public static Map defaultTags(String namespace) { - return new ImmutableMap.Builder(9) - .put(NAMESPACE, namespace) - .put(MetricsTag.ACTIVITY_TYPE, DEFAULT_VALUE) - .put(MetricsTag.OPERATION_NAME, DEFAULT_VALUE) - .put(MetricsTag.SIGNAL_NAME, DEFAULT_VALUE) - .put(MetricsTag.QUERY_TYPE, DEFAULT_VALUE) - .put(MetricsTag.TASK_QUEUE, DEFAULT_VALUE) - .put(MetricsTag.STATUS_CODE, DEFAULT_VALUE) - .put(MetricsTag.EXCEPTION, DEFAULT_VALUE) - .put(MetricsTag.WORKFLOW_TYPE, DEFAULT_VALUE) - .build(); - } -} 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 08d58a267c..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,8 +19,6 @@ package io.temporal.internal.sync; -import static io.temporal.internal.metrics.DefaultMetricsTags.defaultTags; - import com.google.common.base.Strings; import com.google.common.reflect.TypeToken; import com.uber.m3.tally.Scope; @@ -37,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; @@ -79,7 +78,10 @@ private WorkflowClientInternal( // For metrics only String namespace = options.getNamespace() == null ? "default" : options.getNamespace(); metricsScope = - workflowServiceStubs.getOptions().getMetricsScope().tagged(defaultTags(namespace)); + workflowServiceStubs + .getOptions() + .getMetricsScope() + .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 3160ba7fbb..dd2635316e 100644 --- a/temporal-sdk/src/main/java/io/temporal/worker/WorkerFactory.java +++ b/temporal-sdk/src/main/java/io/temporal/worker/WorkerFactory.java @@ -19,8 +19,6 @@ package io.temporal.worker; -import static io.temporal.internal.metrics.DefaultMetricsTags.defaultTags; - import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -30,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; @@ -108,7 +106,7 @@ private WorkerFactory(WorkflowClient workflowClient, WorkerFactoryOptions factor .getWorkflowServiceStubs() .getOptions() .getMetricsScope() - .tagged(defaultTags(workflowClient.getOptions().getNamespace())); + .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 7b250950d9..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,10 +33,9 @@ import io.temporal.client.WorkflowClientOptions; import io.temporal.client.WorkflowOptions; import io.temporal.common.reporter.TestStatsReporter; -import io.temporal.internal.metrics.DefaultMetricsTags; -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; @@ -160,7 +159,7 @@ public void whenStickyIsEnabledThenTheWorkflowIsCachedSignals() throws Exception // Verify the workflow succeeded without having to recover from a failure Map tags = new ImmutableMap.Builder(9) - .putAll(DefaultMetricsTags.defaultTags(NAMESPACE)) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, taskQueueName) .put(MetricsTag.WORKFLOW_TYPE, "GreetingSignalWorkflow") .build(); @@ -260,7 +259,7 @@ public void whenStickyIsEnabledThenTheWorkflowIsCachedActivities() throws Except // Verify the workflow succeeded without having to recover from a failure Map tags = new ImmutableMap.Builder(9) - .putAll(DefaultMetricsTags.defaultTags(NAMESPACE)) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, taskQueueName) .put(MetricsTag.WORKFLOW_TYPE, "ActivitiesWorkflow") .build(); @@ -301,7 +300,7 @@ public void whenStickyIsEnabledThenTheWorkflowIsCachedChildWorkflows() throws Ex // Verify the workflow succeeded without having to recover from a failure Map tags = new ImmutableMap.Builder(9) - .putAll(DefaultMetricsTags.defaultTags(NAMESPACE)) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, taskQueueName) .put(MetricsTag.WORKFLOW_TYPE, "GreetingParentWorkflow") .build(); @@ -350,7 +349,7 @@ public void whenStickyIsEnabledThenTheWorkflowIsCachedMutableSideEffect() throws // Verify the workflow succeeded without having to recover from a failure Map tags = new ImmutableMap.Builder(9) - .putAll(DefaultMetricsTags.defaultTags(NAMESPACE)) + .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 25d06f1279..1a47e181ad 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/MetricsTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/MetricsTest.java @@ -47,8 +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.DefaultMetricsTags; -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; @@ -267,7 +266,7 @@ public void testWorkflowMetrics() throws InterruptedException { ImmutableMap.Builder tagsB = new ImmutableMap.Builder(9) - .putAll(DefaultMetricsTags.defaultTags(NAMESPACE)) + .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()); @@ -280,14 +279,14 @@ public void testWorkflowMetrics() throws InterruptedException { ImmutableMap tags = new ImmutableMap.Builder(9) - .putAll(DefaultMetricsTags.defaultTags(NAMESPACE)) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, "sticky") .build(); reporter.assertCounter("temporal_poller_start", tags); tags = new ImmutableMap.Builder(9) - .putAll(DefaultMetricsTags.defaultTags(NAMESPACE)) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.WORKFLOW_TYPE, "TestWorkflow") .put(MetricsTag.TASK_QUEUE, TASK_QUEUE) .build(); @@ -296,7 +295,7 @@ public void testWorkflowMetrics() throws InterruptedException { reporter.assertCounter("test_done", tags, 1); tags = new ImmutableMap.Builder(9) - .putAll(DefaultMetricsTags.defaultTags(NAMESPACE)) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.WORKFLOW_TYPE, "TestChildWorkflow") .put(MetricsTag.TASK_QUEUE, TASK_QUEUE) .build(); @@ -307,7 +306,7 @@ public void testWorkflowMetrics() throws InterruptedException { Map activityCompletionTags = new ImmutableMap.Builder(9) - .putAll(DefaultMetricsTags.defaultTags(NAMESPACE)) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, TASK_QUEUE) .put(MetricsTag.ACTIVITY_TYPE, "RunActivity") .put(MetricsTag.WORKFLOW_TYPE, "TestWorkflow") @@ -317,7 +316,7 @@ public void testWorkflowMetrics() throws InterruptedException { tagsB = new ImmutableMap.Builder(9) - .putAll(DefaultMetricsTags.defaultTags(NAMESPACE)) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, TASK_QUEUE); tags = @@ -330,7 +329,7 @@ public void testWorkflowMetrics() throws InterruptedException { Map workflowTaskCompletionTags = new ImmutableMap.Builder(9) - .putAll(DefaultMetricsTags.defaultTags(NAMESPACE)) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, TASK_QUEUE) .put(MetricsTag.WORKFLOW_TYPE, "TestWorkflow") .put(MetricsTag.OPERATION_NAME, "RespondWorkflowTaskCompleted") @@ -370,7 +369,7 @@ public void testCorruptedSignalMetrics() throws InterruptedException { Map tags = new ImmutableMap.Builder(9) - .putAll(DefaultMetricsTags.defaultTags(NAMESPACE)) + .putAll(MetricsTag.defaultTags(NAMESPACE)) .put(MetricsTag.TASK_QUEUE, TASK_QUEUE) .put(MetricsTag.WORKFLOW_TYPE, "ReceiveSignalObjectChildWorkflow") .build(); @@ -420,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(); @@ -455,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..a0b860a6c8 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,19 @@ package io.temporal.serviceclient; import com.uber.m3.tally.Scope; +import com.uber.m3.util.ImmutableMap; import io.grpc.CallOptions; +import java.util.Map; 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 +42,20 @@ 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"; + + public static Map defaultTags(String namespace) { + return new ImmutableMap.Builder(9) + .put(NAMESPACE, namespace) + .put(MetricsTag.ACTIVITY_TYPE, DEFAULT_VALUE) + .put(MetricsTag.OPERATION_NAME, DEFAULT_VALUE) + .put(MetricsTag.SIGNAL_NAME, DEFAULT_VALUE) + .put(MetricsTag.QUERY_TYPE, DEFAULT_VALUE) + .put(MetricsTag.TASK_QUEUE, DEFAULT_VALUE) + .put(MetricsTag.STATUS_CODE, DEFAULT_VALUE) + .put(MetricsTag.EXCEPTION, DEFAULT_VALUE) + .put(MetricsTag.WORKFLOW_TYPE, DEFAULT_VALUE) + .build(); + } } From beaac9a6983e5ed785431f469a1127114c785987 Mon Sep 17 00:00:00 2001 From: Vitaly Date: Thu, 22 Oct 2020 16:18:47 -0700 Subject: [PATCH 3/4] Add a cache for metric tags --- .../io/temporal/serviceclient/MetricsTag.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) 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 a0b860a6c8..3b20cd4335 100644 --- a/temporal-serviceclient/src/main/java/io/temporal/serviceclient/MetricsTag.java +++ b/temporal-serviceclient/src/main/java/io/temporal/serviceclient/MetricsTag.java @@ -23,6 +23,8 @@ 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"; @@ -45,17 +47,24 @@ public class MetricsTag { public static final String DEFAULT_VALUE = "none"; + private static final ConcurrentMap> tagsByNamespace = + new ConcurrentHashMap<>(); + 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(MetricsTag.ACTIVITY_TYPE, DEFAULT_VALUE) - .put(MetricsTag.OPERATION_NAME, DEFAULT_VALUE) - .put(MetricsTag.SIGNAL_NAME, DEFAULT_VALUE) - .put(MetricsTag.QUERY_TYPE, DEFAULT_VALUE) - .put(MetricsTag.TASK_QUEUE, DEFAULT_VALUE) - .put(MetricsTag.STATUS_CODE, DEFAULT_VALUE) - .put(MetricsTag.EXCEPTION, DEFAULT_VALUE) - .put(MetricsTag.WORKFLOW_TYPE, DEFAULT_VALUE) + .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(); } } From 04296ba35f71b18ce99c024aed598f497da8650c Mon Sep 17 00:00:00 2001 From: Vitaly Date: Thu, 22 Oct 2020 16:26:21 -0700 Subject: [PATCH 4/4] Add a comment --- .../src/main/java/io/temporal/serviceclient/MetricsTag.java | 1 + 1 file changed, 1 insertion(+) 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 3b20cd4335..cb9edf06dc 100644 --- a/temporal-serviceclient/src/main/java/io/temporal/serviceclient/MetricsTag.java +++ b/temporal-serviceclient/src/main/java/io/temporal/serviceclient/MetricsTag.java @@ -50,6 +50,7 @@ public class MetricsTag { 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); }