From 4d06fba2a4bcafee86751a6357093c5df95446ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Murat=20Erg=C3=BCl?= <56608579+mrtergl@users.noreply.github.com> Date: Fri, 12 Jan 2024 17:33:05 +0300 Subject: [PATCH] Fun/Consumed Budget Ratio metric (#413) * Add: *Consumed Budget Ratio metric added to report * Add: *Consumed Budget Ratio metric added to report * Add: *Consumed Budget Ratio metric added to report * Add: Division by zero fixed * Change made in setup.cfg for an issue related pip version vulnerability scanned by safety * Change made in setup.cfg for an issue related pip version vulnerability scanned by safety * Change made in setup.cfg for an issue related pip version vulnerability scanned by safety * Rollback to pip 23.2 * Safety version setted to >=2.3.5 * consumed_budget_ratio renamed to error_budget_consumed_ratio --------- Co-authored-by: Laurent Vaylet --- slo_generator/exporters/bigquery.py | 5 +++++ slo_generator/report.py | 4 ++++ tests/unit/fixtures/slo_report_v2.json | 1 + 3 files changed, 10 insertions(+) diff --git a/slo_generator/exporters/bigquery.py b/slo_generator/exporters/bigquery.py index 1ea573f0..97232e63 100644 --- a/slo_generator/exporters/bigquery.py +++ b/slo_generator/exporters/bigquery.py @@ -276,6 +276,11 @@ def _format(errors): "type": "FLOAT", "mode": "NULLABLE", }, + { + "name": "error_budget_consumed_ratio", + "type": "FLOAT", + "mode": "NULLABLE", + }, { "name": "timestamp_human", "type": "TIMESTAMP", diff --git a/slo_generator/report.py b/slo_generator/report.py index 2959e4ba..d1305933 100644 --- a/slo_generator/report.py +++ b/slo_generator/report.py @@ -26,6 +26,7 @@ LOGGER = logging.getLogger(__name__) +# pylint: disable=too-many-arguments,too-many-locals @dataclass(init=False) class SLOReport: """SLO report dataclass. Compute an SLO report out of an SLO config and an @@ -60,6 +61,7 @@ class SLOReport: error_budget_minutes: float error_budget_remaining_minutes: float error_minutes: float + error_budget_consumed_ratio: float # Data validation valid: bool @@ -147,6 +149,7 @@ def build(self, step, data): eb_remaining_minutes = self.window * gap / 60 eb_target_minutes = self.window * eb_target / 60 eb_minutes = self.window * eb_value / 60 + eb_ratio = eb_value * 100 / eb_target if eb_target > 0 else 0 if eb_target == 0: eb_burn_rate = 0 else: @@ -178,6 +181,7 @@ def build(self, step, data): error_budget_remaining_minutes=eb_remaining_minutes, error_budget_minutes=eb_target_minutes, error_minutes=eb_minutes, + error_budget_consumed_ratio=eb_ratio, alert=alert, consequence_message=consequence_message, ) diff --git a/tests/unit/fixtures/slo_report_v2.json b/tests/unit/fixtures/slo_report_v2.json index 3a7fa22b..c39c4bde 100644 --- a/tests/unit/fixtures/slo_report_v2.json +++ b/tests/unit/fixtures/slo_report_v2.json @@ -16,6 +16,7 @@ "error_budget_remaining_minutes": -288, "error_budget_target": 0.09999999999999998, "error_minutes": "360.0", + "error_budget_consumed_ratio": 19.9999999999999, "events_count": 7112, "gap": -0.4, "goal": 0.9,