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

"Advanced" Date Time in Time Range Filter is Incorrect for "last", "this", "beginning", "start", "end" #30592

Open
3 tasks done
sam-hieken opened this issue Oct 13, 2024 · 15 comments · May be fixed by #31867
Open
3 tasks done
Assignees
Labels
dashboard:native-filters Related to the native filters of the Dashboard global:timezone Related to timezones preset:bounty:bug Bugs that have been selected by Preset and have a bounty attached. preset:bounty Issues that have been selected by Preset and have a bounty attached.

Comments

@sam-hieken
Copy link

sam-hieken commented Oct 13, 2024

Bug description

Certain values in the Advanced Time Filters are not returning the correct values:

  • Specifying "Last minutes" in the "Advanced" section of time range filters on dashboards will sometimes think it's a time from the day before.
  • "beginning of this month" or "start of this month" are not setting the correct date
  • "end of next month" is not finding the correct date either

Repro steps:
In either a chart with a time filter or a dashboard with a time filter, select the "Advanced" option and try one of the above options.

Screenshots/recordings

For some clarity, the following test was performed on 2024-10-13T19:38:00-0400, give or take a few seconds. I'm in EDT/EST zone.

Last Hour:

Screenshot 2024-10-13 at 7 38 31 PM

Last 2 Minutes:

Screenshot 2024-10-13 at 7 38 48 PM

Obviously "Last 2 minutes" is way off - the timestamp is nowhere close, and the date shown is yesterday. Every dashboard with a time range filter I've tried this on has the same issue, and it happens in both the Start and End inputs.


Additional Screenshots

Start of this month:

