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

Datasource: Change query filtering #84656

Merged
merged 30 commits into from
Mar 21, 2024
Merged

Conversation

sunker
Copy link
Contributor

@sunker sunker commented Mar 18, 2024

What is this feature?
This PR changes query filtering in data source plugins. There are two noticeable changes:

Responses associated with hidden queries will be removed automatically by Grafana

Starting from Grafana 11, responses that are associated with queries where hide: true will be removed by Grafana. Queries where hide: true will still be executed (unless they're prevented from it in the data source filterQuery method), but the associated responses will no longer be passed to the panel. To align the UI with this behaviour (and with the DataQuery model), the tooltip in the query editor row is changed from Disable query to Hide/Show response.

The datasource.filterQuery method will be called from the query runner

Data source plugins that extended DataSourceWithBackend could optionally implement filterQuery to prevent certain queries from being executed. The filterQuery method was called fromwithin the query method in the DataSourceWithBackend class. Not all data source plugins extends DataSourceWithBackend, and this led to inconsistencies in how filtering worked between different types of data source plugins.

From Grafana 11, the filterQuery method is called from the query runner before the data source query method is called. This means query filtering now works in a consistent way for all types of data source plugins.

For data source plugins that extend DataSourceWithBackend, it means they can no longer test query filtering by calling the query method, as filtering occurs at an earlier stage in the query execution flow.

Why do we need this feature?

To harmonize query execution flow in backend- and non backend data source plugins and clarify the purpose of the Hide/Show response button for plugin authors and end-users.

Who is this feature for?

Plugin authors and end-users

Which issue(s) does this PR fix?:

Fixes #80531

Release notice breaking change

For data sources that extend DataSourceWithBackend, the filterQuery method is now called before the data source query method. If the filterQuery method assumes that some kind of query migration happens before this method is called, you now need to do the migration inside this method.

Users of data source plugins that did not previously remove hidden queries will see a change of behaviour: Before this change, clicking the Disable query button had no impact on the query result, but starting from Grafana 11 responses associated with hidden queries will no longer be returned to the panel.

@grafana-pr-automation
Copy link

grafana-pr-automation bot commented Mar 18, 2024

⚠️   Possible breaking changes (md version)   ⚠️

grafana-data

Changes

DataSourceApi.importQueries
/home/runner/work/grafana/grafana/pr/grafana-data/dist/index.d.ts
Parameter type changed:
      * public/app/features/datasources/state/actions.ts
      */
     abstract testDatasource(): Promise;
     /**
-     * This function is not called automatically unless running within the DataSourceWithBackend
-     *
-     * @deprecated
+     * Optionally, you can implement this method to prevent certain queries from being executed.
+     * Return false to prevent the query from being executed.
      */
     filterQuery?(query: TQuery): boolean;
     /**
      *  Get hints for query improvements


grafana-runtime

Removals

DataSourceWithBackend.filterQuery

/home/runner/work/grafana/grafana/base/grafana-runtime/dist/index.d.ts

filterQuery?(query: TQuery): boolean;


Read our guideline
Console output

@grafana-pr-automation grafana-pr-automation bot added the levitate breaking change A label indicating a breaking change and assigned by Levitate. label Mar 18, 2024
@grafana-pr-automation grafana-pr-automation bot requested review from a team and jackw and removed request for a team March 18, 2024 12:40
@sunker sunker force-pushed the datasources/base-class-defaults branch from 11faa90 to 02448f4 Compare March 19, 2024 07:13
@grafana grafana deleted a comment from grafanabot Mar 19, 2024
@grafana grafana deleted a comment from grafanabot Mar 19, 2024
@grafana grafana deleted a comment from grafanabot Mar 19, 2024
@grafana grafana deleted a comment from grafanabot Mar 19, 2024
@sunker sunker changed the title Datasource: Move methods from DataSourceWithBackend to DataSourceAPI Datasource: Change query filtering Mar 19, 2024
@sunker sunker self-assigned this Mar 19, 2024
Copy link
Contributor

@mckn mckn left a comment

Choose a reason for hiding this comment

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

LGTM!

@grafana-pr-automation grafana-pr-automation bot requested a review from a team March 20, 2024 15:35
@sunker sunker requested review from grafanabot and a team as code owners March 21, 2024 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

Datasources: Confusion around query filtering
9 participants