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
Add silent option to backend requests #11678
Conversation
* When set to `true`, the `silent` option for backend_srv requests suppresses all event emitters that are triggered when the response is received. * Added `helperRequest()` to the Prometheus datasource to support requests that are not triggered by the user, e.g., for tab completion. `helperRequest()` sets the `silent` option. * Migrated all non-timeseries queries of the Prometheus datasource to use `helperRequest()`. Fixes #11673
@@ -81,6 +81,20 @@ export class PrometheusDatasource { | |||
return this.backendSrv.datasourceRequest(options); | |||
} | |||
|
|||
// Use this for tab completion features, wont publish response to other components | |||
helperRequest(url) { |
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 think we can come up with a better name :)
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.
Agree with Carl. How about metadataRequest?
@@ -81,6 +81,20 @@ export class PrometheusDatasource { | |||
return this.backendSrv.datasourceRequest(options); | |||
} | |||
|
|||
// Use this for tab completion features, wont publish response to other components | |||
helperRequest(url) { |
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.
Agree with Carl. How about metadataRequest?
silent: true, | ||
}; | ||
|
||
if (this.basicAuth || this.withCredentials) { |
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.
It's a bit unfortunate to multiply this logic and possibly easy to miss if making a change to the _request function. Would it be possible to let this function reuse the _request function? Maybe by introducing a new argument at the end of _request function.
From review feedback: * s/helper/metadata * combined positional args to _request into options dict * metadataRequest reuses _request() * moved consumption of this.httpMethod into _request, can be overwritten in options due to spread-after
Thanks for the feedback @marefr PTAL |
var options: any = { | ||
url: this.url + url, | ||
method: method, | ||
requestId: requestId, | ||
method: this.httpMethod, |
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 does not work for metric find queries when using Prometheus >= v2.1.0 and HTTP method is configured to POST. When editing a template variable query I receive "Template variables could not be initialized: Cannot read property 'jquery' of null".
I think all meta data requests should always use GET to resolve this problem. Some tests of this would be nice for the _request method and/or metric find queries.
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.
Good catch!
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.
Great 👍
true
, thesilent
option for backend_srv requestssuppresses all event emitters that are triggered when the response is
received.
metadataRequest()
to the Prometheus datasource to supportrequests that are not triggered by the user, e.g., for tab completion.
metadataRequest()
sets thesilent
option.use
metadataRequest()
._request
intooptions
dict.Fixes #11673