Skip to content

Commit

Permalink
Add missing metrics from go client (#379) (#518)
Browse files Browse the repository at this point in the history
Co-authored-by: Liang Mei <meiliang86@gmail.com>
  • Loading branch information
aai95 and meiliang86 committed Sep 18, 2020
1 parent 0dbd1bc commit 47f7ecf
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public class MetricsType {
CADENCE_METRICS_PREFIX + "decision-task-error";
public static final String DECISION_TASK_COMPLETED_COUNTER =
CADENCE_METRICS_PREFIX + "decision-task-completed";
public static final String DECISION_TASK_FORCE_COMPLETED =
CADENCE_METRICS_PREFIX + "decision-task-force-completed";

public static final String ACTIVITY_POLL_COUNTER = CADENCE_METRICS_PREFIX + "activity-poll-total";
public static final String ACTIVITY_POLL_FAILED_COUNTER =
Expand Down Expand Up @@ -145,4 +147,6 @@ public class MetricsType {
public static final String STICKY_CACHE_SIZE = CADENCE_METRICS_PREFIX + "sticky-cache-size";
public static final String WORKFLOW_ACTIVE_THREAD_COUNT =
CADENCE_METRICS_PREFIX + "workflow_active_thread_count";

public static final String NON_DETERMINISTIC_ERROR = CADENCE_METRICS_PREFIX + "non-deterministic-error";
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@
import com.uber.cadence.WorkflowExecutionStartedEventAttributes;
import com.uber.cadence.WorkflowType;
import com.uber.cadence.internal.common.WorkflowExecutionUtils;
import com.uber.cadence.internal.metrics.MetricsTag;
import com.uber.cadence.internal.metrics.MetricsType;
import com.uber.cadence.internal.replay.HistoryHelper.DecisionEvents;
import com.uber.cadence.internal.worker.SingleWorkerOptions;
import com.uber.cadence.internal.worker.WorkflowExecutionException;
import com.uber.m3.tally.Scope;
import com.uber.m3.util.ImmutableMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -86,6 +91,7 @@ class DecisionsHelper {
+ "change in the workflow definition.";

private final PollForDecisionTaskResponse task;
private final SingleWorkerOptions options;

/**
* When workflow task completes the decisions are converted to events that follow the decision
Expand All @@ -105,8 +111,9 @@ class DecisionsHelper {
// TODO: removal of completed activities
private final Map<String, Long> activityIdToScheduledEventId = new HashMap<>();

DecisionsHelper(PollForDecisionTaskResponse task) {
DecisionsHelper(PollForDecisionTaskResponse task, SingleWorkerOptions options) {
this.task = task;
this.options = options;
}

long getNextDecisionEventId() {
Expand Down Expand Up @@ -718,6 +725,10 @@ private boolean addMissingVersionMarker(
private DecisionStateMachine getDecision(DecisionId decisionId) {
DecisionStateMachine result = decisions.get(decisionId);
if (result == null) {
Scope metricsScope = options
.getMetricsScope()
.tagged(ImmutableMap.of(MetricsTag.WORKFLOW_TYPE, task.getWorkflowType().getName()));
metricsScope.counter(MetricsType.NON_DETERMINISTIC_ERROR).inc(1);
throw new NonDeterminisicWorkflowError(
"Unknown " + decisionId + ". " + NON_DETERMINISTIC_MESSAGE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,9 @@ private boolean decideImpl(PollForDecisionTaskResponse decisionTask, Functions.P
// Reset state to before running the event loop
decisionsHelper.handleDecisionTaskStartedEvent(decision);
}

if (forceCreateNewDecisionTask) {
metricsScope.counter(MetricsType.DECISION_TASK_FORCE_COMPLETED).inc(1);
}
return forceCreateNewDecisionTask;
} catch (Error e) {
if (this.workflow.getWorkflowImplementationOptions().getNonDeterministicWorkflowPolicy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private Decider createDecider(PollForDecisionTaskResponse decisionTask) throws E
decisionTask.setHistory(getHistoryResponse.getHistory());
decisionTask.setNextPageToken(getHistoryResponse.getNextPageToken());
}
DecisionsHelper decisionsHelper = new DecisionsHelper(decisionTask);
DecisionsHelper decisionsHelper = new DecisionsHelper(decisionTask, options);
ReplayWorkflow workflow = workflowFactory.getWorkflow(workflowType);
return new ReplayDecider(
service, domain, workflowType, workflow, decisionsHelper, options, laTaskPoller);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public WorkflowImplementationOptions getWorkflowImplementationOptions() {
return new WorkflowImplementationOptions.Builder().build();
}
},
new DecisionsHelper(response),
new DecisionsHelper(response, new SingleWorkerOptions.Builder().build()),
new SingleWorkerOptions.Builder().build(),
(a, d) -> true);
}
Expand Down

0 comments on commit 47f7ecf

Please sign in to comment.