Search in sources :

Example 21 with Scope

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

the class ReplayDeciderCacheTests method whenHistoryIsPartialAndCacheIsEmptyThenExceptionIsThrown.

@Test
public void whenHistoryIsPartialAndCacheIsEmptyThenExceptionIsThrown() throws Exception {
    // Arrange
    Map<String, String> tags = new ImmutableMap.Builder<String, String>(2).put(MetricsTag.DOMAIN, "domain").put(MetricsTag.TASK_LIST, "stickyTaskList").build();
    StatsReporter reporter = mock(StatsReporter.class);
    Scope scope = new RootScopeBuilder().reporter(reporter).reportEvery(Duration.ofMillis(10)).tagged(tags);
    DeciderCache replayDeciderCache = new DeciderCache(10, scope);
    // Act
    PollForDecisionTaskResponse decisionTask = HistoryUtils.generateDecisionTaskWithPartialHistory();
    try {
        replayDeciderCache.getOrCreate(decisionTask, () -> createFakeDecider(decisionTask));
    } catch (IllegalArgumentException ex) {
        // Wait for reporter
        Thread.sleep(600);
        verify(reporter, times(1)).reportCounter(MetricsType.STICKY_CACHE_MISS, tags, 1);
        return;
    }
    fail("Expected replayDeciderCache.getOrCreate to throw IllegalArgumentException but no exception was thrown");
}
Also used : RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) Scope(com.uber.m3.tally.Scope) NoopScope(com.uber.cadence.internal.metrics.NoopScope) PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) StatsReporter(com.uber.m3.tally.StatsReporter) ImmutableMap(com.uber.m3.util.ImmutableMap) Test(org.junit.Test)

Example 22 with Scope

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

the class ReplayDeciderCacheTests method whenHistoryIsPartialCachedEntryIsReturned.

@Test(timeout = 2000)
public void whenHistoryIsPartialCachedEntryIsReturned() throws Exception {
    // Arrange
    Map<String, String> tags = new ImmutableMap.Builder<String, String>(2).put(MetricsTag.DOMAIN, "domain").put(MetricsTag.TASK_LIST, "stickyTaskList").build();
    StatsReporter reporter = mock(StatsReporter.class);
    Scope scope = new RootScopeBuilder().reporter(reporter).reportEvery(Duration.ofMillis(500)).tagged(tags);
    DeciderCache replayDeciderCache = new DeciderCache(10, scope);
    TestWorkflowService service = new TestWorkflowService();
    service.lockTimeSkipping("test");
    PollForDecisionTaskResponse decisionTask = HistoryUtils.generateDecisionTaskWithInitialHistory("domain", "taskList", "workflowType", service);
    Decider decider = replayDeciderCache.getOrCreate(decisionTask, () -> createFakeDecider(decisionTask));
    replayDeciderCache.addToCache(decisionTask, decider);
    // Act
    PollForDecisionTaskResponse decisionTask2 = HistoryUtils.generateDecisionTaskWithPartialHistoryFromExistingTask(decisionTask, "domain", "stickyTaskList", service);
    Decider decider2 = replayDeciderCache.getOrCreate(decisionTask2, () -> doNotCreateFakeDecider(decisionTask2));
    // Assert
    // Wait for reporter
    Thread.sleep(500);
    verify(reporter, times(1)).reportCounter(MetricsType.STICKY_CACHE_HIT, tags, 1);
    assertEquals(decider, decider2);
    service.close();
}
Also used : RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) Scope(com.uber.m3.tally.Scope) NoopScope(com.uber.cadence.internal.metrics.NoopScope) TestWorkflowService(com.uber.cadence.internal.testservice.TestWorkflowService) PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) StatsReporter(com.uber.m3.tally.StatsReporter) ImmutableMap(com.uber.m3.util.ImmutableMap) Test(org.junit.Test)

Example 23 with Scope

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

the class NoopScope method getInstance.

public static synchronized Scope getInstance() {
    if (noopScope == null) {
        noopCounter = delta -> {
        };
        noopGauge = value -> {
        };
        noopTimer = new Timer() {

            @Override
            public void record(Duration interval) {
            }

            @Override
            public Stopwatch start() {
                return new Stopwatch(0, stopwatchStart -> {
                });
            }
        };
        noopHistogram = new Histogram() {

            @Override
            public void recordValue(double value) {
            }

            @Override
            public void recordDuration(Duration value) {
            }

            @Override
            public Stopwatch start() {
                return new Stopwatch(0, stopwatchStart -> {
                });
            }
        };
        noopScope = new NoopScope();
    }
    return noopScope;
}
Also used : Stopwatch(com.uber.m3.tally.Stopwatch) Scope(com.uber.m3.tally.Scope) Timer(com.uber.m3.tally.Timer) CapableOf(com.uber.m3.tally.CapableOf) Map(java.util.Map) Counter(com.uber.m3.tally.Counter) Histogram(com.uber.m3.tally.Histogram) Capabilities(com.uber.m3.tally.Capabilities) Gauge(com.uber.m3.tally.Gauge) Duration(com.uber.m3.util.Duration) Buckets(com.uber.m3.tally.Buckets) Histogram(com.uber.m3.tally.Histogram) Timer(com.uber.m3.tally.Timer) Stopwatch(com.uber.m3.tally.Stopwatch) Duration(com.uber.m3.util.Duration)

Example 24 with Scope

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

the class POJOActivityTaskHandler method mapToActivityFailure.

@SuppressWarnings("deprecation")
private ActivityTaskHandler.Result mapToActivityFailure(Throwable exception, String activityId, Scope metricsScope, boolean isLocalActivity) {
    if (exception instanceof ActivityCanceledException) {
        if (isLocalActivity) {
            metricsScope.counter(MetricsType.LOCAL_ACTIVITY_EXEC_CANCELLED_COUNTER).inc(1);
            metricsScope.counter(MetricsType.LOCAL_ACTIVITY_CANCELED_COUNTER).inc(1);
        } else {
            metricsScope.counter(MetricsType.ACTIVITY_EXEC_CANCELLED_COUNTER).inc(1);
            metricsScope.counter(MetricsType.ACTIVITY_CANCELED_COUNTER).inc(1);
        }
        String stackTrace = FailureConverter.serializeStackTrace(exception);
        throw new FailureWrapperException(Failure.newBuilder().setStackTrace(stackTrace).setCanceledFailureInfo(CanceledFailureInfo.newBuilder()).build());
    }
    Scope ms = metricsScope.tagged(ImmutableMap.of(MetricsTag.EXCEPTION, exception.getClass().getSimpleName()));
    if (isLocalActivity) {
        ms.counter(MetricsType.LOCAL_ACTIVITY_EXEC_FAILED_COUNTER).inc(1);
        ms.counter(MetricsType.LOCAL_ACTIVITY_FAILED_COUNTER).inc(1);
    } else {
        ms.counter(MetricsType.ACTIVITY_EXEC_FAILED_COUNTER).inc(1);
    }
    if (exception instanceof TemporalFailure) {
        ((TemporalFailure) exception).setDataConverter(dataConverter);
    }
    if (exception instanceof TimeoutFailure) {
        exception = new SimulatedTimeoutFailure((TimeoutFailure) exception);
    }
    Failure failure = FailureConverter.exceptionToFailure(exception);
    RespondActivityTaskFailedRequest.Builder result = RespondActivityTaskFailedRequest.newBuilder().setFailure(failure);
    return new ActivityTaskHandler.Result(activityId, null, new Result.TaskFailedResult(result.build(), exception), null, null, false);
}
Also used : FailureWrapperException(io.temporal.internal.replay.FailureWrapperException) Scope(com.uber.m3.tally.Scope) TimeoutFailure(io.temporal.failure.TimeoutFailure) SimulatedTimeoutFailure(io.temporal.failure.SimulatedTimeoutFailure) ActivityCanceledException(io.temporal.client.ActivityCanceledException) TemporalFailure(io.temporal.failure.TemporalFailure) SimulatedTimeoutFailure(io.temporal.failure.SimulatedTimeoutFailure) TimeoutFailure(io.temporal.failure.TimeoutFailure) TemporalFailure(io.temporal.failure.TemporalFailure) SimulatedTimeoutFailure(io.temporal.failure.SimulatedTimeoutFailure) Failure(io.temporal.api.failure.v1.Failure) RespondActivityTaskFailedRequest(io.temporal.api.workflowservice.v1.RespondActivityTaskFailedRequest)

