Skip to content

Commit f87bae2

Browse files
authored
Fix ACTIVITY_E2E_LATENCY metrics (#537)
1 parent 0b1555c commit f87bae2

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
}
66

77
plugins {
8-
id 'net.minecrell.licenser' version '0.4.1'
8+
id "com.github.hierynomus.license" version"0.15.0"
99
id 'com.github.sherter.google-java-format' version '0.8'
1010
id 'net.ltgt.errorprone' version '1.1.1'
1111
id 'java-library'
@@ -66,6 +66,7 @@ dependencies {
6666

6767
license {
6868
header rootProject.file('license-header.txt')
69+
skipExistingHeaders true
6970
exclude 'com/uber/cadence/*.java' // generated code
7071
}
7172

@@ -212,7 +213,7 @@ task registerDomain(type:JavaExec) {
212213

213214
test {
214215
dependsOn 'registerDomain'
215-
dependsOn 'checkLicenseMain'
216+
dependsOn 'licenseMain'
216217
testLogging {
217218
events 'passed', 'skipped', 'failed'
218219
exceptionFormat 'full'

src/main/java/com/uber/cadence/internal/common/Retryer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2+
* Modifications Copyright (c) 2017-2020 Uber Technologies Inc.
3+
* Portions of the Software are attributed to Copyright (c) 2020 Temporal Technologies Inc.
24
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
35
*
4-
* Modifications copyright (C) 2017 Uber Technologies, Inc.
5-
*
66
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
77
* use this file except in compliance with the License. A copy of the License is
88
* located at
@@ -22,6 +22,7 @@
2222
import com.uber.cadence.*;
2323
import com.uber.cadence.common.RetryOptions;
2424
import java.time.Duration;
25+
import java.util.concurrent.CancellationException;
2526
import java.util.concurrent.CompletableFuture;
2627
import java.util.concurrent.CompletionException;
2728
import java.util.function.BiFunction;
@@ -124,7 +125,7 @@ public static <R, T extends Throwable> R retryWithResult(
124125
return result;
125126
} catch (InterruptedException e) {
126127
Thread.currentThread().interrupt();
127-
return null;
128+
throw new CancellationException();
128129
} catch (Exception e) {
129130
throttler.failure();
130131
if (options.getDoNotRetry() != null) {

src/main/java/com/uber/cadence/internal/testservice/StateMachines.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2+
* Modifications Copyright (c) 2017-2020 Uber Technologies Inc.
3+
* Portions of the Software are attributed to Copyright (c) 2020 Temporal Technologies Inc.
24
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
35
*
4-
* Modifications copyright (C) 2017 Uber Technologies, Inc.
5-
*
66
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
77
* use this file except in compliance with the License. A copy of the License is
88
* located at
@@ -743,6 +743,7 @@ private static void scheduleActivityTask(
743743
.setScheduleToCloseTimeoutSeconds(scheduleToCloseTimeoutSeconds)
744744
.setStartToCloseTimeoutSeconds(d.getStartToCloseTimeoutSeconds())
745745
.setScheduledTimestamp(ctx.currentTimeInNanoseconds())
746+
.setScheduledTimestampOfThisAttempt(ctx.currentTimeInNanoseconds())
746747
.setHeader(d.getHeader())
747748
.setAttempt(0);
748749

@@ -1057,11 +1058,13 @@ private static boolean attemptActivityRetry(
10571058
data.nextBackoffIntervalSeconds =
10581059
data.retryState.getBackoffIntervalInSeconds(errorReason, data.store.currentTimeMillis());
10591060
if (data.nextBackoffIntervalSeconds > 0) {
1060-
data.activityTask.getTask().setHeartbeatDetails(data.heartbeatDetails);
1061+
PollForActivityTaskResponse task = data.activityTask.getTask();
1062+
task.setHeartbeatDetails(data.heartbeatDetails);
10611063
ctx.onCommit(
10621064
(historySize) -> {
10631065
data.retryState = nextAttempt;
1064-
data.activityTask.getTask().setAttempt(nextAttempt.getAttempt());
1066+
task.setAttempt(nextAttempt.getAttempt());
1067+
task.setScheduledTimestampOfThisAttempt(ctx.currentTimeInNanoseconds());
10651068
});
10661069
return true;
10671070
} else {

src/main/java/com/uber/cadence/internal/worker/ActivityWorker.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2+
* Modifications Copyright (c) 2017-2020 Uber Technologies Inc.
3+
* Portions of the Software are attributed to Copyright (c) 2020 Temporal Technologies Inc.
24
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
35
*
4-
* Modifications copyright (C) 2017 Uber Technologies, Inc.
5-
*
66
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
77
* use this file except in compliance with the License. A copy of the License is
88
* located at
@@ -184,10 +184,10 @@ public void handle(PollForActivityTaskResponse task) throws Exception {
184184
sendReply(task, response, metricsScope);
185185
sw.stop();
186186

187-
metricsScope
188-
.timer(MetricsType.ACTIVITY_E2E_LATENCY)
189-
.record(
190-
Duration.ofNanos(System.nanoTime() - task.getScheduledTimestampOfThisAttempt()));
187+
long nanoTime =
188+
TimeUnit.NANOSECONDS.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
189+
Duration duration = Duration.ofNanos(nanoTime - task.getScheduledTimestampOfThisAttempt());
190+
metricsScope.timer(MetricsType.ACTIVITY_E2E_LATENCY).record(duration);
191191

192192
} catch (CancellationException e) {
193193
RespondActivityTaskCanceledRequest cancelledRequest =

0 commit comments

Comments
 (0)