From 905c9fb36a67171464f03fd9565f02db74708974 Mon Sep 17 00:00:00 2001 From: Zach Aysan Date: Mon, 29 Apr 2024 06:12:44 -0400 Subject: [PATCH] fix: Get current api usage InfluxDB query (#3846) --- api/app_analytics/influxdb_wrapper.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/api/app_analytics/influxdb_wrapper.py b/api/app_analytics/influxdb_wrapper.py index c8a1b8f565f3..05ea0218b6e1 100644 --- a/api/app_analytics/influxdb_wrapper.py +++ b/api/app_analytics/influxdb_wrapper.py @@ -341,6 +341,7 @@ def get_current_api_usage(organisation_id: int, date_range: str) -> int: ), drop_columns=("_start", "_stop", "_time"), extra='|> sum() \ + |> group() \ |> sort(columns: ["_value"], desc: true) ', ) @@ -349,10 +350,7 @@ def get_current_api_usage(organisation_id: int, date_range: str) -> int: if len(result.records) == 0: return 0 - # There should only be one matching result due to the - # sum part of the query. - assert len(result.records) == 1 - return result.records[0].get_value() + return sum(r.get_value() for r in result.records) return 0