athena-datasource icon indicating copy to clipboard operation
athena-datasource copied to clipboard

$__dateFilter macro excludes same day data

Open a-szegel opened this issue 2 years ago • 7 comments

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 avatar Sep 08 '23 07:09 a-szegel

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 avatar Sep 08 '23 15:09 a-szegel

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

a-szegel avatar Oct 11 '23 16:10 a-szegel

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

sidd328 avatar Nov 10 '23 18:11 sidd328

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

lankath avatar Jan 09 '24 17:01 lankath

Is this issue being worked on ?

anuragarora avatar Jan 24 '24 03:01 anuragarora

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

jessermejia avatar Feb 22 '24 00:02 jessermejia

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.

sarahzinger avatar Feb 22 '24 13:02 sarahzinger

This issue has been automatically marked as stale because it has not had activity in the last year. It will be closed in 30 days if no further activity occurs. Please feel free to leave a comment if you believe the issue is still relevant. Thank you for your contributions!

github-actions[bot] avatar Feb 22 '25 02:02 github-actions[bot]

This issue has been automatically closed because it has not had any further activity in the last 30 days. Thank you for your contributions!

github-actions[bot] avatar Mar 24 '25 02:03 github-actions[bot]