Skip to content

Commit 352f3d9

Browse files
author
Peng Zhou
committed
add retry for the Loki Grafana query
1 parent a20112d commit 352f3d9

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

test/e2e/2_marklogic_cluster_test.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,28 @@ func TestMarklogicCluster(t *testing.T) {
308308
}
309309
queryUrl := fmt.Sprintf("%s/api/ds/query?ds_type=loki", grafanaURL)
310310
curlCommand = fmt.Sprintf(`curl -X POST %s -u %s:%s -H "Content-Type: application/json" -d '%s'`, queryUrl, grafanaAdminUser, grafanaAdminPassword, payloadBytes)
311-
output, err = utils.ExecCmdInPod(grafanaPodName, "grafana", "grafana", curlCommand)
312-
if err != nil {
313-
t.Fatalf("Failed to execute kubectl command in grafana pod: %v", err)
314-
}
315-
t.Logf("Query datasource response: %s", output)
316-
// Verify MarkLogic logs in Grafana using Loki and Fluent Bit
317-
if !(strings.Contains(string(output), "Starting MarkLogic Server")) {
318-
t.Fatal("Failed to Query datasource")
311+
maxRetries := 5
312+
for attempt := 1; attempt <= maxRetries; attempt++ {
313+
t.Logf("Attempt %d to query datasource", attempt)
314+
output, err = utils.ExecCmdInPod(grafanaPodName, "grafana", "grafana", curlCommand)
315+
if err != nil {
316+
t.Logf("Attempt %d/%d Failed to execute kubectl command in grafana pod: %v", attempt, 5, err)
317+
if attempt == maxRetries {
318+
t.Fatalf("failed to execute kubectl command after %d attempts: %v", maxRetries, err)
319+
}
320+
// Exponential backoff: 1s, 2s, 4s, 8s, 16s
321+
time.Sleep(time.Duration(1<<(attempt-1)) * time.Second)
322+
}
323+
t.Logf("Query datasource response: %s", output)
324+
// Verify MarkLogic logs in Grafana using Loki and Fluent Bit
325+
if strings.Contains(string(output), "Starting MarkLogic Server") {
326+
t.Logf("Successfully found MarkLogic logs on attempt %d", attempt)
327+
} else if attempt == maxRetries {
328+
t.Fatalf("Failed to find MarkLogic logs in Grafana after %d attempts", maxRetries)
329+
} else {
330+
t.Logf("MarkLogic logs not found, retrying...")
331+
time.Sleep(time.Duration(1<<(attempt-1)) * time.Second) // Exponential backoff
332+
}
319333
}
320334

321335
curlCommand = fmt.Sprintf(`curl -u %s:%s %s/api/dashboards/uid/%s`, grafanaAdminUser, grafanaAdminPassword, grafanaURL, dashboardUID)

0 commit comments

Comments
 (0)