Example 25 with Scope

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

the class GenericWorkflowClientExternalImpl method signalWithStart.

@Override
public WorkflowExecution signalWithStart(SignalWithStartWorkflowExecutionParameters parameters) {
    StartWorkflowExecutionRequest startParameters = parameters.getStartParameters();
    SignalWithStartWorkflowExecutionRequest.Builder request = SignalWithStartWorkflowExecutionRequest.newBuilder().setNamespace(namespace).setRequestId(generateUniqueId()).setIdentity(identity).setSignalName(parameters.getSignalName()).setWorkflowRunTimeout(startParameters.getWorkflowRunTimeout()).setWorkflowExecutionTimeout(startParameters.getWorkflowExecutionTimeout()).setWorkflowTaskTimeout(startParameters.getWorkflowTaskTimeout()).setWorkflowType(startParameters.getWorkflowType()).setWorkflowIdReusePolicy(startParameters.getWorkflowIdReusePolicy()).setCronSchedule(startParameters.getCronSchedule());
    Optional<Payloads> signalInput = parameters.getSignalInput();
    if (signalInput.isPresent()) {
        request.setSignalInput(signalInput.get());
    }
    if (startParameters.hasInput()) {
        request.setInput(startParameters.getInput());
    }
    if (startParameters.hasTaskQueue()) {
        request.setTaskQueue(startParameters.getTaskQueue());
    }
    String workflowId = startParameters.getWorkflowId();
    if (workflowId.isEmpty()) {
        workflowId = generateUniqueId();
    }
    request.setWorkflowId(workflowId);
    if (startParameters.hasRetryPolicy()) {
        request.setRetryPolicy(startParameters.getRetryPolicy());
    }
    if (startParameters.hasHeader()) {
        request.setHeader(startParameters.getHeader());
    }
    Map<String, String> tags = new ImmutableMap.Builder<String, String>(2).put(MetricsTag.WORKFLOW_TYPE, request.getWorkflowType().getName()).put(MetricsTag.TASK_QUEUE, request.getTaskQueue().getName()).put(MetricsTag.SIGNAL_NAME, request.getSignalName()).build();
    Scope scope = metricsScope.tagged(tags);
    SignalWithStartWorkflowExecutionResponse result;
    result = GrpcRetryer.retryWithResult(RpcRetryOptions.newBuilder().buildWithDefaultsFrom(service.getOptions().getRpcRetryOptions()), () -> service.blockingStub().withOption(METRICS_TAGS_CALL_OPTIONS_KEY, scope).signalWithStartWorkflowExecution(request.build()));
    return WorkflowExecution.newBuilder().setRunId(result.getRunId()).setWorkflowId(request.getWorkflowId()).build();
}
Also used : SignalWithStartWorkflowExecutionRequest(io.temporal.api.workflowservice.v1.SignalWithStartWorkflowExecutionRequest) Scope(com.uber.m3.tally.Scope) SignalWithStartWorkflowExecutionResponse(io.temporal.api.workflowservice.v1.SignalWithStartWorkflowExecutionResponse) SignalWithStartWorkflowExecutionRequest(io.temporal.api.workflowservice.v1.SignalWithStartWorkflowExecutionRequest) StartWorkflowExecutionRequest(io.temporal.api.workflowservice.v1.StartWorkflowExecutionRequest) Payloads(io.temporal.api.common.v1.Payloads)

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