diff --git a/CHANGELOG.md b/CHANGELOG.md index 55175feb65..a829fe89e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,8 @@ to docs, or any other relevant information. project-scoped custom roles, and caller rate limits. ### Fixed +- Keep Nexus response request counters and latency metrics compatible with Prometheus by including + `nexus_service` and `nexus_operation` on regular gRPC request metrics, where they default to `none`. - Autoscaling workflow pollers now prioritize meaningful sticky backlog up to the sticky pool's target and use advertised slot capacity to balance sticky and non-sticky admission. Without an advertised maximum, additional polls of one queue type wait until the other has an active poll. diff --git a/temporal-sdk/src/test/java/io/temporal/client/functional/MetricsTest.java b/temporal-sdk/src/test/java/io/temporal/client/functional/MetricsTest.java index 0224e27cc0..9d21d02c8f 100644 --- a/temporal-sdk/src/test/java/io/temporal/client/functional/MetricsTest.java +++ b/temporal-sdk/src/test/java/io/temporal/client/functional/MetricsTest.java @@ -2,9 +2,12 @@ import static io.temporal.testUtils.Eventually.assertEventually; import static junit.framework.TestCase.*; +import static org.junit.Assert.assertThrows; import static org.junit.Assume.assumeTrue; import com.uber.m3.tally.RootScopeBuilder; +import com.uber.m3.tally.Scope; +import io.grpc.StatusRuntimeException; import io.micrometer.core.instrument.*; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; import io.temporal.activity.ActivityInterface; @@ -12,17 +15,22 @@ import io.temporal.activity.LocalActivityOptions; import io.temporal.api.common.v1.WorkflowExecution; import io.temporal.api.enums.v1.WorkflowTaskFailedCause; +import io.temporal.api.workflowservice.v1.GetSystemInfoRequest; +import io.temporal.api.workflowservice.v1.RespondNexusTaskCompletedRequest; import io.temporal.client.*; import io.temporal.common.reporter.MicrometerClientStatsReporter; import io.temporal.failure.ApplicationFailure; import io.temporal.failure.CanceledFailure; import io.temporal.serviceclient.MetricsTag; import io.temporal.serviceclient.MetricsType; +import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.testing.internal.SDKTestWorkflowRule; import io.temporal.workflow.*; import java.time.Duration; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.concurrent.ExecutionException; @@ -149,6 +157,51 @@ public void testAsynchronousStartAndGetResult() throws InterruptedException, Exe }); } + @Test + public void testNexusResponseMetricsHaveConsistentTagKeys() { + WorkflowServiceStubs service = testWorkflowRule.getWorkflowServiceStubs(); + service.blockingStub().getSystemInfo(GetSystemInfoRequest.getDefaultInstance()); + + Map nexusTags = new HashMap<>(MetricsTag.defaultTags(MetricsTag.DEFAULT_VALUE)); + nexusTags.put(MetricsTag.NEXUS_SERVICE, "TestNexusService"); + nexusTags.put(MetricsTag.NEXUS_OPERATION, "testOperation"); + Scope nexusScope = service.getOptions().getMetricsScope().tagged(nexusTags); + // The test server rejects the empty task token, and the interceptor records the RPC. + assertThrows( + StatusRuntimeException.class, + () -> + service + .blockingStub() + .withOption(MetricsTag.METRICS_TAGS_CALL_OPTIONS_KEY, nexusScope) + .respondNexusTaskCompleted(RespondNexusTaskCompletedRequest.getDefaultInstance())); + + assertEventually( + Duration.ofSeconds(2), + () -> { + for (String metric : + new String[] {MetricsType.TEMPORAL_REQUEST, MetricsType.TEMPORAL_REQUEST_LATENCY}) { + Meter ordinary = + registry.find(metric).tag(MetricsTag.OPERATION_NAME, "GetSystemInfo").meter(); + Meter nexus = + registry + .find(metric) + .tag(MetricsTag.OPERATION_NAME, "RespondNexusTaskCompleted") + .meter(); + assertNotNull(ordinary); + assertNotNull(nexus); + assertEquals( + ordinary.getId().getTags().stream().map(Tag::getKey).collect(Collectors.toSet()), + nexus.getId().getTags().stream().map(Tag::getKey).collect(Collectors.toSet())); + assertEquals( + MetricsTag.DEFAULT_VALUE, ordinary.getId().getTag(MetricsTag.NEXUS_SERVICE)); + assertEquals( + MetricsTag.DEFAULT_VALUE, ordinary.getId().getTag(MetricsTag.NEXUS_OPERATION)); + assertEquals("TestNexusService", nexus.getId().getTag(MetricsTag.NEXUS_SERVICE)); + assertEquals("testOperation", nexus.getId().getTag(MetricsTag.NEXUS_OPERATION)); + } + }); + } + @Test public void testStandaloneActivityStartRequestTags() { // SAA is not supported by in-mem test server yet 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 2f0eaa0932..91cd488fc9 100644 --- a/temporal-serviceclient/src/main/java/io/temporal/serviceclient/MetricsTag.java +++ b/temporal-serviceclient/src/main/java/io/temporal/serviceclient/MetricsTag.java @@ -71,6 +71,8 @@ private static Map tags(String namespace) { .put(SIGNAL_NAME, DEFAULT_VALUE) .put(QUERY_TYPE, DEFAULT_VALUE) .put(UPDATE_NAME, DEFAULT_VALUE) + .put(NEXUS_SERVICE, DEFAULT_VALUE) + .put(NEXUS_OPERATION, DEFAULT_VALUE) .put(TASK_QUEUE, DEFAULT_VALUE) .put(STATUS_CODE, DEFAULT_VALUE) .put(EXCEPTION, DEFAULT_VALUE)