You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: scripts/ci/check_canary_budgets.py
+85-2Lines changed: 85 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -26,6 +26,14 @@ class BudgetResult:
26
26
regression: Optional[float] =None
27
27
28
28
defto_line(self) ->str:
29
+
"""
30
+
Format the BudgetResult as a one-line status string.
31
+
32
+
The string contains a status token (`OK` or `FAIL`), the budget name, the current value with unit, an optional previous value, and the threshold with unit and optional regression percentage. Numeric values are formatted with fixed decimal places (current and threshold to four decimals, regression as a percentage with two decimals).
33
+
34
+
Returns:
35
+
A single-line human-readable status string, e.g. "[OK] p95-latency: current=123.4567 ms, previous=100.0000 ms (threshold=3000.0000 ms, regression=23.45%)"
Evaluate a named budget by comparing the current Prometheus value to a baseline and determining threshold and regression compliance.
113
+
114
+
Parameters:
115
+
name (str): Logical name for the budget result.
116
+
base_url (str): Prometheus base URL used to execute the query.
117
+
query (str): Prometheus instant query expression to evaluate.
118
+
unit_scale (float): Multiplier applied to raw Prometheus values to convert units (e.g., seconds to milliseconds).
119
+
threshold (float): Maximum acceptable current value for the budget to pass.
120
+
regression_tolerance (float): Maximum allowed relative increase ((current - previous) / previous) for the budget to pass.
121
+
baseline_offset_seconds (float): Seconds to subtract from the current timestamp to obtain the baseline evaluation time.
122
+
unit_label (str): Human-readable unit suffix included in the returned BudgetResult (e.g., " ms", " rate").
123
+
124
+
Returns:
125
+
BudgetResult: Result containing the budget `name`, scaled `current` and `previous` values, `threshold`, `unit`, boolean `passed` indicating both threshold and regression compliance, and numeric `regression` (relative change) or `None` when previous value is zero.
Evaluate Tempo trace durations and compare the maximum observed duration against a provided duration budget.
180
+
181
+
Parameters:
182
+
base_url (str): Base URL of the Tempo API.
183
+
query (str): Tempo search query payload as a JSON string.
184
+
duration_budget_ms (float): Allowed maximum trace duration in milliseconds.
185
+
186
+
Returns:
187
+
BudgetResult: Result with name "tempo-trace-duration", `current` set to the maximum `durationMs` observed among returned traces, `previous` set to None, `threshold` equal to `duration_budget_ms`, `unit` set to " ms", and `passed` true if `current` is less than or equal to `threshold`.
188
+
189
+
Raises:
190
+
SystemExit: If the Tempo response contains no traces or no trace durations.
Validate configured canary budgets by querying Prometheus (and optionally Tempo) and return an exit code.
215
+
216
+
Reads environment variables for Prometheus and Tempo configuration and budget thresholds, evaluates latency and error budgets (and optional Tempo trace-duration budget), prints a one-line summary for each budget, and returns an exit code indicating overall status.
217
+
218
+
Returns:
219
+
exit_code (int): 0 if Prometheus configuration is missing (validation skipped) or if all budgets pass; 1 if any budget failed.
0 commit comments