From 1720367c6b8923c63e9d7eb6074b959f17a2af81 Mon Sep 17 00:00:00 2001 From: Kaushik Basu Date: Wed, 26 Nov 2025 21:46:10 +0100 Subject: [PATCH 1/2] Fixed download speed alert query --- network_speed/grafana/terraform/main.tf | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/network_speed/grafana/terraform/main.tf b/network_speed/grafana/terraform/main.tf index 7fdb3d1..1b03694 100644 --- a/network_speed/grafana/terraform/main.tf +++ b/network_speed/grafana/terraform/main.tf @@ -159,7 +159,9 @@ resource "grafana_rule_group" "internet_speed_alerts" { }) } - # Query B: Threshold check + # Query B: Check if speed < threshold + # This reduces Query A to the last value and evaluates: is it < 63? + # Returns: 1 (true) if below threshold, 0 (false) if above data { ref_id = "B" @@ -171,21 +173,21 @@ resource "grafana_rule_group" "internet_speed_alerts" { datasource_uid = "__expr__" model = jsonencode({ - expression = "A" - reducer = "last" + expression = "A" # Input: Query A (the speed metric) + reducer = "last" # Take the most recent value refId = "B" - type = "reduce" + type = "threshold" # Evaluate a threshold condition conditions = [ { evaluator = { - params = [var.download_threshold] - type = "lt" + params = [var.download_threshold] # Threshold: 63 Mbps + type = "lt" # Condition: less than (<) } operator = { type = "and" } query = { - params = [] + params = ["A"] # Apply condition to Query A } reducer = { params = [] From 04dd9764bfade06fd8b0874961f2f415256fdfea Mon Sep 17 00:00:00 2001 From: Kaushik Basu Date: Wed, 26 Nov 2025 21:56:33 +0100 Subject: [PATCH 2/2] Addressed co-pilot review comment --- network_speed/grafana/terraform/main.tf | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/network_speed/grafana/terraform/main.tf b/network_speed/grafana/terraform/main.tf index 1b03694..ae9b560 100644 --- a/network_speed/grafana/terraform/main.tf +++ b/network_speed/grafana/terraform/main.tf @@ -159,8 +159,7 @@ resource "grafana_rule_group" "internet_speed_alerts" { }) } - # Query B: Check if speed < threshold - # This reduces Query A to the last value and evaluates: is it < 63? + # Query B: Evaluates if Query A's last value is below the threshold # Returns: 1 (true) if below threshold, 0 (false) if above data { ref_id = "B" @@ -173,21 +172,20 @@ resource "grafana_rule_group" "internet_speed_alerts" { datasource_uid = "__expr__" model = jsonencode({ - expression = "A" # Input: Query A (the speed metric) - reducer = "last" # Take the most recent value + expression = "A" refId = "B" - type = "threshold" # Evaluate a threshold condition + type = "threshold" conditions = [ { evaluator = { - params = [var.download_threshold] # Threshold: 63 Mbps - type = "lt" # Condition: less than (<) + params = [var.download_threshold] + type = "lt" } operator = { type = "and" } query = { - params = ["A"] # Apply condition to Query A + params = ["A"] } reducer = { params = []