Skip to content

Commit

Permalink
JVMCBC-1071: Don't allow negative values to be sent into the ValueRec…
Browse files Browse the repository at this point in the history
…order.

In the rare case where nanoTime goes backwards, we need to make sure that this
case is captured since the internal histogram doesn't like being sent negative
values.

Change-Id: Ie9d73b23246d5549f760db36cae56faaa55b1c85
Reviewed-on: https://review.couchbase.org/c/couchbase-jvm-clients/+/171579
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: Graham Pople <graham.pople@couchbase.com>
  • Loading branch information
daschl authored and Michael Nitschinger committed Mar 1, 2022
1 parent f262525 commit 19a360c
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ public RequestContext logicallyComplete() {
}

if (!(environment().meter() instanceof NoopMeter)) {
core().responseMetric(request).recordValue(logicalRequestLatency());
long latency = logicalRequestLatency();
if (latency > 0) {
core().responseMetric(request).recordValue(latency);
}
}

return this;
Expand Down Expand Up @@ -243,10 +246,11 @@ public long logicallyCompletedAt() {
* calls).
*/
public long logicalRequestLatency() {
if (logicallyCompletedAt == 0) {
long createdAt = request.createdAt();
if (logicallyCompletedAt == 0 || logicallyCompletedAt <= createdAt) {
return 0;
}
return logicallyCompletedAt - request.createdAt();
return logicallyCompletedAt - createdAt;
}

@Stability.Internal
Expand Down

0 comments on commit 19a360c

Please sign in to comment.