elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.69k stars 8.24k forks source link

Global time range in URL overwritten in certain situations. #21326

Closed walterra closed 6 years ago

walterra commented 6 years ago

Found in version

Browser

Steps to reproduce

Expected result

Actual result

image

Additional information

elasticmachine commented 6 years ago

Pinging @elastic/ml-ui

stacey-gammon commented 6 years ago

Sorry for causing this with my PR. I thought that the fix would bring the logic back to where it was prior to June 26th, when angular was removed from the time picker.

Sounds like ML jobs and dashboards stored with time work similarly - when you open them, they should adjust the time, both in the UI and in the URL. That broke for dashboards when angular was removed from the time picker (the URL and the UI got out of sync). My change to fix that was to sync the URL with the UI state. The problem was that it wasn't being initialized on page load.

I'm technically off today but can help more on Monday, and spend some time investigating (or if I find time later today).

stacey-gammon commented 6 years ago

Assuming we start out with timefilter set to Time A. Opening a job URL set to Time B goes through this flow:

  1. State.$routeChangeStart
  2. this.emit('fetch_with_changes', diffResults.keys); because URL Time changed to Time B.
  3. kbnGlobalTimePicker is initialized
  4. updateGlobalStateWithTime sets globalState to that stored in timefilter (Time A).
  5. globalState.on('fetch_with_changes', function () { syncs timefilter to globalState, but that is now Time A, not Time B.

Why does this work for dashboards?

Assuming we start out with timefilter set to Time A and we open a dashboard with time stored as Time B. Dashboards soft refresh goes like this:

  1. this.emit('fetch_with_changes', diffResults.keys); with Time B (same as above). 2. dashboardStateManager.syncTimefilterWithDashboard(_timefilter.timefilter, config.get('timepicker:quickRanges')); updates timefilter to what is stored in the dashboard
  2. kbnGlobalTimePicker is initialized

Step 2 stops this bug from appearing because dashboard manually syncs the timefilter to the saved time.

What about when we edit the URL directly, how come the bug doesn't appear then?

In that case kbnGlobalTimePicker is not initialized so we don't hit the bug.

I can actually reproduce this bug now excluding ML completely:

  1. Open up a dashboard and set time to Time A
  2. Copy the url, paste into an editor, change the global time to Time B.
  3. Go to dashboard listing page.
  4. Paste the URL into the browser

You'll get a soft refresh that causes the kbnGlobalTimePicker to be re-initialized and the url will end up re-syncing with Time A and losing Time B.

stacey-gammon commented 6 years ago

Not sure of a fix yet, but I think this is not related to ML so I edited the title and labels. It's really a platform/discover team thing, but the de-angularization of time picker was taken on by the Sharing team, as was the fix that caused this additional blocker, so I supposed it's up to us to find a short term solution for 6.4.

Long term, I think this is yet another example of how the tech debt in this area is causing us lost productivity.

nreese commented 6 years ago

@walterra Can you give this change a try - https://github.com/elastic/kibana/pull/21440. It should fix the problems you were seeing

walterra commented 6 years ago

@nreese can confirm that this fixes the issue for me, great!