In a short ill try to describe a problem which I am currently facing.
I made a grafana annotator script which posts an annotation on a service failure. The problem is that it do not recognize variables of dashboard. For example we got a “node” variable which filters instance name (label_values(node_load1, instance)), so in one dashboard we can select a lot of instances and check the node metrics of it.
The problem is if we post annotation, it posts it globally on all instances, and variable is not recognized.
In the meantime, I was able to pass template variables into an annotation’s text using the HTTP API. The annotations still appear across instances, but at least each annotation is specific to one:
curl -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer my-api-token" -X POST -d "{\"dashboardId\": 29, \"panelId\": 2, \"time\": 1620701703864, \"timeEnd\": 1620701703864, \"tags\":[\"localhost:9100\"], \"text\":\"this is a tesCt on $instance\"}" https://grafana.example.dev/api/annotations
Now from the UI, you can create non-global annotations with specific queries that pass in variables. See the query by tag section in the documentation for annotations.
Then the annotations only appear when viewing that variable:
Hey, yes, that’s actually what i need, so ill wait for the new feature because from the issues i can see that the tags are not recognized with a variables. We can close this ticket i think.
Ok @nerijusrazvodovskis, so I spoke with another engineer and I actually think what you want to do is possible.
Using the above curl command, I was able to reproduce your problem. I created an annotation for a panel that was using template variables to render data for two different instances. But, the annotation would appear across both panel-views.
I changed the Filter by to Tags in the Annotation UI for that dashboard. I then added the template variable as a tag. Then the views rendered properly.
Yes i see you have replicated my issue, i’ve already tried filter by tags before on my end too, but no success (it was adding to both dashboards anyways ). Could you also provide your variable configuration? Maybe im doing something wrong with the variable Also you are on the newest version of grafana?
I added the annotation using cURL from my local machine. Grafana is running on a remote Ubuntu 20 server, on v.7.4.5, behind nginx w/ domain & tls. hmmm…
still no luck?