From a7e487433a83f0dab18a482bd67f49c778655a89 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 21 Nov 2023 10:34:16 -0800 Subject: [PATCH] keep attempt end time instead of duration --- google/cloud/bigtable/data/_metrics/data_model.py | 4 ++-- google/cloud/bigtable/data/_metrics/handlers/opentelemetry.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/google/cloud/bigtable/data/_metrics/data_model.py b/google/cloud/bigtable/data/_metrics/data_model.py index c1243494f..475073a8f 100644 --- a/google/cloud/bigtable/data/_metrics/data_model.py +++ b/google/cloud/bigtable/data/_metrics/data_model.py @@ -60,7 +60,7 @@ class CompletedAttemptMetric: """ start_time: float - duration: float + end_time: float end_status: StatusCode first_response_latency: float | None = None gfe_latency: float | None = None @@ -209,7 +209,7 @@ def end_attempt_with_status(self, status: StatusCode | Exception) -> None: new_attempt = CompletedAttemptMetric( start_time=self.active_attempt.start_time, first_response_latency=self.active_attempt.first_response_latency, - duration=time.monotonic() - self.active_attempt.start_time, + end_time=time.monotonic(), end_status=self._exc_to_status(status) if isinstance(status, Exception) else status, diff --git a/google/cloud/bigtable/data/_metrics/handlers/opentelemetry.py b/google/cloud/bigtable/data/_metrics/handlers/opentelemetry.py index 87e967ba1..5b68c9ca2 100644 --- a/google/cloud/bigtable/data/_metrics/handlers/opentelemetry.py +++ b/google/cloud/bigtable/data/_metrics/handlers/opentelemetry.py @@ -120,7 +120,7 @@ def on_operation_complete(self, op: CompletedOperationMetric) -> None: # - connectivity_error_count labels["status"] = attempt.end_status.value - self.attempt_latency.record(attempt.duration, labels) + self.attempt_latency.record(attempt.end_time-attempt.start_time, labels) if ( op.op_type == OperationType.READ_ROWS and attempt.first_response_latency is not None