Skip to content

Commit 47f7ecf

Browse files
aai95meiliang86
andauthored
Add missing metrics from go client (#379) (#518)
Co-authored-by: Liang Mei <[email protected]>
1 parent 0dbd1bc commit 47f7ecf

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

src/main/java/com/uber/cadence/internal/metrics/MetricsType.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public class MetricsType {
6767
CADENCE_METRICS_PREFIX + "decision-task-error";
6868
public static final String DECISION_TASK_COMPLETED_COUNTER =
6969
CADENCE_METRICS_PREFIX + "decision-task-completed";
70+
public static final String DECISION_TASK_FORCE_COMPLETED =
71+
CADENCE_METRICS_PREFIX + "decision-task-force-completed";
7072

7173
public static final String ACTIVITY_POLL_COUNTER = CADENCE_METRICS_PREFIX + "activity-poll-total";
7274
public static final String ACTIVITY_POLL_FAILED_COUNTER =
@@ -145,4 +147,6 @@ public class MetricsType {
145147
public static final String STICKY_CACHE_SIZE = CADENCE_METRICS_PREFIX + "sticky-cache-size";
146148
public static final String WORKFLOW_ACTIVE_THREAD_COUNT =
147149
CADENCE_METRICS_PREFIX + "workflow_active_thread_count";
150+
151+
public static final String NON_DETERMINISTIC_ERROR = CADENCE_METRICS_PREFIX + "non-deterministic-error";
148152
}

src/main/java/com/uber/cadence/internal/replay/DecisionsHelper.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@
5757
import com.uber.cadence.WorkflowExecutionStartedEventAttributes;
5858
import com.uber.cadence.WorkflowType;
5959
import com.uber.cadence.internal.common.WorkflowExecutionUtils;
60+
import com.uber.cadence.internal.metrics.MetricsTag;
61+
import com.uber.cadence.internal.metrics.MetricsType;
6062
import com.uber.cadence.internal.replay.HistoryHelper.DecisionEvents;
63+
import com.uber.cadence.internal.worker.SingleWorkerOptions;
6164
import com.uber.cadence.internal.worker.WorkflowExecutionException;
65+
import com.uber.m3.tally.Scope;
66+
import com.uber.m3.util.ImmutableMap;
6267
import java.util.ArrayList;
6368
import java.util.HashMap;
6469
import java.util.Iterator;
@@ -86,6 +91,7 @@ class DecisionsHelper {
8691
+ "change in the workflow definition.";
8792

8893
private final PollForDecisionTaskResponse task;
94+
private final SingleWorkerOptions options;
8995

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

108-
DecisionsHelper(PollForDecisionTaskResponse task) {
114+
DecisionsHelper(PollForDecisionTaskResponse task, SingleWorkerOptions options) {
109115
this.task = task;
116+
this.options = options;
110117
}
111118

112119
long getNextDecisionEventId() {
@@ -718,6 +725,10 @@ private boolean addMissingVersionMarker(
718725
private DecisionStateMachine getDecision(DecisionId decisionId) {
719726
DecisionStateMachine result = decisions.get(decisionId);
720727
if (result == null) {
728+
Scope metricsScope = options
729+
.getMetricsScope()
730+
.tagged(ImmutableMap.of(MetricsTag.WORKFLOW_TYPE, task.getWorkflowType().getName()));
731+
metricsScope.counter(MetricsType.NON_DETERMINISTIC_ERROR).inc(1);
721732
throw new NonDeterminisicWorkflowError(
722733
"Unknown " + decisionId + ". " + NON_DETERMINISTIC_MESSAGE);
723734
}

src/main/java/com/uber/cadence/internal/replay/ReplayDecider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,9 @@ private boolean decideImpl(PollForDecisionTaskResponse decisionTask, Functions.P
454454
// Reset state to before running the event loop
455455
decisionsHelper.handleDecisionTaskStartedEvent(decision);
456456
}
457-
457+
if (forceCreateNewDecisionTask) {
458+
metricsScope.counter(MetricsType.DECISION_TASK_FORCE_COMPLETED).inc(1);
459+
}
458460
return forceCreateNewDecisionTask;
459461
} catch (Error e) {
460462
if (this.workflow.getWorkflowImplementationOptions().getNonDeterministicWorkflowPolicy()

src/main/java/com/uber/cadence/internal/replay/ReplayDecisionTaskHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ private Decider createDecider(PollForDecisionTaskResponse decisionTask) throws E
276276
decisionTask.setHistory(getHistoryResponse.getHistory());
277277
decisionTask.setNextPageToken(getHistoryResponse.getNextPageToken());
278278
}
279-
DecisionsHelper decisionsHelper = new DecisionsHelper(decisionTask);
279+
DecisionsHelper decisionsHelper = new DecisionsHelper(decisionTask, options);
280280
ReplayWorkflow workflow = workflowFactory.getWorkflow(workflowType);
281281
return new ReplayDecider(
282282
service, domain, workflowType, workflow, decisionsHelper, options, laTaskPoller);

src/test/java/com/uber/cadence/internal/replay/ReplayDeciderCacheTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public WorkflowImplementationOptions getWorkflowImplementationOptions() {
306306
return new WorkflowImplementationOptions.Builder().build();
307307
}
308308
},
309-
new DecisionsHelper(response),
309+
new DecisionsHelper(response, new SingleWorkerOptions.Builder().build()),
310310
new SingleWorkerOptions.Builder().build(),
311311
(a, d) -> true);
312312
}

0 commit comments

Comments
 (0)