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

Time filter within a variable query does't work #546

Closed
shaharmor opened this issue Jan 25, 2023 · 9 comments · Fixed by #560
Closed

Time filter within a variable query does't work #546

shaharmor opened this issue Jan 25, 2023 · 9 comments · Fixed by #560
Assignees
Labels
datasource/ADX effort/small good first issue Good for newcomers type/bug Something isn't working

Comments

@shaharmor
Copy link

shaharmor commented Jan 25, 2023

What happened:

When trying to add a time filter to a query-based variable, the query fails.

Example query:

myTable
| where $__timeFilter(timestamp) // <-- This line makes the query fail
| take 10
| project columnName

What you expected to happen:

The query should use the timefilter when getting the data from ADX for the variable

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

Screenshots

Anything else we need to know?:

Environment:

  • Grafana version: v9.2.7.1 (0f96ed148c)
  • Plugin version: 4.1.6
  • OS Grafana is installed on: N/A
  • User OS & Browser: Mac + Chrome
  • Others:
@shaharmor shaharmor added datasource/ADX type/bug Something isn't working labels Jan 25, 2023
@bossinc
Copy link
Contributor

bossinc commented Jan 26, 2023

It doesn't look like we currently support time macros in template variable queries. @aangelisc please correct me if I'm wrong.

@shaharmor
Copy link
Author

shaharmor commented Jan 26, 2023

I also don’t think it is possible to reference other variables for even further filtering.

for example, if I have a “customer” variable and an “order” variable, I would want that when I filter for customer A, the orders variable will only show values for customer A.

should I open a different issue for this?

@andresmgot
Copy link
Contributor

The timeFilter macro and other variables are supported. If you open the Query Inspector, you should be able to see how it's resolved, something like:

myTable
| where timestamp >= datetime(2023-01-26T08:23:09.677Z) and timestamp <= datetime(2023-01-26T08:38:09.677Z)
| take 10
| project columnName

The problem may be that the column timestamp may not exist. What is the error you are getting?

I also recommend upgrading to the latest version of the plugin to get rid of possible bugs.

@shaharmor
Copy link
Author

@andresmgot it doesn't work.

I added this where clause to the query of the variable:

| where $__timeFilter(timestamp)

and the query is being sent with this line as is.

@andresmgot
Copy link
Contributor

@shaharmor that indeed should not happen. I cannot reproduce it with the latest version of the plugin (and Grafana):

Screenshot from 2023-01-26 15-52-15

Can you check if upgrading solves your issue?

@shaharmor
Copy link
Author

@andresmgot in a panel it works, but not in a variable query

@andresmgot
Copy link
Contributor

andresmgot commented Jan 26, 2023

ah, sorry, completely misread the description you are right @bossinc we don't support time variables in variables queries. This would be a new feature.

We should refactor how template variables are written in the plugin. It's using the old metricFindQuery method, while it should use the same query editor as the panel.

As currently is, it's not sending a time range as part of the query so in the backend, the timeFilter macro is resolved but using 0 as the value, which leads to an empty result.

@shaharmor
Copy link
Author

I really think this would greatly improve the UX of using variables for filtering, as the values will only be the ones relevant and not all possible values

@taleena
Copy link

taleena commented Apr 4, 2023

Overally, the fix alone for this was a small effort, but did additional work to improve the feature, which would count the overall time spent here closer to a medium.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datasource/ADX effort/small good first issue Good for newcomers type/bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants