Skip to content

chore(ci): wait for Grafana Cloud readiness before dashboard provisioning#320

Merged
FSM1 merged 2 commits into
mainfrom
chore/ci-grafana-readiness-wait
Mar 22, 2026
Merged

chore(ci): wait for Grafana Cloud readiness before dashboard provisioning#320
FSM1 merged 2 commits into
mainfrom
chore/ci-grafana-readiness-wait

Conversation

@FSM1

@FSM1 FSM1 commented Mar 22, 2026

Copy link
Copy Markdown
Owner

Summary

  • Grafana Cloud free-tier instances sleep when idle and return 503 "Your instance is loading" on first access
  • Adds a readiness poll step (up to 5 min, 10s intervals) against /api/health before pushing the dashboard
  • Fixes consistently failing Provision Grafana Dashboard job in deploy-staging workflow

Test plan

  • Trigger a staging deploy and verify the readiness step waits then succeeds
  • Verify dashboard is provisioned after the wait completes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Improved deployment workflow: added a dashboard provisioning step that normalizes the target URL, waits for Grafana to become healthy with retries, and fails fast on authentication/permission or not-found errors to prevent faulty pushes.

…ning

Grafana Cloud free-tier instances sleep when idle and return 503
"Your instance is loading" when first accessed. Add a readiness poll
(up to 5 minutes) against /api/health before pushing the dashboard.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: ea465215ea30
@coderabbitai

coderabbitai Bot commented Mar 22, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 314780e2-9f53-45b8-bc62-856df5e06303

📥 Commits

Reviewing files that changed from the base of the PR and between 440cd51 and fa6ad3b.

📒 Files selected for processing (1)
  • .github/workflows/deploy-staging.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/deploy-staging.yml

Walkthrough

Added a GitHub Actions workflow step (provision-dashboard) that normalizes GRAFANA_URL and polls GET {GRAFANA_URL}/api/health with a Bearer GRAFANA_API_KEY, retrying up to 30 times at 10s intervals; succeeds on HTTP 200, fails immediately on 401/403/404, otherwise continues polling.

Changes

Cohort / File(s) Summary
Grafana Cloud readiness & provisioning
.github/workflows/deploy-staging.yml
Inserted a provision-dashboard step before "Push dashboard to Grafana Cloud": normalizes GRAFANA_URL, performs health polling against GET /api/health with Authorization: Bearer $GRAFANA_API_KEY, retries up to 30 times with 10s sleeps, treats 200 as success, 401/403/404 as immediate failures, and errors out after timeout.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a readiness check for Grafana Cloud before dashboard provisioning in the CI workflow.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/ci-grafana-readiness-wait

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the reliability of the staging deployment workflow by adding a Grafana Cloud readiness check to handle free-tier “sleep/warm-up” behavior before attempting dashboard provisioning.

Changes:

  • Adds a polling step (up to 5 minutes) that waits for Grafana Cloud to return HTTP 200 on /api/health.
  • Ensures the “Push dashboard to Grafana Cloud” step runs only after Grafana is responsive.

Comment thread .github/workflows/deploy-staging.yml
Comment thread .github/workflows/deploy-staging.yml

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
.github/workflows/deploy-staging.yml (1)

514-516: Fail fast on missing Grafana env vars.

This step should validate required env vars up front; otherwise it retries for minutes on a configuration error.

💡 Proposed fix (guard clauses)
           set -euo pipefail
+          : "${GRAFANA_URL:?GRAFANA_URL is required}"
+          : "${GRAFANA_API_KEY:?GRAFANA_API_KEY is required}"
           GRAFANA_URL="${GRAFANA_URL%/}"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/deploy-staging.yml around lines 514 - 516, Add upfront
guard clauses after "set -euo pipefail" to validate required Grafana environment
variables (e.g. GRAFANA_URL and GRAFANA_API_KEY) before entering retry logic;
check that GRAFANA_URL is non-empty (after the existing
GRAFANA_URL="${GRAFANA_URL%/}" normalization) and that GRAFANA_API_KEY (or any
other required var) is set, and if any are missing emit a clear error to stderr
and exit non-zero immediately (avoiding long MAX_ATTEMPTS retries). Ensure
messages reference the variable names so the failure is actionable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/deploy-staging.yml:
- Around line 518-531: The retry loop uses a fixed MAX_ATTEMPTS which can exceed
a 5-minute wall-clock limit because each curl has its own timeout and there's
sleep; change the loop to enforce a deadline-based timeout instead: capture a
start time (or compute a deadline = now + 300), replace the for ((i=1...)) loop
with a loop that checks elapsed time against 300 seconds (or compares now to
deadline) and increments attempt counter only for logging, run the curl + sleep
until either HTTP 200 or elapsed >= 300, and update the final error/log to
report that Grafana did not become ready after the 5-minute deadline (use the
same variables like HTTP_CODE, INTERVAL, MAX_ATTEMPTS only for logging as
needed).

---

Nitpick comments:
In @.github/workflows/deploy-staging.yml:
- Around line 514-516: Add upfront guard clauses after "set -euo pipefail" to
validate required Grafana environment variables (e.g. GRAFANA_URL and
GRAFANA_API_KEY) before entering retry logic; check that GRAFANA_URL is
non-empty (after the existing GRAFANA_URL="${GRAFANA_URL%/}" normalization) and
that GRAFANA_API_KEY (or any other required var) is set, and if any are missing
emit a clear error to stderr and exit non-zero immediately (avoiding long
MAX_ATTEMPTS retries). Ensure messages reference the variable names so the
failure is actionable.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6fd139d9-1814-4244-a2c0-53f8fd13ae33

📥 Commits

Reviewing files that changed from the base of the PR and between e35f6ba and 440cd51.

📒 Files selected for processing (1)
  • .github/workflows/deploy-staging.yml

Comment thread .github/workflows/deploy-staging.yml
Address PR review feedback:
- Validate GRAFANA_URL and GRAFANA_API_KEY are set before polling
- Fail immediately on 401/403/404 instead of waiting full 5 minutes

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: 7195756b0244
@FSM1 FSM1 merged commit 49886f6 into main Mar 22, 2026
24 checks passed
@FSM1 FSM1 deleted the chore/ci-grafana-readiness-wait branch March 22, 2026 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants