grafana-wtf icon indicating copy to clipboard operation
grafana-wtf copied to clipboard

Datasources defined as variables listed as unused

Open atavakoliyext opened this issue 3 years ago • 1 comments

First off, thank you for this incredibly useful tool!

In cases where a datasource is specified via variable, that datasource may appear as unused in the output of grafana-wtf explore datasources.

How to reproduce

  1. Add a new datasource in Grafana
  2. Create a dashboard in Grafana
  3. Add a variable of type "Data source" with an arbitrary name & confirm that the datasource created in step 1 can be selected
  4. Use the variable as the datasource for a new panel in this dashboard, confirm that the panel renders data from that source
  5. Run grafana-wtf explore datasources

Expected

The unused field of the output does not contain the new datasource.

Actual

The unused field contains the new datasource.

Notes

Since a datasource variable of a given type with no filter could in theory match every datasource of that type, I'm not sure if there's an obvious fix that would avoid excluding too much from the unused field, for any Grafana instance that uses such datasource variables, which might itself be unexpected.

It might also be unexpected that the used field excludes datasources that can be selected via variable; though for the same reason as above, this might result in dashboards that use a datasource variable to appear in every used entry, which may itself be unexpected.

This might just be a documentation fix to warn that these cases exist. Or, perhaps a new argument could be added to explore datasources to control how to treat such cases?

atavakoliyext avatar Sep 21 '22 23:09 atavakoliyext

Dear Ali,

thanks a stack for creating this issue.

This might just be a documentation fix to warn that these cases exist. Or, perhaps a new argument could be added to explore datasources to control how to treat such cases?

I will be happy if grafana-wtf will be improved on this matter. However, I haven't wrapped my head about the issue yet. Would you also be up for submitting a corresponding patch?

With kind regards, Andreas.

amotl avatar Sep 30 '22 11:09 amotl

Hi again,

I just found a minute to read a bit into the details of this issue.

In cases where a datasource is specified via variable, that datasource may appear as unused in the output of grafana-wtf explore datasources.

Without doing too much research yet, I think the only option for providing a sane implementation would be that grafana-wtf should exercise the same functionality as Grafana here, essentially supporting the datasource is specified via variable feature, no?

The question which comes to mind, is: How could grafana-wtf resolve that variable into the effective data source name? Maybe using an API endpoint?

Maybe you can share some JSON payload snippets of dashboards which use that feature, in order to contribute to the implementation?

With kind regards, Andreas.

amotl avatar Nov 14 '22 23:11 amotl

Dear Ali,

I've just submitted a corresponding patch at GH-60, aiming to improve the situation, at least for a specific case. What do you think about it?

This might just be a documentation fix to warn that these cases exist.

Good idea.

Or, perhaps a new argument could be added to explore datasources to control how to treat such cases?

I will be happy to listen to corresponding proposals.

With kind regards, Andreas.

amotl avatar Feb 09 '23 22:02 amotl

Hi again,

have you been able to try out the new implementation? We will be happy to hear back if this improves the situation for you, and if you think we should take further actions on this topic.

With kind regards, Andreas.

amotl avatar Mar 05 '23 13:03 amotl

Hi @amotl, apologies for the delay and thanks for the fix! This looks to address the issue.

Thanks again for building this great tool!

atavakoliyext avatar Mar 15 '23 12:03 atavakoliyext

Hi Ali, thanks for reporting back!

Thanks again for building this great tool!

Thank you, appreciate it. [^1]

[^1]: Make sure not to miss the new GH-65 ;].

amotl avatar Mar 15 '23 18:03 amotl