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

Timefilter should return strings instead of moments #25625

Merged
merged 3 commits into from
Nov 16, 2018

Conversation

lukasolson
Copy link
Member

@lukasolson lukasolson commented Nov 14, 2018

Fixes #25596.

Prior to this PR, if you had selected a time zone in your advanced settings other than your browser, then there was a possibility that the date histogram would show dates in your browser's time zone rather than the time zone you selected.

Part of the reason behind this is that the timefilter is inconsistent with what it returns in getTime. Sometimes it would return an object with from as a UTC string, and other times it would return a moment object.

There is some case that we're still debugging where the moment object gets stripped of its method properties, which in turns caused errors with the date histogram which attempts to call moment(result) with the resulting object, which in turn barfs inside the moment code because it's expecting function properties to be on the object which aren't actually there.

--- Edit: See this comment which explains when that happens. --

As a follow-up PR, we should probably go through all of the places where we conditionally handle moment objects and remove it, since they are already handling the case when strings are passed.

@lukasolson lukasolson added review Feature:Timepicker Timepicker v7.0.0 Team:Visualizations Visualization editors, elastic-charts and infrastructure v6.5.1 labels Nov 14, 2018
@lukasolson lukasolson self-assigned this Nov 14, 2018
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app

@elasticmachine
Copy link
Contributor

💔 Build Failed

@timroes
Copy link
Contributor

timroes commented Nov 14, 2018

Looks like legit test failures.

@spalger spalger added v6.5.1 and removed v6.5.1 labels Nov 14, 2018
@LeeDr
Copy link
Contributor

LeeDr commented Nov 14, 2018

@lukasolson I'd like this PR to include a test which would currently fail. I think it probably needs to be a UI functional test. It might be easy at the end of one of the Discover tests to go change the dateFormat:tz from UTC to some other timezone (maybe some place that doesn't use daylight savings time like Arizona?) and then go back to discover and check the timestamp of a particular doc while using an absolute time range. With this bug it would probably fail everywhere except when run in that timezone. So maybe we need to pick a timezone where none of our team lives for the test...

@elasticmachine
Copy link
Contributor

💔 Build Failed

@spalger
Copy link
Contributor

spalger commented Nov 14, 2018

Please merge master to get CI working

@elasticmachine
Copy link
Contributor

💔 Build Failed

@lukasolson
Copy link
Member Author

So I spent some more time digging today and it looks like this was introduced in #21827. Prior to that pull, the timeRange was not an agg param. This is important because agg params are passed through cloneDeep, which is where the moment objects were stripped of their functions. (Interestingly enough, this behavior was changed in a new version of lodash, so that even functions on an object's prototype are cloned.)

@elasticmachine
Copy link
Contributor

💔 Build Failed

@lukasolson
Copy link
Member Author

retest

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@Bargs
Copy link
Contributor

Bargs commented Nov 15, 2018

I am still able to reproduce the bug. Seems to involve switching between quick and absolute time ranges:

nov-15-2018 08-08-42

@@ -103,15 +103,15 @@ module.directive('kbnTimepicker', function (refreshIntervals) {
return;
}

_.set($scope, 'browserAbsolute.from', new Date(newDate.year(), newDate.month(), newDate.date()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change and the one below will reintroduce #5370 which was fixed by #11773.

if (moment.isMoment(date) && $scope.mode === TIME_MODES.ABSOLUTE) {
$scope.absolute.to = date;
if (date && $scope.mode === TIME_MODES.ABSOLUTE) {
$scope.absolute.to = moment.isMoment(date) ? date.toISOString() : date;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If date is not a moment object, we simply return it. Could date be a native javascript date? Seems we should ensure we're returning a string no matter what.

@lukasolson lukasolson removed the review label Nov 15, 2018
@lukasolson lukasolson changed the title Timepicker should return strings instead of moments Timefilter should return strings instead of moments Nov 15, 2018
@lukasolson
Copy link
Member Author

@Bargs This is ready for another look

@lukasolson
Copy link
Member Author

@LeeDr I've added the functional tests. They test in multiple timezones so that it shouldn't pass/fail depending on which timezone you actually live in.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM. Tested locally, compared to master, can verify that the issue is present on master but not in this PR.

Copy link
Member

@tsullivan tsullivan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lukasolson lukasolson merged commit 9325e94 into elastic:master Nov 16, 2018
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

lukasolson added a commit that referenced this pull request Nov 16, 2018
* fix timefilter to return strings instead of moment objects

* add functional test

* remove unused functions
lukasolson added a commit that referenced this pull request Nov 16, 2018
* fix timefilter to return strings instead of moment objects

* add functional test

* remove unused functions
@lukasolson
Copy link
Member Author

6.5 (6.5.2): 3058792
6.x (6.6.0): e23ef0e

@lukasolson lukasolson deleted the fix/timepicker-absolute branch December 2, 2019 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Timepicker Timepicker Team:Visualizations Visualization editors, elastic-charts and infrastructure v6.5.2 v6.6.0 v7.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants