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

Fix default ad hoc filters #650

Merged
merged 5 commits into from
Jan 26, 2024
Merged

Fix default ad hoc filters #650

merged 5 commits into from
Jan 26, 2024

Conversation

cwurm
Copy link
Contributor

@cwurm cwurm commented Jan 8, 2024

According to the README, it should be possible to use ad hoc filters without any special configuration:

By default, Ad Hoc filters will be populated with all Tables and Columns. If

But that's actually not the case. The current logic sets the target table for the filter to default when $clickhouse_adhoc_query is not set. This then leads to a query with a setting like SETTINGS additional_table_filters = {'default':' field = value } that doesn't work because it's not specifying the correct table.

This fix removes setting the target table to default (which seems weird in any case since there isn't usually a table like that in ClickHouse; there is only a database by that name) and sets it to the table from the query instead if no table has been specified any other way. With that, ad hoc filters work without setting $clickhouse_adhoc_query or a default database in the datasource settings.

Fixes #599.

@CLAassistant
Copy link

CLAassistant commented Jan 8, 2024

CLA assistant check
All committers have signed the CLA.

@bossinc
Copy link
Collaborator

bossinc commented Jan 10, 2024

This makes sense but, I am not able to make this work. I am using the default ChickHouse - Query Analysis dashboard with an added a adhoc var.
I set the adhoc var to query_log.query_kind with a value of Create. The query inspector returns additional_table_filters={'query_log' : ' query_kind = \'Create\' '} for the adhoc function. It should be additional_table_filters={'system.query_log' : ' query_kind = \'Create\' '} It is not filtering without the database before the table.

@cwurm
Copy link
Contributor Author

cwurm commented Jan 10, 2024

This makes sense but, I am not able to make this work. I am using the default ChickHouse - Query Analysis dashboard with an added a adhoc var.

@bossinc How are you adding the adhoc var? With that dashboard, I can add it via the Query overview panel: Edit -> Overrides -> Override 20 -> Add override property Standard options -> Ad-hoc filterable and then I can click on table cells in the Type column and it filters the whole dashboard.

@cwurm
Copy link
Contributor Author

cwurm commented Jan 10, 2024

This makes sense but, I am not able to make this work. I am using the default ChickHouse - Query Analysis dashboard with an added a adhoc var. I set the adhoc var to query_log.query_kind with a value of Create. The query inspector returns additional_table_filters={'query_log' : ' query_kind = \'Create\' '} for the adhoc function. It should be additional_table_filters={'system.query_log' : ' query_kind = \'Create\' '} It is not filtering without the database before the table.

@bossinc Ah, I think I know what you mean. You're creating a new variable on the dashboard level, type Ad hoc filters and then setting it to query_log.query_kind and Create while on the dashboard?

Seems that's another case that's not working (and hasn't worked before this PR, either).

I've fixed that as well now. Can you check that it's working for you?

@bossinc
Copy link
Collaborator

bossinc commented Jan 10, 2024

@cwurm I think we are talking about two difference ad-hoc filters. I did not know that you could make overrides for ad-hoc filters in tables like you described. 😆
I am referring to template variable adhoc filters found in dashboard settings. Here are the grafana docs: adhoc filters
In the CH plugin when filtering with adhoc filters, the data source adds the CH function additional_table_filters. When filtering with overrides it is filtering the response on the frontend instead of CH doing the filtering

@cwurm
Copy link
Contributor Author

cwurm commented Jan 10, 2024

@cwurm I think we are talking about two difference ad-hoc filters. I did not know that you could make overrides for ad-hoc filters in tables like you described. 😆
I am referring to template variable adhoc filters found in dashboard settings. Here are the grafana docs: adhoc filters

Ah, crossed wires! This should be working as well now as per my previous comment.

In the CH plugin when filtering with adhoc filters, the data source adds the CH function additional_table_filters. When filtering with overrides it is filtering the response on the frontend instead of CH doing the filtering

Hm, from what I can see, overrides also change the ClickHouse query.

@bossinc
Copy link
Collaborator

bossinc commented Jan 12, 2024

Hm, from what I can see, overrides also change the ClickHouse query.
You are right! I am trying to recreate what I thought I saw and the ad-hoc vars seem to be the same. 🤷

This PR looks good.

@bossinc bossinc enabled auto-merge (squash) January 16, 2024 23:10
@bossinc bossinc merged commit e7b1616 into grafana:main Jan 26, 2024
14 of 15 checks passed
@cwurm cwurm deleted the fix_adhoc_filters branch January 30, 2024 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ad-hoc filter does not calculate correct target table
4 participants