Search in sources :

Example 6 with Scope

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

the class StickyWorkerTest method workflowCacheEvictionDueToThreads.

@Test
public void workflowCacheEvictionDueToThreads() {
    // Arrange
    String taskListName = "workflowCacheEvictionDueToThreads";
    StatsReporter reporter = mock(StatsReporter.class);
    Scope scope = new RootScopeBuilder().reporter(reporter).reportEvery(com.uber.m3.util.Duration.ofMillis(300));
    WorkerFactoryOptions factoryOptions = WorkerFactoryOptions.newBuilder().setDisableStickyExecution(false).setMaxWorkflowThreadCount(10).setStickyCacheSize(100).build();
    TestEnvironmentWrapper wrapper = new TestEnvironmentWrapper(factoryOptions, scope);
    WorkerFactory factory = wrapper.getWorkerFactory();
    Worker worker = factory.newWorker(taskListName, WorkerOptions.newBuilder().setMaxConcurrentWorkflowExecutionSize(5).build());
    worker.registerWorkflowImplementationTypes(ActivitiesWorkflowImpl.class);
    worker.registerActivitiesImplementations(new ActivitiesImpl());
    factory.start();
    WorkflowOptions workflowOptions = new WorkflowOptions.Builder().setTaskList(taskListName).setExecutionStartToCloseTimeout(Duration.ofDays(30)).setTaskStartToCloseTimeout(Duration.ofSeconds(1)).build();
    int count = 100;
    ActivitiesWorkflow[] workflows = new ActivitiesWorkflow[count];
    WorkflowParams w = new WorkflowParams();
    w.CadenceSleep = Duration.ofSeconds(1);
    w.ChainSequence = 2;
    w.ConcurrentCount = 1;
    w.PayloadSizeBytes = 10;
    w.TaskListName = taskListName;
    for (int i = 0; i < count; i++) {
        ActivitiesWorkflow workflow = wrapper.getWorkflowClient().newWorkflowStub(ActivitiesWorkflow.class, workflowOptions);
        workflows[i] = workflow;
        WorkflowClient.start(workflow::execute, w);
    }
    for (int i = 0; i < count; i++) {
        workflows[i].execute(w);
    }
    // Finish Workflow
    wrapper.close();
}
Also used : RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) StatsReporter(com.uber.m3.tally.StatsReporter) Scope(com.uber.m3.tally.Scope) NoopScope(com.uber.cadence.internal.metrics.NoopScope) WorkflowOptions(com.uber.cadence.client.WorkflowOptions)

Example 7 with Scope

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

the class StickyWorkerTest method whenStickyIsEnabledThenTheWorkflowIsCachedChildWorkflows.

@Test
public void whenStickyIsEnabledThenTheWorkflowIsCachedChildWorkflows() throws Exception {
    // Arrange
    String taskListName = "cachedStickyTest_ChildWorkflows";
    StatsReporter reporter = mock(StatsReporter.class);
    Scope scope = new RootScopeBuilder().reporter(reporter).reportEvery(com.uber.m3.util.Duration.ofMillis(300));
    WorkerFactoryOptions factoryOptions = WorkerFactoryOptions.newBuilder().setDisableStickyExecution(false).build();
    TestEnvironmentWrapper wrapper = new TestEnvironmentWrapper(factoryOptions, scope);
    WorkerFactory factory = wrapper.getWorkerFactory();
    Worker worker = factory.newWorker(taskListName);
    worker.registerWorkflowImplementationTypes(GreetingParentWorkflowImpl.class, GreetingChildImpl.class);
    factory.start();
    WorkflowOptions workflowOptions = new WorkflowOptions.Builder().setTaskList(taskListName).setExecutionStartToCloseTimeout(Duration.ofDays(30)).setTaskStartToCloseTimeout(Duration.ofSeconds(30)).build();
    GreetingParentWorkflow workflow = wrapper.getWorkflowClient().newWorkflowStub(GreetingParentWorkflow.class, workflowOptions);
    // Act
    Assert.assertEquals("Hello World!", workflow.getGreeting("World"));
    // Wait for reporter
    Thread.sleep(600);
    // Verify the workflow succeeded without having to recover from a failure
    Map<String, String> tags = new ImmutableMap.Builder<String, String>(2).put(MetricsTag.DOMAIN, DOMAIN).put(MetricsTag.TASK_LIST, STICKY_TASK_LIST_METRIC_TAG).build();
    verify(reporter, atLeastOnce()).reportCounter(eq(MetricsType.STICKY_CACHE_HIT), eq(tags), anyInt());
    verify(reporter, never()).reportCounter(eq(MetricsType.STICKY_CACHE_MISS), eq(tags), anyInt());
    // Finish Workflow
    wrapper.close();
}
Also used : RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) StatsReporter(com.uber.m3.tally.StatsReporter) ImmutableMap(com.uber.m3.util.ImmutableMap) Scope(com.uber.m3.tally.Scope) NoopScope(com.uber.cadence.internal.metrics.NoopScope) WorkflowOptions(com.uber.cadence.client.WorkflowOptions)

Example 8 with Scope

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

the class MetricsTest method setUp.

