Skip to content

Commit 8778ce7

Browse files
meiliang86mfateev
authored andcommitted
Correctly calculate workflow e2e latency (#262)
1 parent 8846a57 commit 8778ce7

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ReplayDecider implements Decider {
7979

8080
private final Scope metricsScope;
8181

82-
private long wfStartTime = -1;
82+
private final long wfStartTimeNanos;
8383

8484
private final WorkflowExecutionStartedEventAttributes startedEvent;
8585

@@ -102,6 +102,7 @@ class ReplayDecider implements Decider {
102102
throw new IllegalArgumentException(
103103
"First event in the history is not WorkflowExecutionStarted");
104104
}
105+
wfStartTimeNanos = decisionTask.getHistory().getEvents().get(0).getTimestamp();
105106

106107
context =
107108
new DecisionContextImpl(
@@ -288,12 +289,10 @@ private void completeWorkflow() {
288289
}
289290
}
290291

291-
if (wfStartTime != -1) {
292-
long nanoTime =
293-
TimeUnit.NANOSECONDS.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
294-
com.uber.m3.util.Duration d = com.uber.m3.util.Duration.ofNanos(nanoTime - wfStartTime);
295-
metricsScope.timer(MetricsType.WORKFLOW_E2E_LATENCY).record(d);
296-
}
292+
long nanoTime =
293+
TimeUnit.NANOSECONDS.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
294+
com.uber.m3.util.Duration d = com.uber.m3.util.Duration.ofNanos(nanoTime - wfStartTimeNanos);
295+
metricsScope.timer(MetricsType.WORKFLOW_E2E_LATENCY).record(d);
297296
}
298297

299298
private void updateTimers() {

0 commit comments

Comments
 (0)