Skip to content
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

expose annotations to linter #192

Merged
merged 1 commit into from
Sep 25, 2024
Merged

Conversation

diurnalist
Copy link
Contributor

these are structured similarly to the 'templating' field, but in general do not reliably have a 'type' field exposed.

use-case for this is catching when datasources are defined in annotations but they're not derived from dashboard inputs.

these are structured similarly to the 'templating' field, but
in general do not reliably have a 'type' field exposed.
Copy link
Collaborator

@rgeyer rgeyer left a comment

Choose a reason for hiding this comment

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

When would this get used?

The opinion of the dashboard linter is that a dashboard should always have a templated data source, which the user can select.

By using an annotated data source instead, that directly violates the template-datasource-rule.

Or.. Am I missing something?

@diurnalist
Copy link
Contributor Author

diurnalist commented Sep 19, 2024

maybe I am misunderstanding, but this is about defining annotations w/in the dashboard. Annotations can be defined by querying a datasource. for example, we had some dashboards at $JOB that had this in the top-level JSON schema:

  "annotations": {
    "list": [
      {
        "datasource": {
          "type": "prometheus",
          "uid": "0c52be2e-c5dd-48b3-b134-99d970fd5bc3"
        },
        "enable": true,
        "expr": "changes(kube_deployment_status_replicas{k8s_namespace_name=\"$kube_namespace\", deployment_environment=\"$env\", deployment_stack=\"$stack\"}[$__interval]) > 0",
        "iconColor": "red",
        "name": "Deployment annotations",
        "titleFormat": "Deployment"
      },
      {
        "builtIn": 1,
        "datasource": {
          "type": "grafana",
          "uid": "-- Grafana --"
        },
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },

because the linter was not looking at .annotations on the model, it didn't detect the fact that this datasource wasn't templated. and yes, the intent is to be able to use the templated datasource rule in more places :) - there are a lot of places where datasources can be configured, i am finding :p

@rgeyer
Copy link
Collaborator

rgeyer commented Sep 19, 2024

Ohh ohh right.. I'm picking up what you're putting down now. I conflated this with the __inputs value that you can use to replace a hard-coded data source when importing a dashboard. Totally different thing, but my brain combined them.

So for this, we'd want to make sure that the data source used by the annotation is the templated data source.

That warrants another rule, as it wouldn't make sense in panel-template-rule, since it isn't really a panel. Maybe a dashboard rule.. 🤔 I'll have to give that some thought.

Can I ask you to create an issue to go along with this, to ultimately implement a rule that takes advantage of the visibility of the annotations? I can get this merged at that point.

@diurnalist
Copy link
Contributor Author

sure! i filed #197

fwiw we are using this project as part of a custom lint script and I wrote a new rule datasource-from-inputs-rule that will detect and automatically fix any instances where datasources are not templated.

@rgeyer rgeyer merged commit 5af3c16 into grafana:main Sep 25, 2024
4 checks passed
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