public void setUp(com.uber.m3.util.Duration reportingFrequecy) {
    reporter = mock(StatsReporter.class);
    Scope scope = new RootScopeBuilder().reporter(reporter).reportEvery(reportingFrequecy);
    WorkflowClientOptions clientOptions = WorkflowClientOptions.newBuilder().setDomain(WorkflowTest.DOMAIN).setMetricsScope(scope).build();
    TestEnvironmentOptions testOptions = new TestEnvironmentOptions.Builder().setWorkflowClientOptions(clientOptions).build();
    testEnvironment = TestWorkflowEnvironment.newInstance(testOptions);
}
Also used : TestEnvironmentOptions(com.uber.cadence.testing.TestEnvironmentOptions) RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) WorkflowClientOptions(com.uber.cadence.client.WorkflowClientOptions) Scope(com.uber.m3.tally.Scope) RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) StatsReporter(com.uber.m3.tally.StatsReporter)

Example 9 with Scope

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

the class ReplayDeciderCacheTests method evictAnyWillInvalidateAnEntryRandomlyFromTheCache.

@Test
public void evictAnyWillInvalidateAnEntryRandomlyFromTheCache() throws Exception {
    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(100)).tagged(tags);
    // Arrange
    DeciderCache replayDeciderCache = new DeciderCache(50, scope);
    PollForDecisionTaskResponse decisionTask1 = HistoryUtils.generateDecisionTaskWithInitialHistory();
    PollForDecisionTaskResponse decisionTask2 = HistoryUtils.generateDecisionTaskWithInitialHistory();
    PollForDecisionTaskResponse decisionTask3 = HistoryUtils.generateDecisionTaskWithInitialHistory();
    // Act
    Decider decider = replayDeciderCache.getOrCreate(decisionTask1, () -> createFakeDecider(decisionTask1));
    replayDeciderCache.addToCache(decisionTask1, decider);
    decider = replayDeciderCache.getOrCreate(decisionTask2, () -> createFakeDecider(decisionTask2));
    replayDeciderCache.addToCache(decisionTask2, decider);
    decider = replayDeciderCache.getOrCreate(decisionTask3, () -> createFakeDecider(decisionTask3));
    replayDeciderCache.addToCache(decisionTask3, decider);
    assertEquals(3, replayDeciderCache.size());
    replayDeciderCache.evictAnyNotInProcessing(decisionTask3.workflowExecution.runId);
    // Assert
    assertEquals(2, replayDeciderCache.size());
    // Wait for reporter
    Thread.sleep(600);
    verify(reporter, atLeastOnce()).reportCounter(eq(MetricsType.STICKY_CACHE_TOTAL_FORCED_EVICTION), eq(tags), anyInt());
}
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 10 with Scope

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

the class StickyWorkerTest method whenStickyIsEnabledThenTheWorkflowIsCachedSignals.

@Test
public void whenStickyIsEnabledThenTheWorkflowIsCachedSignals() throws Exception {
    // Arrange
    String taskListName = "cachedStickyTest_Signal";
    StatsReporter reporter = mock(StatsReporter.class);
    Scope scope = new RootScopeBuilder().reporter(reporter).reportEvery(com.uber.m3.util.Duration.ofMillis(300));
    WorkerFactoryOptions factoryOptions = WorkerFactoryOptions.newBuilder().setDisableStickyExecution(false).build();
    TestEnvironmentWrapper wrapper = new TestEnvironmentWrapper(factoryOptions, scope);
    WorkerFactory factory = wrapper.getWorkerFactory();
    Worker worker = factory.newWorker(taskListName);
    worker.registerWorkflowImplementationTypes(GreetingSignalWorkflowImpl.class);
    factory.start();
    WorkflowOptions workflowOptions = new WorkflowOptions.Builder().setTaskList(taskListName).setExecutionStartToCloseTimeout(Duration.ofDays(30)).setTaskStartToCloseTimeout(Duration.ofSeconds(30)).build();
    GreetingSignalWorkflow workflow = wrapper.getWorkflowClient().newWorkflowStub(GreetingSignalWorkflow.class, workflowOptions);
    // Act
    WorkflowClient.start(workflow::getGreeting);
    Thread.sleep(300);
    workflow.waitForName("World");
    String greeting = workflow.getGreeting();
    assertEquals("Hello World!", greeting);
    // Assert
    DeciderCache cache = factory.getCache();
    assertNotNull(cache);
    assertEquals(1, cache.size());
    // Verify the workflow succeeded without having to recover from a failure
    Map<String, String> tags = new ImmutableMap.Builder<String, String>(2).put(MetricsTag.DOMAIN, DOMAIN).put(MetricsTag.TASK_LIST, STICKY_TASK_LIST_METRIC_TAG).build();
    Thread.sleep(600);
    verify(reporter, atLeastOnce()).reportCounter(eq(MetricsType.STICKY_CACHE_HIT), eq(tags), anyInt());
    verify(reporter, never()).reportCounter(eq(MetricsType.STICKY_CACHE_MISS), eq(tags), anyInt());
    // Finish Workflow
    wrapper.close();
}
Also used : RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) DeciderCache(com.uber.cadence.internal.replay.DeciderCache) StatsReporter(com.uber.m3.tally.StatsReporter) ImmutableMap(com.uber.m3.util.ImmutableMap) Scope(com.uber.m3.tally.Scope) NoopScope(com.uber.cadence.internal.metrics.NoopScope) WorkflowOptions(com.uber.cadence.client.WorkflowOptions)

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