(the "Today" is working correctly for reference of today's date)
image

End of next month:

image

Superset version

master / latest-dev

Python version

3.9

Node version

16

Browser

Firefox

Additional context

No response

Checklist

  • I have searched Superset docs and Slack and didn't find a solution to my problem.
  • I have searched the GitHub issue tracker and didn't find a similar bug report.
  • I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
@dosubot dosubot bot added dashboard:native-filters Related to the native filters of the Dashboard global:timezone Related to timezones labels Oct 13, 2024
Copy link

dosubot bot commented Oct 13, 2024

The issue you're experiencing with the "Last minutes" time range filter might be related to timezone handling. Superset uses the timezone-mock library to simulate different timezones and calculate time offsets. This can sometimes lead to discrepancies if the timezone isn't correctly accounted for in the calculations [1].

To address this, you might want to check if the timezone settings in your Superset configuration are correctly set to match your local timezone (EDT/EST). Additionally, ensure that both your database and Superset backend are configured to use UTC, as this can help avoid issues with temporal fields lacking explicit timezones [2].

If the problem persists, consider reviewing the logic in the get_since_until function, which calculates start and end times for relative time ranges. This function uses parameters like relative_start, relative_end, and time_shift to determine the correct time range [3].

To continue talking to Dosu, mention @dosu.

@sam-hieken
Copy link
Author

sam-hieken commented Oct 14, 2024

@dosu Nope, changed both my database timezone and superset timezone (DEFAULT_TIMEZONE in superset_config.py) to use EST/EDT: same issue. Did the exact same thing but UTC for both Superset and my database: still the same issue.

Copy link

dosubot bot commented Oct 14, 2024

Superset assumes timestamps are in UTC, and configuring the backend to a non-UTC timezone like EST/EDT can lead to issues. It's recommended to keep both the database and Superset backend in UTC to ensure consistency [1].

If you've already set both to UTC and the issue persists, it might be worth checking if there are any specific configurations or overrides in your setup that could affect timezone handling. Additionally, reviewing the logic in the get_since_until function might help identify any discrepancies in how relative time ranges are calculated.

To continue talking to Dosu, mention @dosu.

@rusackas
Copy link
Member

rusackas commented Nov 5, 2024

I wonder if the underlying library (which I can't recall the name of) is interpreting "last two minutes" as the "last two minutes of the day" rather than the "last two minutes that occurred." In that case, it's right... and it's kind of a language/clarity failure. What happens if you say "prior two minutes" or "two minutes ago"?

@yousoph
Copy link
Member

yousoph commented Nov 21, 2024

Hi @sam-hieken ! Thanks for filing this issue! I was about to report something very similar, hope you don't mind me making some edits/additions to your original issue to include some more details and other cases where the advanced filters aren't working.

@yousoph yousoph changed the title "Advanced" Date Time in Time Range Filter is Incorrect "Advanced" Date Time in Time Range Filter is Incorrect for "last", "this", "beginning", "start", "end" Nov 21, 2024
@yousoph
Copy link
Member

yousoph commented Nov 21, 2024

I wonder if the underlying library (which I can't recall the name of) is interpreting "last two minutes" as the "last two minutes of the day" rather than the "last two minutes that occurred." In that case, it's right... and it's kind of a language/clarity failure. What happens if you say "prior two minutes" or "two minutes ago"?

It seems to be using the last 2 minutes of yesterday though, which seems like a strange interpretation if that's what's happening. Plus the "last hour" uses the start of the hour before the current hour so that one isn't using yesterday.

You're right that 2 minutes ago does work as expected though so that could be a workaround for the interim

@geido geido added preset:bounty Issues that have been selected by Preset and have a bounty attached. preset:bounty:bug Bugs that have been selected by Preset and have a bounty attached. labels Nov 21, 2024
@geido
Copy link
Member

geido commented Nov 21, 2024


🎉 Preset Bounty Available: $150 USD 🎉

To claim this bounty, please carefully follow the steps below.


📋 Steps to Participate

  1. Review Guidelines:
    Read through the Preset Bounty Program Contribution Guide for complete details on bounty requirements.

  2. Show Your Interest:
    Complete the Preset Bounty Program Survey and comment this issue to express your interest.

  3. Join the Slack Channel:
    After completing the survey, you’ll receive an invitation to the dedicated Apache Superset Slack channel.

  4. Get Assigned:
    To officially start, ensure a Bounty Program Manager has assigned you to this issue.

  5. Submit Your Solution:
    When ready, submit your solution with the Fixes #{issue_number} notation in your Pull Request description.

  6. Claim Your Bounty:
    Sign up at GitPay.me and submit your solution via: https://gitpay.me/#/task/981


💡 Additional Notes

  • Only developers assigned by a Bounty Program Manager should start working on this issue to win the bounty.
  • Be sure to follow the guide closely to avoid any delays in payment. Please, allow a few days after your PR has been merged for the bounty to be released.

Good luck, and happy coding! 🎉

@sam-hieken
Copy link
Author

Hi @yousoph, no worries, please feel free!

@sam-hieken
Copy link
Author

@rusackas So I've found that "2 minutes ago" works as desired like @yousoph said, but "Prior 2 minutes" will actually go 2 minutes into the future:

Screenshot 2024-11-22 at 3 16 27 PM

I'm not familiar with Superset's codebase, but I've narrowed down the problem to the /api/v1/time_range endpoint in the backend. For example, in the above image, the following request was produced to parse the plain language into a date:

Endpoint: /api/v1/time_range/?q='now : Prior 2 minutes'
Response:

{
    "result": {
        "since": "2024-11-22T15:16:19",
        "until": "2024-11-22T15:18:19",
        "timeRange": "now : Prior 2 minutes"
    }
}

@aybanda
Copy link

aybanda commented Nov 27, 2024

Hey @geido can you assign this issue to me ?

@geido
Copy link
Member

geido commented Dec 6, 2024

Hi @aybanda how is this going?

@aybanda
Copy link

aybanda commented Dec 6, 2024

Hey @geido I will be generating a PR very shortly.

@Niharika0104
Copy link

@geido is this still open I see a pr but it's closed can I work on this?

@fzh075
Copy link

fzh075 commented Dec 31, 2024

I'm in line behind @Niharika0104.

@alexandrusoare
Copy link
Contributor

Hey @geido can I have a look at this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dashboard:native-filters Related to the native filters of the Dashboard global:timezone Related to timezones preset:bounty:bug Bugs that have been selected by Preset and have a bounty attached. preset:bounty Issues that have been selected by Preset and have a bounty attached.
Projects
None yet
9 participants