Search in sources :

Example 16 with Scope

use of com.uber.m3.tally.Scope in project cadence-client by uber-java.

the class ActivityPollTaskBase method poll.

public PollForActivityTaskResponse poll() throws TException {
    PollForActivityTaskResponse result = pollTask();
    if (result == null || result.getTaskToken() == null) {
        return null;
    }
    Scope metricsScope = options.getMetricsScope().tagged(ImmutableMap.of(MetricsTag.ACTIVITY_TYPE, result.getActivityType().getName(), MetricsTag.WORKFLOW_TYPE, result.getWorkflowType().getName()));
    metricsScope.counter(MetricsType.ACTIVITY_POLL_SUCCEED_COUNTER).inc(1);
    metricsScope.timer(MetricsType.ACTIVITY_SCHEDULED_TO_START_LATENCY).record(Duration.ofNanos(result.getStartedTimestamp() - result.getScheduledTimestampOfThisAttempt()));
    return result;
}
Also used : Scope(com.uber.m3.tally.Scope) PollForActivityTaskResponse(com.uber.cadence.PollForActivityTaskResponse)

Example 17 with Scope

use of com.uber.m3.tally.Scope in project cadence-client by uber-java.

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);
    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) ReplayAwareScope(com.uber.cadence.internal.metrics.ReplayAwareScope) Timer(com.uber.m3.tally.Timer) ReplayAwareScope(com.uber.cadence.internal.metrics.ReplayAwareScope) ValueBuckets(com.uber.m3.tally.ValueBuckets) Buckets(com.uber.m3.tally.Buckets) Gauge(com.uber.m3.tally.Gauge) Test(org.junit.Test)

Example 18 with Scope

use of com.uber.m3.tally.Scope in project cadence-client by uber-java.

the class ReplayAwareScopeTest method testCustomClockForTimer.

@Test
public void testCustomClockForTimer() {
    Scope scope = mock(Scope.class);
    Timer timer = mock(Timer.class);
    Histogram histogram = mock(Histogram.class);
    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) ReplayAwareScope(com.uber.cadence.internal.metrics.ReplayAwareScope) Timer(com.uber.m3.tally.Timer) ReplayAwareScope(com.uber.cadence.internal.metrics.ReplayAwareScope) Stopwatch(com.uber.m3.tally.Stopwatch) ValueBuckets(com.uber.m3.tally.ValueBuckets) Buckets(com.uber.m3.tally.Buckets) Test(org.junit.Test)

Example 19 with Scope

use of com.uber.m3.tally.Scope in project cadence-client by uber-java.

the class ReplayAwareScopeTest method testReplayAwareScopeReplaying.

@Test
public void testReplayAwareScopeReplaying() {
    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);
    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(true);
    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, never()).inc(1);
    verify(gauge, never()).update(100.0);
    verify(timer, never()).record(Duration.ofMillis(100));
    verify(histogram, never()).recordValue(10);
    verify(histogram, never()).recordDuration(Duration.ofHours(1));
}
Also used : Histogram(com.uber.m3.tally.Histogram) Counter(com.uber.m3.tally.Counter) Scope(com.uber.m3.tally.Scope) ReplayAwareScope(com.uber.cadence.internal.metrics.ReplayAwareScope) Timer(com.uber.m3.tally.Timer) ReplayAwareScope(com.uber.cadence.internal.metrics.ReplayAwareScope) ValueBuckets(com.uber.m3.tally.ValueBuckets) Buckets(com.uber.m3.tally.Buckets) Gauge(com.uber.m3.tally.Gauge) Test(org.junit.Test)

Example 20 with Scope

use of com.uber.m3.tally.Scope in project cadence-client by uber-java.

the class StickyWorkerTest method whenStickyIsEnabledThenTheWorkflowIsCachedMutableSideEffect.

@Test
public void whenStickyIsEnabledThenTheWorkflowIsCachedMutableSideEffect() throws Exception {
    // Arrange
    String taskListName = "cachedStickyTest_MutableSideEffect";
    StatsReporter reporter = mock(StatsReporter.class);
    Scope scope = new RootScopeBuilder().reporter(reporter).reportEvery(com.uber.m3.util.Duration.ofMillis(300));
    WorkerFactoryOptions factoryOptions = WorkerFactoryOptions.newBuilder().setDisableStickyExecution(false).build();
    TestEnvironmentWrapper wrapper = new TestEnvironmentWrapper(factoryOptions, scope);
    WorkerFactory factory = wrapper.getWorkerFactory();
    Worker worker = factory.newWorker(taskListName);
    worker.registerWorkflowImplementationTypes(TestMutableSideEffectWorkflowImpl.class);
    factory.start();
    WorkflowOptions workflowOptions = new WorkflowOptions.Builder().setTaskList(taskListName).setExecutionStartToCloseTimeout(Duration.ofDays(30)).setTaskStartToCloseTimeout(Duration.ofSeconds(30)).build();
    TestMutableSideEffectWorkflow workflow = wrapper.getWorkflowClient().newWorkflowStub(TestMutableSideEffectWorkflow.class, workflowOptions);
    // Act
    ArrayDeque<Long> values = new ArrayDeque<>();
    values.add(1234L);
    values.add(1234L);
    // expected to be ignored as it is smaller than 1234.
    values.add(123L);
    values.add(3456L);
    mutableSideEffectValue.put(taskListName, values);
    String result = workflow.execute(taskListName);
    assertEquals("1234, 1234, 1234, 3456", result);
    // Wait for reporter
    Thread.sleep(600);
    // Verify the workflow succeeded without having to recover from a failure
    Map<String, String> tags = new ImmutableMap.Builder<String, String>(2).put(MetricsTag.DOMAIN, DOMAIN).put(MetricsTag.TASK_LIST, STICKY_TASK_LIST_METRIC_TAG).build();
    verify(reporter, atLeastOnce()).reportCounter(eq(MetricsType.STICKY_CACHE_HIT), eq(tags), anyInt());
    verify(reporter, never()).reportCounter(eq(MetricsType.STICKY_CACHE_MISS), eq(tags), anyInt());
    // Finish Workflow
    wrapper.close();
}
Also used : RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) StatsReporter(com.uber.m3.tally.StatsReporter) ArrayDeque(java.util.ArrayDeque) ImmutableMap(com.uber.m3.util.ImmutableMap) Scope(com.uber.m3.tally.Scope) NoopScope(com.uber.cadence.internal.metrics.NoopScope) WorkflowOptions(com.uber.cadence.client.WorkflowOptions)

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