fix(observability): bind managed Prometheus datasource for AIO Grafana dashboard#674
Open
bindsi wants to merge 3 commits into
Open
fix(observability): bind managed Prometheus datasource for AIO Grafana dashboard#674bindsi wants to merge 3 commits into
bindsi wants to merge 3 commits into
Conversation
…a dashboard
The AIO sample dashboard is a Grafana export whose panels reference the
datasource via the ${DS_MANAGED_PROMETHEUS_INSTANCE} __inputs placeholder.
az grafana dashboard import only auto-binds that placeholder when a matching
Prometheus datasource is Grafana's default, which is not the case in Azure
Managed Grafana, so panels failed with 'Datasource
${DS_MANAGED_PROMETHEUS_INSTANCE} was not found'.
Resolve the managed Prometheus datasource uid and bind it (and drop __inputs)
before importing. Pass MONITOR_WORKSPACE_NAME from Terraform to identify the
datasource, and route the retry helper's diagnostics to stderr so they cannot
pollute the captured uid.
…port script Move pipeline operators to the start of continued lines to comply with the repo .editorconfig (binary_next_line=true), fixing the Shell Lint (shfmt) CI check.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(observability): bind managed Prometheus datasource for AIO Grafana dashboard
Description
The AIO sample dashboard imported by the observability component rendered every panel empty with the error Datasource ${DS_MANAGED_PROMETHEUS_INSTANCE} was not found.
The dashboard is pulled from the upstream source (Azure/azure-iot-operations
samples/grafana-dashboard/aio.sample.json), which is a Grafana export. Its panels and theclustertemplate variable reference the datasource through the__inputsplaceholder"uid": "${DS_MANAGED_PROMETHEUS_INSTANCE}".az grafana dashboard importonly auto-binds that placeholder when a matching Prometheus datasource is Grafana's default, which is never the case in Azure Managed Grafana where the managed Prometheus datasource comes from the Azure Monitor Workspace integration. The placeholder was therefore imported literally and no panel could resolve its datasource.This change resolves the managed Prometheus datasource at import time and binds every placeholder reference before importing.
Related Issue
Fixes #673
Type of Change
Implementation Details
The fix lives in the import script, with a small supporting change in Terraform.
Dashboard import script
src/000-cloud/020-observability/scripts/import-grafana-dashboards.sh was reworked so the remote AIO dashboard is bound to a real datasource before import:
az grafana data-source list ... -o json) and, viajq, selects theuidof the datasource whose name matchesMONITOR_WORKSPACE_NAME, falling back to the first datasource of typeprometheus, then to empty.DS_UIDthrough the existingretrywrapper.curl -fsSL, usesjq walk(...)to replace every object.uidequal to the${DS_MANAGED_PROMETHEUS_INSTANCE}placeholder with the resolved uid, deletes.__inputs, and imports the transformed local file. Temp files are created withmktemp -dand removed via anEXITtrap.retry()diagnostic messages to stderr so they cannot pollute theDS_UIDvalue captured through command substitution.Terraform provisioner
src/000-cloud/020-observability/terraform/main.tf passes MONITOR_WORKSPACE_NAME (
azurerm_monitor_workspace.monitor.name) into thelocal-execprovisioner environment so the script can select the correct datasource by name.Testing Performed
The
jqtransform was validated against the live upstream dashboard:__inputsremoved, zero remaining${DS_MANAGED_PROMETHEUS_INSTANCE}placeholders, and all 63 datasource references bound. The updated script was run against a deployed Azure Managed Grafana instance and the AIO sample dashboard imported successfully with panels bound to the managed Prometheus datasource.Validation Steps
GRAFANA_NAME,RESOURCE_GROUP_NAME, andMONITOR_WORKSPACE_NAME).cluster="$cluster"filters resolve.Checklist
terraform fmton all Terraform codeterraform validateon all Terraform codeaz bicep formaton all Bicep codeaz bicep buildto validate all Bicep codeSecurity Review
Both
DS_UIDandMONITOR_WORKSPACE_NAMEare passed tojqvia parameterized--argrather than string-interpolated into the program, avoiding injection. The${DS_MANAGED_PROMETHEUS_INSTANCE}literal sits inside single-quotedjqprograms, so it is not subject to shell expansion. The remote fetch usescurl -fsSLover HTTPS. No secrets are introduced or logged.Additional Notes
No Terraform resource changes beyond adding one environment variable to the existing
local-execprovisioner; the shell script carries the fix. The fix is resilient to the upstream 2510-release dashboard change (Azure/azure-iot-operations#80) that surfaced the issue.terraform fmt -checkandterraform validatewere run against the observability component and both passed. The broader lint checkbox is left unchecked pending CI running the full linter suite (tflint, shellcheck) against this branch.