-
Notifications
You must be signed in to change notification settings - Fork 28
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
Improve smartquery
and query_factory
beyond data source health checks
#112
Conversation
smartquery
and query_factory
beyond data source health checks
Codecov Report
@@ Coverage Diff @@
## main #112 +/- ##
==========================================
- Coverage 95.88% 95.15% -0.73%
==========================================
Files 25 25
Lines 1531 1590 +59
==========================================
+ Hits 1468 1513 +45
- Misses 63 77 +14
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
now returns dict containing all info to request Grafana API.
fix smart_query for check_health
ce855a9
to
878ca42
Compare
878ca42
to
5782066
Compare
elif datasource_type == "loki": | ||
if "status" in response and response["status"] == "success": | ||
if self.api.version and VERSION_7 <= LooseVersion(self.api.version) < VERSION_8: | ||
if "status" in response and response["status"] == "success": | ||
message = "Success" | ||
success = True | ||
else: | ||
message = response.get("message", "Unknown error") | ||
elif "results" in response and "test" in response["results"]: | ||
message = "Success" | ||
success = True | ||
else: | ||
elif "message" in response: | ||
message = response["message"] |
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.
I've adjusted this a bit, compared to your version, @peekjef72. When anything is wrong, please send fixes. 🌻
@@ -403,6 +440,7 @@ def health_check(self, datasource: Union[DatasourceIdentifier, Dict]) -> Datasou | |||
expression = get_healthcheck_expression(datasource_type, datasource_dialect) | |||
|
|||
start = time.time() | |||
message = "Unknown error" |
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.
I discovered cases where this was needed. Apparently, not all code paths have been covering this before.
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"], | ||
) |
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.
We don't have tests for those yet. Do you think you can add some?
if "time_from" in model: | ||
query["from"] = model["time_from"] | ||
if "time_to" in model: | ||
query["until"] = model["time_to"] | ||
|
||
request["data"] = query |
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.
This spot also lacks testing.
Hi there,
this patch by @peekjef72 (thanks!) will improve the datasource query interface, which is an experimental subsystem of grafana-client, aiming to provide a unified interface for querying data sources "behind" Grafana.
Dear @peekjef72, I am handing in your patch from GH-38 separately, to have something to compare against in the case something went wrong with the rebasing, and for your and future references.
I will continue here to add corresponding adjustments to the test suite, in order to integrate this patch.
With kind regards,
Andreas.