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