-
Notifications
You must be signed in to change notification settings - Fork 3
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add compatibility check and health diagnostics compat feature #39
Conversation
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.
using "test" is a bit confusing to me. i assume its a unit test. can we use "check" or some other term?
src/utils/testDatasource.ts
Outdated
* @param baseTestDatasource The original testDatasource function | ||
* @returns Either the health check result if the health check was successful or an error that is handled later by Grafana | ||
*/ | ||
export const testDatasource = async (baseTestDatasource: BaseTestDatasource): Promise<TestDatasourceReturn> => { |
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.
checkDatasource? testDatasource is confusing to me, I assume its a unit test
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 is the function we want to override the core Grafana's testDatasource
with: https://github.com/grafana/grafana/blob/master/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts#L207
I was thinking it would be good to have the same 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.
yeah that makes sense, just confusing
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.
Yeah, I can see how that can be confusing - hopefully the jsdocs I've added can help clarify things
src/utils/testDatasource.ts
Outdated
// the backwards compatibility only affects the health check error messages | ||
// so only transform the error we give to Grafana | ||
try { | ||
const response = await baseTestDatasource() |
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.
Any reason why you want to store the response and return it?
Also, why await? You are returning a promise anyway or an error.
return baseTestDatasource();
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 point! This was from when I was thinking of transforming things after we receive the response (before I realised we only ever care about the error) 馃挴
Issue: #38 - please read, there is a lot of context and screenshots which may help 馃檹
Supports the old format of error messages for users running Grafana <8, even when we have a new backend response coming from the plugin (for Grafana 8+).
Overriding the
testDatasource
function allows us to keep the new backend response and new core Grafana UI as it is for the new changes, but allow support for transforming what we send back from our plugin to core Grafana. This should improve maintainability.Takes inspriration from https://github.com/marcusolsson/grafana-plugin-support/blob/c3f0272005d2e68142a756dbd85ad2df1ccbb962/src/utils/capability.ts
The addition of the new
compatibility.ts
andcompatFeatures.ts
files should also help us with similar issues in the future for easier maintainability for knowing what compatibility issues we have. These can also be shared across all our plugins, rather than requiring copypasta in each individual plugin.Usage:
From the plugin's
datasource.ts
file:Before
Grafana <8:
With no support for backwards compatibility, users would see an error message that is not useful:
Grafana 8+:
After
Grafana <8:
They can now see the same old format and the new changes do not affect it:
Grafana 8+: