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

$__dateFilter macro excludes same day data #275

Open
a-szegel opened this issue Sep 8, 2023 · 7 comments
Open

$__dateFilter macro excludes same day data #275

a-szegel opened this issue Sep 8, 2023 · 7 comments
Labels
datasource/Athena type/bug Something isn't working

Comments

@a-szegel
Copy link

a-szegel commented Sep 8, 2023

What happened:
WHERE $__dateFilter(timestamp) AND produces athena query logic WHERE timestamp BETWEEN date '2023-08-08' AND date '2023-09-08' for time interval NOW and NOW -30D. 2023-09-08 is today's date, and corresponds to HH:MM:SS of 00:00:00. This means that queries are only searching data from 2023-09-07 23:59:59.999999 (the day before), and will never include data made on the same day. Therefore, I never see same day data on the dashboards.

What you expected to happen:

The Amazon Athena Service supports arbitrary timestamps in the future (today's date + N days is acceptable). When I run an Athena query and use the $__dateFilter macro, I would expect the query to generate todays date + 1 day. If today is 09/08/2023, I would expect the query to generate: WHERE timestamp BETWEEN date '2023-08-08' AND date '2023-09-09'.

Environment:

  • Grafana version: 9.4
  • Plugin version: 2.8.0
  • OS Grafana is installed on: Amazon Managed Grafana
@a-szegel a-szegel added datasource/Athena type/bug Something isn't working labels Sep 8, 2023
@a-szegel a-szegel changed the title Athena $__dateFilter macro excludes same day data $__dateFilter macro excludes same day data Sep 8, 2023
@a-szegel
Copy link
Author

a-szegel commented Sep 8, 2023

I understand that we round NOW to the day to enable QRR queries. I like this idea, and think that we should round to the next day, and not the previous day.

@a-szegel
Copy link
Author

a-szegel commented Oct 11, 2023

I think that this is the change that we want, but I don't have a test environment setup currently (so it is untested).

└─╼ git diff
diff --git a/pkg/athena/macros.go b/pkg/athena/macros.go
index bb87db12..56d835dc 100644
--- a/pkg/athena/macros.go
+++ b/pkg/athena/macros.go
@@ -145,7 +145,7 @@ func macroDateFilter(query *sqlds.Query, args []string) (string, error) {
        var (
                column = args[0]
                from   = query.TimeRange.From.UTC().Format("2006-01-02")
-               to     = query.TimeRange.To.UTC().Format("2006-01-02")
+               to     = query.TimeRange.To.AddDate(0, 0, 1).UTC().Format("2006-01-02")
        )
 
        return fmt.Sprintf("%s BETWEEN date '%s' AND date '%s'", column, from, to), nil

@sidd328
Copy link

sidd328 commented Nov 10, 2023

Hello,

I was wondering if there were any updates on whether this issue will be worked on?

AMG customers are hoping for a fix.

Thank you

@lankath
Copy link

lankath commented Jan 9, 2024

Hi, are there any updates on progress for this issue? Amazon Managed Grafana customers are looking to get this fixed. Thanks!

@anuragarora
Copy link

Is this issue being worked on ?

@jessermejia
Copy link

@sarahzinger are there concerns with changing the behavior? it looks like this was going to be prioritized then re-backlogged

@sarahzinger
Copy link
Member

Hey folks, I'll bring this back to the team to see if we can prioritize a fix for this over the next few weeks.

I suppose some concerns about implementing this as is are that would technically be a breaking change? But perhaps everyone wants this breaking change?

Another alternative could be that we create a new macro with the functionality that has been requested here, and document the existing one to explain this functionality limitation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datasource/Athena type/bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

8 participants