Skip to content

Adhoc filters don't work on the panels with datasource variable #1114

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

Open
sukhada369 opened this issue Jan 14, 2025 · 7 comments
Open

Adhoc filters don't work on the panels with datasource variable #1114

sukhada369 opened this issue Jan 14, 2025 · 7 comments

Comments

@sukhada369
Copy link

What happened:
We are using following versions:
Grafana: v11.4.0
Grafana clickhouse-datasource plugin: v4.5.1
ClickHouse client version: 24.11.1.2557

Adhoc filters don't work on the panels with datasource variable. It works as expected when datasource is explicitly selected in the panel dropdown. In Query inspector we see that additional "additional_table_filters" setting is not getting appended in case of datasource variable is selected.

What you expected to happen:
additional_table_filters should append with datasource variable

How to reproduce it (as minimally and precisely as possible):

  1. Create a single Clickhouse datasource. Create a dashboard with two panels and ensure data is coming in. We are using SQL Editor to add our panel queries.
  2. From the "Logs" panel add a filter and notice that both the panels are showing only the filtered data.
  3. Create one more Clickhouse datasource. Update dashboard with a variable of type Datasources and ensure that both the Clickhouse datasources are available in the variable dropdown. Update both the panels to use the datasource variable.
  4. Refresh the dashboard and change the datasources to ensure that data is coming in from both the datasources and both the panels are updating
  5. From "Logs" panel add filter. Data won't change on both the panels [This is the problem]

How to further debug with Query Inspector:

  1. Edit the "Logs" panel with explicit datasource
  2. Expand one of the logs and filter a value
  3. Execute "Run Query" -> "Query Inspector" -> "Query" tab -> "Refresh" -> This will show what query was executed against Clickhouse
  4. Notice that the end of query is appended with "settings additional_table_filters=<your_filter>"
  5. Close the Query inspector and in Datasource select the Datasource variable and perform all the steps again

Screenshots

With datasource explicitly selected:

Image

With Datasource variable:

Image

Anything else we need to know?:

Environment:

  • Grafana version: 11.4.0
  • Plugin version: 4.5.1
  • OS Grafana is installed on: OEL8
  • User OS & Browser: MAC, Google Chrome
  • Others:
@sukhada369 sukhada369 added datasource/ClickHouse type/bug Something isn't working labels Jan 14, 2025
@satyapriyanka
Copy link

satyapriyanka commented Jan 17, 2025

I am also experiencing this issue as well, along with above issue, additionally while trying to add first additional filter getting below error in console.

Failed to parse SQL statement into an AST: Error: Syntax error at line 4 col 17

It would be great to have this addressed. Let me know if i can help with additional details or testing!

Environment:
Grafana version: 11.1.0
Plugin version: 4.3.2

@SpencerTorres
Copy link
Collaborator

Hey thanks for providing this info. Adhoc filters are known to be a bit unpredictable due to the AST parsing.

@satyapriyanka Thank you for providing the console error, the AST was unable to identify which table to filter on. Do you have the SQL that caused this?

@sukhada369 do you have the console message and SQL that caused this? I wonder if it's also an error in console.

@sukhada369
Copy link
Author

@SpencerTorres , there is no error. Panels show the data it is just that it doesn't add the filter on the fly.

@satyapriyanka
Copy link

@SpencerTorres When i tried to add adhoc filters values i see this in console logs
Failed to parse SQL statement into an AST: Error: Syntax error at line 4 col 17:

2 GROUP BY ServiceName, time
3 ORDER BY time ASC
4
^
Unexpected lparen token: "(". Instead, I was expecting to see one of the following:

- A "word" token
- A "word" token
- A "word" token
- A "op_cast" token
- A "lbracket" token
- A "op_member" token
- A "op_membertext" token
- A "word" token
- A "word" token
- A "op_exp" token
- A "star" token
- A "op_div" token
- A "op_mod" token
- A "op_plus" token
- A "op_minus" token
- A "op_additive" token
- A "kw_not" token
- A "kw_in" token
- A "kw_not" token
- A "op_like" token
- A "op_ilike" token
- A "op_not_like" token
- A "op_not_ilike" token
- A "kw_like" token
- A "kw_ilike" token
- A "ops_others" token
- A "kw_not" token
- A "kw_is" token
- A "kw_notnull" token
- A "kw_is" token
- A "kw_isnull" token
- A "kw_is" token
- A "word" token
- A "op_compare" token
- A "op_eq" token
- A "op_neq" token
- A "kw_and" token
- A "kw_or" token
- A "kw_as" token
- A "kw_primary" token
- A "kw_unique" token
- A "quoted_word" token
- A "word" token
- A "comma" token
- A "kw_from" token
- A "kw_where" token
- A "kw_group" token
- A "kw_order" token
- A "kw_offset" token
- A "kw_for" token
- A "kw_limit" token
- A "kw_fetch" token
- A "kw_union" token
- A "semicolon" token

@SpencerTorres
Copy link
Collaborator

@satyapriyanka do you have the SQL query itself? Which query is causing this?

@sukhada369 If theres no error in the JS console then perhaps it's excluding it for other reasons. I'll see if I can reproduce this error

@sukhada369
Copy link
Author

@SpencerTorres , did the steps help to reproduce the issue?

@sukhada369
Copy link
Author

I have tried with latest version of the plugin i.e. 4.7.0 and the behavior is the same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants