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鈥檒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

Merged
merged 11 commits into from
May 4, 2021

Conversation

vickyyyyyyy
Copy link
Member

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 and compatFeatures.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:

import { healthDiagnosticsErrorsCompat } from 'ui-enterprise';

async testDatasource() {
    return healthDiagnosticsErrorsCompat(super.testDatasource.bind(this))
}

Before

Grafana <8:

With no support for backwards compatibility, users would see an error message that is not useful:

image

Grafana 8+:

image

After

Grafana <8:

They can now see the same old format and the new changes do not affect it:

image

Grafana 8+:

image

@vickyyyyyyy vickyyyyyyy requested review from a team, srclosson and yesoreyeram April 30, 2021 13:20
Copy link
Contributor

@scottlepp scottlepp left a 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?

* @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> => {
Copy link
Contributor

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

Copy link
Member Author

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?

Copy link
Contributor

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

Copy link
Member Author

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

// the backwards compatibility only affects the health check error messages
// so only transform the error we give to Grafana
try {
const response = await baseTestDatasource()
Copy link
Member

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();

Copy link
Member Author

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) 馃挴

@vickyyyyyyy vickyyyyyyy merged commit c21b866 into master May 4, 2021
@vickyyyyyyy vickyyyyyyy deleted the compat branch May 4, 2021 09:48
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

3 participants