This is an automated email from the ASF dual-hosted git repository.

Amar3tto pushed a commit to branch fix-prober-community-metrics
in repository https://gitbox.apache.org/repos/asf/beam.git

commit 711b8149c49043c954ae347bdb2f49865deb22d0
Author: Vitaly Terentyev <[email protected]>
AuthorDate: Wed Oct 21 20:15:01 2026 +0400

    Update legacy prober test
---
 .../metrics/src/test/groovy/ProberTests.groovy     | 92 ++++++++++++++++++++--
 1 file changed, 85 insertions(+), 7 deletions(-)

diff --git a/.test-infra/metrics/src/test/groovy/ProberTests.groovy 
b/.test-infra/metrics/src/test/groovy/ProberTests.groovy
index ff7fe502da2..38d2c4176f5 100644
--- a/.test-infra/metrics/src/test/groovy/ProberTests.groovy
+++ b/.test-infra/metrics/src/test/groovy/ProberTests.groovy
@@ -18,8 +18,8 @@
 package org.apache.beam.testinfra.metrics
 
 import org.junit.Test
+import groovy.json.JsonOutput
 import groovy.json.JsonSlurper
-import static groovy.test.GroovyAssert.shouldFail
 
 /**
  * Prober tests which performs health checks on deployed infrastructure for
@@ -40,12 +40,90 @@ class ProberTests {
   }
 
   @Test
-  void CheckGrafanaStalenessAlerts() {
-    def alertsJson = 
"${grafanaEndpoint}/api/alerts?dashboardQuery=Source%20Data%20Freshness".toURL().text
-    def alerts = new JsonSlurper().parseText(alertsJson)
-    assert alerts.size() > 0
-    alerts.each { alert ->
-      assert alert.state == 'ok' : "Input data is stale! ${alert}\n   See: 
${grafanaEndpoint}/d/data-freshness"
+  void CheckGrafanaDataFreshness() {
+    def query = '''
+    WITH sources AS (
+      SELECT
+        'Jenkins' AS source,
+        MAX(build_timestamp + make_interval(secs := timing_executingtimemillis 
/ 1000.0)) AS last_sync
+      FROM jenkins_builds
+
+      UNION ALL
+
+      SELECT
+        'GitHub Issues' AS source,
+        timestamp AS last_sync
+      FROM gh_sync_metadata
+      WHERE name = 'gh_issue_sync'
+
+      UNION ALL
+
+      SELECT
+        'GitHub Pull Requests' AS source,
+        timestamp AS last_sync
+      FROM gh_sync_metadata
+      WHERE name = 'gh_pr_sync'
+    )
+    SELECT
+      COUNT(*) AS source_count,
+      COUNT(last_sync) AS synced_source_count,
+      MAX(EXTRACT(EPOCH FROM age(current_timestamp, last_sync)) / 60)
+        AS max_staleness_minutes
+    FROM sources
+  '''
+
+    def requestBody = [
+      queries: [[
+                  refId: 'A',
+                  datasource: [
+                    uid: 'beampsql',
+                    type: 'grafana-postgresql-datasource'
+                  ],
+                  editorMode: 'code',
+                  format: 'table',
+                  rawQuery: true,
+                  rawSql: query
+                ]],
+      from: 'now-5m',
+      to: 'now'
+    ]
+
+    def connection = new 
URL("${grafanaEndpoint}/api/ds/query").openConnection()
+    connection.requestMethod = 'POST'
+    connection.doOutput = true
+    connection.setRequestProperty('Content-Type', 'application/json')
+
+    connection.outputStream.withWriter('UTF-8') {
+      it << JsonOutput.toJson(requestBody)
+    }
+
+    assert connection.responseCode == 200 :
+      "Grafana datasource query failed with HTTP ${connection.responseCode}"
+
+    def response = new JsonSlurper().parse(connection.inputStream)
+    def frame = response.results.A.frames[0]
+
+    def fieldNames = frame.schema.fields.collect { it.name }
+
+    def value = { String fieldName ->
+      def index = fieldNames.indexOf(fieldName)
+      assert index >= 0 : "Missing field '${fieldName}' in Grafana response"
+      frame.data.values[index][0]
     }
+
+    def sourceCount = value('source_count')
+    def syncedSourceCount = value('synced_source_count')
+    def maxStalenessMinutes = value('max_staleness_minutes')
+
+    assert sourceCount == 3 :
+      "Expected 3 metrics sources, got ${sourceCount}"
+
+    assert syncedSourceCount == 3 :
+      "One or more metrics sources have no synchronization timestamp"
+
+    assert maxStalenessMinutes != null
+    assert maxStalenessMinutes <= 480 :
+      "Input data is stale: ${maxStalenessMinutes} minutes\n" +
+        "See: ${grafanaEndpoint}/d/data-freshness"
   }
 }

Reply via email to