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

Review adjustments to smartquery and query_factory #38

Closed
wants to merge 27 commits into from

Conversation

peekjef72
Copy link
Contributor

@peekjef72 peekjef72 commented Sep 19, 2022

About

I've tried to use query methods from grafana-client info grafana-snapshot-tool. For that I need to perform some adjustement to api interface.

  • extend query_factory to be able to set more parameters for each "known" datasource according to their parameters. Goal it to use parameters set in the panel mixed with datasource requirements and format to generate a request object (method, uri fragments, data to Post)
  • review examples datasource-smartquery.py and datasource-health-check.py to ensure they still work.

Discussion

it seems to me that :

  • datasource accesses change with grafana version: Prometheus in v 7 use format specified in function query() and query_range(), but now use a standard format for the queries (type or range) and results.
  • the format of the results changes from one datasource to anothers, maybe for grafana vesion too.
  • some of your tests (Loki ) seems not working for me : format my have change... not sure.

I'm not sure that the grafana_client must implement a generic function smartquery() that permit to users to query and version to Grafana server and any data source in a unified way.
What is your opinion ?

@peekjef72

This comment was marked as duplicate.

@amotl
Copy link
Contributor

amotl commented Oct 17, 2022

Dear Jean-Francois,

thanks a stack for your excellent contribution and for bringing up the corresponding discussion topics.

I've tried to use query methods from grafana-client in grafana-snapshot-tool. For that I need to perform some adjustments to the API interface.

grafana-client should definitively be able to support grafana-snapshot-tool in the way you are proposing. It is very sweet to see you have been able to build upon my recent additions at grafana_client.elements.datasource, where you certainly improved some important details in order to make it more generic. This is the place where I had to stop on the last iteration, so I am exceptionally happy about it.

I will try to dedicate some time for a detailed review of your patch soon. I think your recent updates, especially removing smartquery_old, makes the overall appearance much more clear now.

With kind regards,
Andreas.

Comment on lines +315 to +330
elif datasource_type in ("prometheus", "loki") and LooseVersion(self.api.version) <= VERSION_7:
if "queries" in request["data"] and len(request["data"]["queries"]) > 0 \
and "instant" in request["data"]["queries"][0] and request["data"]["queries"][0]["instant"]:
return self.query(
datasource.get("id"),
request["expr"],
request["data"]["to"],
)
else:
return self.query_range(
datasource.get("id"),
request["expr"],
request["data"]["from"],
request["data"]["to"],
request["data"]["step"],
)
Copy link
Contributor

Choose a reason for hiding this comment

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

datasource accesses change with grafana version: Prometheus in v 7 use format specified in function query() and query_range(), but now use a standard format for the queries (type or range) and results.

Hi. It looks like @PankajKhanwani is looking for this improvement around properly supporting Prometheus at GH-85, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi,
I think so.
even if PR was built for grafana 9.2 I think that the Prometheus datasource has not changed.
Do you believe you have time to review ?
JFPIK-

@amotl
Copy link
Contributor

amotl commented Sep 15, 2023

Dear Jean-Francois,

having to apologize again for the long delay, I finally found some time to review your patch in detail. I really like it, and would like to wrap it up, to satisfy the linter and the software tests, and also squash the commits, in order to finally integrate it.

I would start pushing directly to your feature branch, After rebasing your branch, I just pushed it to GH-112 already. Do you have any objections about this? If you want, and have a few spare minutes, feel free to add your comments there if you think I made a mistake anywhere.

datasource accesses change with grafana version: Prometheus in v 7 use format specified in function query() and query_range(), but now use a standard format for the queries (type or range) and results.

It is sad, right. I was well aware about those details when starting this experiment, that things will be in flux for times to come. Thank you for addressing any anomalies with your patch.

the format of the results changes from one datasource to anothers, maybe for grafana vesion too.

C'est la vie, I would say. Thank you so much for making the best out of it, by introducing corresponding version switching.

some of your tests (Loki ) seems not working for me : format my have change... not sure.

Thanks, I will look into it when starting to work on this.

I'm not sure that the grafana_client must implement a generic function smartquery() that permit to users to query and version to Grafana server and any data source in a unified way. What is your opinion?

I am absolutely not sure about it, but I definitively wanted to give it a try, because I thought it would make a nice feature. I know there will always be anomalies wrt. to a completely unified interface, that is natural. I am open to any discussions about this, and to hear back about what you think, how this topic could be approached better.

Still, I think the outcome is quite nice: After learning a bit of query parameters, how to use smartquery() for your purposes, I think it becomes very much usable for scripting purposes and for automating and monitoring Grafana, and the data sources behind. At least, this is what I was originally humbly aiming at, in order to expand what monitoring-check-grafana can do 1.

With kind regards,
Andreas.

Footnotes

  1. Currently, it is only a Shell program, and just supports InfluxDB 1.x, so it was clear to use Python for the next iteration.

@amotl amotl changed the title review query_factory and smartquery Improve smartquery and query_factory beyond data source health checks Sep 15, 2023
@amotl amotl changed the title Improve smartquery and query_factory beyond data source health checks Review improvements to smartquery and query_factory Sep 15, 2023
@amotl amotl changed the title Review improvements to smartquery and query_factory Review adjustments to smartquery and query_factory Sep 15, 2023
@amotl
Copy link
Contributor

amotl commented Sep 15, 2023

Closing this in favor of GH-112, where I added some adjustments to make the tests work again. Your improvements have been included into the 3.8.0 release, and I will be happy to receive corresponding feedback or bugfix patches, in case I made any mistakes. Thank you again, for both your patch and your patience.

@amotl amotl closed this Sep 15, 2023
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.

None yet

2 participants