use of com.uber.m3.tally.Scope in project sdk-java by temporalio.
the class GenericWorkflowClientExternalImpl method start.
@Override
public WorkflowExecution start(StartWorkflowExecutionRequest request) {
Map<String, String> tags = new ImmutableMap.Builder<String, String>(2).put(MetricsTag.WORKFLOW_TYPE, request.getWorkflowType().getName()).put(MetricsTag.TASK_QUEUE, request.getTaskQueue().getName()).build();
Scope scope = metricsScope.tagged(tags);
StartWorkflowExecutionResponse result;
result = GrpcRetryer.retryWithResult(RpcRetryOptions.newBuilder().buildWithDefaultsFrom(service.getOptions().getRpcRetryOptions()), () -> service.blockingStub().withOption(METRICS_TAGS_CALL_OPTIONS_KEY, scope).startWorkflowExecution(request));
return WorkflowExecution.newBuilder().setRunId(result.getRunId()).setWorkflowId(request.getWorkflowId()).build();
}
use of com.uber.m3.tally.Scope in project sdk-java by temporalio.
the class GenericWorkflowClientExternalImpl method signal.
@Override
public void signal(SignalWorkflowExecutionRequest request) {
Map<String, String> tags = new ImmutableMap.Builder<String, String>(1).put(MetricsTag.SIGNAL_NAME, request.getSignalName()).build();
Scope scope = metricsScope.tagged(tags);
GrpcRetryer.retry(RpcRetryOptions.newBuilder().buildWithDefaultsFrom(service.getOptions().getRpcRetryOptions()), () -> service.blockingStub().withOption(METRICS_TAGS_CALL_OPTIONS_KEY, scope).signalWorkflowExecution(request));
}
use of com.uber.m3.tally.Scope in project sdk-java by temporalio.
the class GrpcMetricsInterceptor method interceptCall.
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
Scope scope = callOptions.getOption(MetricsTag.METRICS_TAGS_CALL_OPTIONS_KEY);
if (scope == null) {
scope = defaultScope;
}
Map<String, String> tags = methodTags.get(method);
scope = scope.tagged(tags);
return new MetricsClientCall<>(next, method, callOptions, scope);
}
use of com.uber.m3.tally.Scope in project sdk-java by temporalio.
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);
@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(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 sdk-java by temporalio.
the class ReplayWorkflowRunTaskHandlerCacheTests method evictAnyWillInvalidateAnEntryRandomlyFromTheCache.
@Test
public void evictAnyWillInvalidateAnEntryRandomlyFromTheCache() throws Exception {
Map<String, String> tags = new ImmutableMap.Builder<String, String>(2).put(MetricsTag.NAMESPACE, NAMESPACE).put(MetricsTag.TASK_QUEUE, HOST_TASK_QUEUE).put(MetricsTag.WORKFLOW_TYPE, WORKFLOW_TYPE).build();
Scope scope = metricsScope.tagged(tags);
// Arrange
WorkflowExecutorCache cache = new WorkflowExecutorCache(50, scope);
PollWorkflowTaskQueueResponse workflowTask1 = HistoryUtils.generateWorkflowTaskWithInitialHistory();
PollWorkflowTaskQueueResponse workflowTask2 = HistoryUtils.generateWorkflowTaskWithInitialHistory();
PollWorkflowTaskQueueResponse workflowTask3 = HistoryUtils.generateWorkflowTaskWithInitialHistory();
// Act
WorkflowRunTaskHandler workflowRunTaskHandler = cache.getOrCreate(workflowTask1, scope, () -> createFakeExecutor(workflowTask1));
cache.addToCache(workflowTask1.getWorkflowExecution(), workflowRunTaskHandler);
workflowRunTaskHandler = cache.getOrCreate(workflowTask2, scope, () -> createFakeExecutor(workflowTask2));
cache.addToCache(workflowTask2.getWorkflowExecution(), workflowRunTaskHandler);
workflowRunTaskHandler = cache.getOrCreate(workflowTask3, scope, () -> createFakeExecutor(workflowTask3));
WorkflowExecution execution = workflowTask3.getWorkflowExecution();
cache.addToCache(execution, workflowRunTaskHandler);
assertEquals(3, cache.size());
cache.evictAnyNotInProcessing(execution, scope);
// Assert
assertEquals(2, cache.size());
// Wait for reporter
Thread.sleep(100);
reporter.assertCounter(MetricsType.STICKY_CACHE_TOTAL_FORCED_EVICTION, tags, 3);
}
Aggregations