-
-
Notifications
You must be signed in to change notification settings - Fork 331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix grafana dashboard lint script #5221
Conversation
- Nested dashboard panels are now recursively checked - Panel datasource must point to the datasource variable
@dapplion do you know why it is required to hard code a value here? it seems like it does not matter what value is used here as long as it is not lodestar/scripts/lint-grafana-dashboards.mjs Line 171 in 466c754
|
diff of lint script is hard to reason about because logic to assert panels was extracted into function to be able to call it recursively here is a better diff to understand changes done to diff --git a/scripts/lint-grafana-dashboards.mjs b/scripts/lint-grafana-dashboards.mjs
index 4082300d53..754045bc05 100755
--- a/scripts/lint-grafana-dashboards.mjs
+++ b/scripts/lint-grafana-dashboards.mjs
@@ -214,17 +214,12 @@ function assertTemplatingListItemContent(json, varName, item) {
*/
function assertPanels(panels) {
for (const panel of panels) {
+ // Panel datasource must point to the datasource variable
+ if (panel.datasource) {
+ panel.datasource.type = "prometheus";
+ panel.datasource.uid = `\${${variableNameDatasource}}`;
+ }
if (panel.targets) {
for (const target of panel.targets) {
// All panels must point to the datasource variable
if (target.datasource) {
target.datasource.type = "prometheus";
+ target.datasource.uid = `\${${variableNameDatasource}}`;
- target.datasource.uid = "${DS_PROMETHEUS}";
}
// Disable exemplar
@@ -238,9 +233,5 @@ function assertPanels(panels) {
}
}
}
+ // Recursively check nested panels
+ if (panel.panels) {
+ assertPanels(panel.panels);
+ }
}
} |
other interesting approach as mentioned in grafana/grafana#10786 (comment), recommends to replace all uids with null-string ( Other repositories using lodestar dashboards + auto-provisioning are replacing Based on my observations, we could support auto-provisioning without workarounds if we remove the prometheus variable altogether or remove uid references as mentioned above. However, both of those approaches are not ideal as it would not longer be possible to specific which prometheus datasource to use in case there are multiple. |
Performance Report✔️ no performance regression detected Full benchmark results
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the thorough explanation
🎉 This PR is included in v1.6.0 🎉 |
Motivation
Dashboard linter script was not catching some references to internal prometheus uids, see #5210 (comment).
Description
scripts/validate-grafana-dashboards.sh
Further observations
There are two observations unrelated to the changes in this PR which I am not sure are an issue or not
DS_PROMETHEUS
variable is not referenced by any variable or dashboard, this happens for all dashboards where we haveDS_PROMETHEUS
in__inputs
, I think this happens though because on import it will replaces the variable with the acutal uid, in my case this seems to bePBFA97CFB590B2093
and if I exported without sharing externally"uid": "${DS_PROMETHEUS}"
is replaced by"uid": "PBFA97CFB590B2093"
Export for sharing externally
there will always be a diff even if same grafana version is used, I am not sure why this replacements happens...it should not set some internal uid here. I guess just have to run./scripts/validate-grafana-dashboards.sh
locally to fix this before commiting