Search in sources :

Example 26 with Scope

use of com.uber.m3.tally.Scope in project sdk-java by temporalio.

the class GenericWorkflowClientExternalImpl method query.

@Override
public QueryWorkflowResponse query(QueryWorkflowRequest queryParameters) {
    Map<String, String> tags = new ImmutableMap.Builder<String, String>(1).put(MetricsTag.QUERY_TYPE, queryParameters.getQuery().getQueryType()).build();
    Scope scope = metricsScope.tagged(tags);
    return GrpcRetryer.retryWithResult(RpcRetryOptions.newBuilder().buildWithDefaultsFrom(service.getOptions().getRpcRetryOptions()), () -> service.blockingStub().withOption(METRICS_TAGS_CALL_OPTIONS_KEY, scope).queryWorkflow(queryParameters));
}
Also used : Scope(com.uber.m3.tally.Scope)

Example 27 with Scope

use of com.uber.m3.tally.Scope in project sdk-java by temporalio.

the class ReplayAwareScopeTest method testReplayAwareScopeNotReplaying.

@Test
public void testReplayAwareScopeNotReplaying() {
    Scope scope = mock(Scope.class);
    Counter counter = mock(Counter.class);
    Gauge gauge = mock(Gauge.class);
    Timer timer = mock(Timer.class);
    Histogram histogram = mock(Histogram.class);
    @SuppressWarnings("deprecation") com.uber.m3.tally.Buckets buckets = ValueBuckets.linear(0, 10, 10);
    when(scope.counter("test-counter")).thenReturn(counter);
    when(scope.gauge("test-gauge")).thenReturn(gauge);
    when(scope.timer("test-timer")).thenReturn(timer);
    when(scope.histogram("test-histogram", buckets)).thenReturn(histogram);
    TestContext context = new TestContext(false);
    Scope replayAwareScope = new ReplayAwareScope(scope, context, System::currentTimeMillis);
    replayAwareScope.counter("test-counter").inc(1);
    replayAwareScope.gauge("test-gauge").update(100.0);
    replayAwareScope.timer("test-timer").record(Duration.ofMillis(100));
    replayAwareScope.histogram("test-histogram", buckets).recordValue(10);
    replayAwareScope.histogram("test-histogram", buckets).recordDuration(Duration.ofHours(1));
    verify(counter, times(1)).inc(1);
    verify(gauge, times(1)).update(100.0);
    verify(timer, times(1)).record(Duration.ofMillis(100));
    verify(histogram, times(1)).recordValue(10);
    verify(histogram, times(1)).recordDuration(Duration.ofHours(1));
}
Also used : Histogram(com.uber.m3.tally.Histogram) Counter(com.uber.m3.tally.Counter) Scope(com.uber.m3.tally.Scope) Timer(com.uber.m3.tally.Timer) Gauge(com.uber.m3.tally.Gauge) Test(org.junit.Test)

Example 28 with Scope

use of com.uber.m3.tally.Scope in project sdk-java by temporalio.

the class ReplayAwareScopeTest method testCustomClockForTimer.

@Test
public void testCustomClockForTimer() {
    Scope scope = mock(Scope.class);
    Timer timer = mock(Timer.class);
    Histogram histogram = mock(Histogram.class);
    @SuppressWarnings("deprecation") com.uber.m3.tally.Buckets buckets = ValueBuckets.linear(0, 10, 10);
    when(scope.timer("test-timer")).thenReturn(timer);
    when(scope.histogram("test-histogram", buckets)).thenReturn(histogram);
    TestContext context = new TestContext(false);
    TestClock clock = new TestClock();
    clock.setTime(0);
    Scope replayAwareScope = new ReplayAwareScope(scope, context, clock);
    Stopwatch sw = replayAwareScope.timer("test-timer").start();
    clock.setTime(100);
    sw.stop();
    sw = replayAwareScope.histogram("test-histogram", buckets).start();
    clock.setTime(150);
    sw.stop();
    verify(timer, times(1)).record(Duration.ofMillis(100));
    verify(histogram, times(1)).recordDuration(Duration.ofMillis(50));
}
Also used : Histogram(com.uber.m3.tally.Histogram) Scope(com.uber.m3.tally.Scope) Timer(com.uber.m3.tally.Timer) Stopwatch(com.uber.m3.tally.Stopwatch) Test(org.junit.Test)

Example 29 with Scope

use of com.uber.m3.tally.Scope in project sdk-java by temporalio.

the class ReplayWorkflowRunTaskHandlerCacheTests method whenHistoryIsPartialCachedEntryIsReturned.

@Test(timeout = 2000)
public void whenHistoryIsPartialCachedEntryIsReturned() throws Exception {
    // Arrange
    Map<String, String> tags = new ImmutableMap.Builder<String, String>(2).put(MetricsTag.NAMESPACE, "namespace").put(MetricsTag.TASK_QUEUE, "stickyTaskQueue").build();
    Scope scope = metricsScope.tagged(tags);
    WorkflowExecutorCache cache = new WorkflowExecutorCache(10, scope);
    TestWorkflowService testService = new TestWorkflowService(true);
    WorkflowServiceStubs service = testService.newClientStub();
    try {
        PollWorkflowTaskQueueResponse workflowTask = HistoryUtils.generateWorkflowTaskWithInitialHistory("namespace", "taskQueue", "workflowType", service);
        WorkflowRunTaskHandler workflowRunTaskHandler = cache.getOrCreate(workflowTask, scope, () -> createFakeExecutor(workflowTask));
        cache.addToCache(workflowTask.getWorkflowExecution(), workflowRunTaskHandler);
        // Act
        PollWorkflowTaskQueueResponse workflowTask2 = HistoryUtils.generateWorkflowTaskWithPartialHistoryFromExistingTask(workflowTask, "namespace", "stickyTaskQueue", service);
        WorkflowRunTaskHandler workflowRunTaskHandler2 = cache.getOrCreate(workflowTask2, scope, () -> doNotCreateFakeExecutor(workflowTask2));
        // Assert
        // Wait for reporter
        Thread.sleep(100);
        reporter.assertCounter(MetricsType.STICKY_CACHE_HIT, tags, 1);
        assertEquals(workflowRunTaskHandler, workflowRunTaskHandler2);
    } finally {
        service.shutdownNow();
        service.awaitTermination(1, TimeUnit.SECONDS);
        testService.close();
    }
}
Also used : PollWorkflowTaskQueueResponse(io.temporal.api.workflowservice.v1.PollWorkflowTaskQueueResponse) NoopScope(com.uber.m3.tally.NoopScope) Scope(com.uber.m3.tally.Scope) TestWorkflowService(io.temporal.internal.testservice.TestWorkflowService) ImmutableMap(com.uber.m3.util.ImmutableMap) WorkflowServiceStubs(io.temporal.serviceclient.WorkflowServiceStubs) Test(org.junit.Test)

Example 30 with Scope

use of com.uber.m3.tally.Scope in project sdk-java by temporalio.

the class ReplayWorkflowRunTaskHandlerCacheTests method whenHistoryIsPartialAndCacheIsEmptyThenExceptionIsThrown.

@Test
public void whenHistoryIsPartialAndCacheIsEmptyThenExceptionIsThrown() throws Exception {
    // Arrange
    Map<String, String> tags = new ImmutableMap.Builder<String, String>(2).put(MetricsTag.NAMESPACE, "namespace").put(MetricsTag.TASK_QUEUE, "stickyTaskQueue").build();
    Scope scope = metricsScope.tagged(tags);
    WorkflowExecutorCache cache = new WorkflowExecutorCache(10, scope);
    // Act
    PollWorkflowTaskQueueResponse workflowTask = HistoryUtils.generateWorkflowTaskWithPartialHistory();
    try {
        cache.getOrCreate(workflowTask, scope, () -> createFakeExecutor(workflowTask));
        fail("Expected workflowExecutorCache.getOrCreate to throw IllegalArgumentException but no exception was thrown");
    } catch (IllegalArgumentException ex) {
        // Wait for reporter
        Thread.sleep(100);
        reporter.assertCounter(MetricsType.STICKY_CACHE_MISS, tags, 1);
    }
}
Also used : PollWorkflowTaskQueueResponse(io.temporal.api.workflowservice.v1.PollWorkflowTaskQueueResponse) NoopScope(com.uber.m3.tally.NoopScope) Scope(com.uber.m3.tally.Scope) ImmutableMap(com.uber.m3.util.ImmutableMap) Test(org.junit.Test)

Aggregations

Scope (com.uber.m3.tally.Scope)35 RootScopeBuilder (com.uber.m3.tally.RootScopeBuilder)15 Test (org.junit.Test)13 ImmutableMap (com.uber.m3.util.ImmutableMap)12 StatsReporter (com.uber.m3.tally.StatsReporter)11 NoopScope (com.uber.cadence.internal.metrics.NoopScope)9 Histogram (com.uber.m3.tally.Histogram)7 Timer (com.uber.m3.tally.Timer)7 PollForDecisionTaskResponse (com.uber.cadence.PollForDecisionTaskResponse)5 WorkflowOptions (com.uber.cadence.client.WorkflowOptions)5 Counter (com.uber.m3.tally.Counter)5 Gauge (com.uber.m3.tally.Gauge)5 Stopwatch (com.uber.m3.tally.Stopwatch)5 Buckets (com.uber.m3.tally.Buckets)4 NoopScope (com.uber.m3.tally.NoopScope)4 ReplayAwareScope (com.uber.cadence.internal.metrics.ReplayAwareScope)3 ValueBuckets (com.uber.m3.tally.ValueBuckets)3 PollWorkflowTaskQueueResponse (io.temporal.api.workflowservice.v1.PollWorkflowTaskQueueResponse)3 WorkflowServiceStubs (io.temporal.serviceclient.WorkflowServiceStubs)3 HttpServer (com.sun.net.httpserver.HttpServer)2