diff --git a/apps/api/src/services/signoz_client.py b/apps/api/src/services/signoz_client.py index bf1107c3d..386bbde70 100644 --- a/apps/api/src/services/signoz_client.py +++ b/apps/api/src/services/signoz_client.py @@ -254,9 +254,7 @@ class SignOzClient: # ===================================================================== # 使用 signoz_traces.distributed_signoz_index_v3 表 # statusCode: 0=Unset, 1=Ok, 2=Error - # 計算 Unix 納秒時間戳 (ClickHouse DateTime64(9) 格式) - start_ns = int(start_time.timestamp() * 1_000_000_000) - end_ns = int(end_time.timestamp() * 1_000_000_000) + # 使用 INTERVAL 語法避免 Decimal overflow rps_query = f""" SELECT @@ -264,7 +262,7 @@ class SignOzClient: countIf(statusCode = 2) as error_count FROM signoz_traces.distributed_signoz_index_v3 WHERE - timestamp BETWEEN toDateTime64({start_ns}, 9) AND toDateTime64({end_ns}, 9) + timestamp > now() - INTERVAL {time_window_minutes} MINUTE AND serviceName LIKE '%{service_name}%' """ @@ -290,7 +288,7 @@ class SignOzClient: quantile(0.99)(durationNano / 1000000.0) as p99 FROM signoz_traces.distributed_signoz_index_v3 WHERE - timestamp BETWEEN toDateTime64({start_ns}, 9) AND toDateTime64({end_ns}, 9) + timestamp > now() - INTERVAL {time_window_minutes} MINUTE AND serviceName LIKE '%{service_name}%' """ @@ -305,14 +303,11 @@ class SignOzClient: # ===================================================================== # Query 3: Trend Analysis (對比前一時間窗) # ===================================================================== - prev_start_ns = int((start_time - timedelta(minutes=time_window_minutes)).timestamp() * 1_000_000_000) - prev_end_ns = start_ns - trend_query = f""" SELECT count() as prev_requests FROM signoz_traces.distributed_signoz_index_v3 WHERE - timestamp BETWEEN toDateTime64({prev_start_ns}, 9) AND toDateTime64({prev_end_ns}, 9) + timestamp BETWEEN now() - INTERVAL {time_window_minutes * 2} MINUTE AND now() - INTERVAL {time_window_minutes} MINUTE AND serviceName LIKE '%{service_name}%' """