Search in sources :

Example 1 with Scope

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();
}
Also used : Scope(com.uber.m3.tally.Scope) StartWorkflowExecutionResponse(io.temporal.api.workflowservice.v1.StartWorkflowExecutionResponse) SignalWithStartWorkflowExecutionResponse(io.temporal.api.workflowservice.v1.SignalWithStartWorkflowExecutionResponse) ImmutableMap(com.uber.m3.util.ImmutableMap)

Example 2 with Scope

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));
}
Also used : Scope(com.uber.m3.tally.Scope)

Example 3 with Scope

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);
}
Also used : Scope(com.uber.m3.tally.Scope)

Example 4 with 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));
}
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 5 with Scope

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);
}
Also used : PollWorkflowTaskQueueResponse(io.temporal.api.workflowservice.v1.PollWorkflowTaskQueueResponse) NoopScope(com.uber.m3.tally.NoopScope) Scope(com.uber.m3.tally.Scope) RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) WorkflowExecution(io.temporal.api.common.v1.WorkflowExecution) 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