Search in sources :

Example 1 with Counter

use of com.uber.m3.tally.Counter 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 2 with Counter

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

the class ActivityPollTask method pollTask.

@Override
protected PollForActivityTaskResponse pollTask() throws TException {
    options.getMetricsScope().counter(MetricsType.ACTIVITY_POLL_COUNTER).inc(1);
    Stopwatch sw = options.getMetricsScope().timer(MetricsType.ACTIVITY_POLL_LATENCY).start();
    PollForActivityTaskRequest pollRequest = new PollForActivityTaskRequest();
    pollRequest.setDomain(domain);
    pollRequest.setIdentity(options.getIdentity());
    pollRequest.setTaskList(new TaskList().setName(taskList));
    if (options.getTaskListActivitiesPerSecond() > 0) {
        TaskListMetadata metadata = new TaskListMetadata();
        metadata.setMaxTasksPerSecond(options.getTaskListActivitiesPerSecond());
        pollRequest.setTaskListMetadata(metadata);
    }
    if (log.isDebugEnabled()) {
        log.debug("poll request begin: " + pollRequest);
    }
    PollForActivityTaskResponse result;
    try {
        result = service.PollForActivityTask(pollRequest);
    } catch (InternalServiceError | ServiceBusyError e) {
        options.getMetricsScope().counter(MetricsType.ACTIVITY_POLL_TRANSIENT_FAILED_COUNTER).inc(1);
        throw e;
    } catch (TException e) {
        options.getMetricsScope().counter(MetricsType.ACTIVITY_POLL_FAILED_COUNTER).inc(1);
        throw e;
    }
    if (result == null || result.getTaskToken() == null) {
        if (log.isDebugEnabled()) {
            log.debug("poll request returned no task");
        }
        options.getMetricsScope().counter(MetricsType.ACTIVITY_POLL_NO_TASK_COUNTER).inc(1);
        return null;
    }
    if (log.isTraceEnabled()) {
        log.trace("poll request returned " + result);
    }
    sw.stop();
    return result;
}
Also used : PollForActivityTaskRequest(com.uber.cadence.PollForActivityTaskRequest) TException(org.apache.thrift.TException) TaskListMetadata(com.uber.cadence.TaskListMetadata) TaskList(com.uber.cadence.TaskList) Stopwatch(com.uber.m3.tally.Stopwatch) PollForActivityTaskResponse(com.uber.cadence.PollForActivityTaskResponse) ServiceBusyError(com.uber.cadence.ServiceBusyError) InternalServiceError(com.uber.cadence.InternalServiceError)

Example 3 with Counter

use of com.uber.m3.tally.Counter 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));
}
Also used : Histogram(com.uber.m3.tally.Histogram) Counter(com.uber.m3.tally.Counter) Scope(com.uber.m3.tally.Scope) ReplayAwareScope(com.uber.cadence.internal.metrics.ReplayAwareScope) Timer(com.uber.m3.tally.Timer) ReplayAwareScope(com.uber.cadence.internal.metrics.ReplayAwareScope) ValueBuckets(com.uber.m3.tally.ValueBuckets) Buckets(com.uber.m3.tally.Buckets) Gauge(com.uber.m3.tally.Gauge) Test(org.junit.Test)

Example 4 with Counter

use of com.uber.m3.tally.Counter 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));
}
Also used : Histogram(com.uber.m3.tally.Histogram) Counter(com.uber.m3.tally.Counter) Scope(com.uber.m3.tally.Scope) ReplayAwareScope(com.uber.cadence.internal.metrics.ReplayAwareScope) Timer(com.uber.m3.tally.Timer) ReplayAwareScope(com.uber.cadence.internal.metrics.ReplayAwareScope) ValueBuckets(com.uber.m3.tally.ValueBuckets) Buckets(com.uber.m3.tally.Buckets) Gauge(com.uber.m3.tally.Gauge) Test(org.junit.Test)

Example 5 with Counter

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

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

Aggregations

Counter (com.uber.m3.tally.Counter)4 Gauge (com.uber.m3.tally.Gauge)4 Histogram (com.uber.m3.tally.Histogram)4 Scope (com.uber.m3.tally.Scope)4 Timer (com.uber.m3.tally.Timer)4 Test (org.junit.Test)4 ReplayAwareScope (com.uber.cadence.internal.metrics.ReplayAwareScope)2 Buckets (com.uber.m3.tally.Buckets)2 ValueBuckets (com.uber.m3.tally.ValueBuckets)2 InternalServiceError (com.uber.cadence.InternalServiceError)1 PollForActivityTaskRequest (com.uber.cadence.PollForActivityTaskRequest)1 PollForActivityTaskResponse (com.uber.cadence.PollForActivityTaskResponse)1 ServiceBusyError (com.uber.cadence.ServiceBusyError)1 TaskList (com.uber.cadence.TaskList)1 TaskListMetadata (com.uber.cadence.TaskListMetadata)1 Stopwatch (com.uber.m3.tally.Stopwatch)1 TException (org.apache.thrift.TException)1