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;
}
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));
}
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));
}
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));
}
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();
}
Aggregations