Skip to content

Add "use time filter" option to input controls - #15852

Merged
nreese merged 6 commits into
elastic:masterfrom
nreese:useTimefilter
Jan 16, 2018
Merged

nreese merged 6 commits into
elastic:masterfrom
nreese:useTimefilter

Conversation

@nreese

@nreese nreese commented Jan 4, 2018 •

Copy link
Copy Markdown
Contributor

partial fix for #14659

Add use time filter option to input controls. When set to true, Controls will use the global time when fetching terms and min/max values.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of using JSON.stringify to determine if the time filter's changed, can we use _.clone and _.isEqual instead?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are we going to miss potential new items when using a relative time range, as the this.vis.API.timeFilter.time will be equal, but the underlying data ranges will differ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right now there is no way knowing if the render method is getting called because the timefilter updated. I thought comparing the time would work but you are right that when data is fetched for a relative time range then this strategy breaks down. Any ideas on how to handle relative dates?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's the downside to rendering every-time render is called? Does this cause the data to be fetched again, and we're trying to prevent this when it's unnecessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

exactly. Each time the component is drawn, then the terms agg or min/max agg will be required.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

timefilter has a getBounds method call. I can just watch the results of that instead. Also, I am going to move that logic into https://github.com/elastic/kibana/blob/master/src/ui/public/vis/update_status.js. That way the status parameter will just contain a time key that will be set to true or false.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should rely on Elasticsearch to cache what it can and make our requests as fast as possible. Trying to dedupe things client side (especially per visualization) seems like it will be very tricky to get right in all scenarios if not impossible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should rely on Elasticsearch to cache what it can and make our requests as fast as possible. Trying to dedupe things client side (especially per visualization) seems like it will be very tricky to get right in all scenarios if not impossible.

Agreed. I'm not aware of us doing this for other visualizations, was there a specific reason why Input Controls should be the exception to this @nreese?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Other visualizations do have custom logic to render under certain conditions. Visualizations are passed a status object to know why render is getting called. For example, the map visualization does different things based on the contents of status.

I created a new PR that adds time to the status object so all time change logic can be removed from vis_controller.js

@nreese

nreese commented Jan 8, 2018

Copy link
Copy Markdown
Contributor Author

@kobelb I removed the time checking logic since it's now provided by the status object. Let me know if there are any other changes needed.

@kobelb

kobelb commented Jan 8, 2018

Copy link
Copy Markdown
Contributor

@nreese when I add the input control that uses the timefilter to a Dashboard, I'm still seeing it hit the early return when subsequently searching, this is going to cause the user to not see "new" values show up in the input control.

@kobelb

kobelb commented Jan 9, 2018

Copy link
Copy Markdown
Contributor

@nreese I stand corrected, LGTM

@kobelb kobelb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@nreese
nreese requested review from thomasneirynck and removed request for stacey-gammon January 9, 2018 16:01

@thomasneirynck thomasneirynck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm.

I'd consider explaining the option better, either with a longer label or info-hover over. I'm not sure "use time filter" will make sense to a user without context.

@nreese
nreese requested a review from lukasolson January 11, 2018 23:20
@nreese

nreese commented Jan 12, 2018

Copy link
Copy Markdown
Contributor Author

@thomasneirynck I think you are right that an info description is needed for better explanation. This visualization is all react based so I can not use the angular kbn-info directive. I will create an info component in EUI. Should I delay this PR until that component is available or merge this PR as is and open an issue to add the info section once the EUI component is available?

@nreese
nreese merged commit 0c907ba into elastic:master Jan 16, 2018
nreese added a commit to nreese/kibana that referenced this pull request Jan 16, 2018
* add useTimeFilter parameter to Controls visualization

* fix broken jest test

* add functional tests for useTimeFilter

* remove wrong comment

* use _.clone and _.isEqual for time comparision

* do not track time changes in vis_controller - use status.time instead
@nreese

nreese commented Jan 16, 2018

Copy link
Copy Markdown
Contributor Author

@thomasneirynck Issue #16072 created to track Use time filter description.

nreese added a commit that referenced this pull request Jan 16, 2018
* add useTimeFilter parameter to Controls visualization

* fix broken jest test

* add functional tests for useTimeFilter

* remove wrong comment

* use _.clone and _.isEqual for time comparision

* do not track time changes in vis_controller - use status.time instead
@robcowart

Copy link
Copy Markdown

@nreese. Playing around with this feature, when enabled, it looks like it causes the visualization to pickup more than just the time to determine the list of items displayed. It also restricts the list by all of the global filters. This is not necessarily a bad thing. In fact I find it useful as it behaves like https://github.com/robcowart/kibana-vis-dropdown. I do however wish that I could set this on a per element basis.

Consider this... I have a dropdown with for Hosts(A) and a dropdown for Interfaces(B). If I could set A to ignore the global filter it would give me a list of all hosts.

screen shot 2018-02-22 at 17 12 05

When I pick a host in A it would set a global filter for the host. If B is set with to respect the global filter, it would now contain a list of interfaces only from the host selected in A.

screen shot 2018-02-22 at 17 13 10

As you can see from the screenshots, I tried to achieve this by creating two separate input control visualizations. One for Nodes, one for Interfaces. However in practice this doesn't work because the visualizations will overwrite each other's filter.

So to achieve such dependency-based input controls, either...

  • It must be possible set whether to ignore global settings per input element within a single visualization.
    or
  • If each input control visualization instance needs to be able to set its own independent filter instances and keep track of them. (this is how the plugin I linked to above works)

@nreese

nreese commented Feb 22, 2018 •

Copy link
Copy Markdown
Contributor Author

Yes, the implementation in 6.2 is broken and picks up all global attributes.

//Broken implemenation
if (!useTimeFilter) {
  searchSource.inherits(false); //Do not filter by time so can not inherit from rootSearchSource
}

This has been fixed in 6.3, and now only the time filter is added instead of just inheriting from the root search source. The bug was fixed when refactoring for nested input controls #16407.

  searchSource.inherits(false);
  searchSource.filter(() => {
    const activeFilters = [...filters];
    if (useTimeFilter) {
      activeFilters.push(kbnApi.timeFilter.get(indexPattern));
    }
    return activeFilters;
  });

Maybe nested input controls solve your other problems as well?

@robcowart

robcowart commented Feb 22, 2018 •

Copy link
Copy Markdown

Got it. Of course that begs the follow on question. Is there an issue open to optionally allow an element to apply the global filter? As I mention this could make possible dependent elements as I show above. This feature is listed in #13911, but I don't see an issue open for it.

@nreese

nreese commented Feb 22, 2018

Copy link
Copy Markdown
Contributor Author

#16061

@robcowart

Copy link
Copy Markdown

That isn't the same thing and doesn't achieve dependency between two input control elements. The Kibana Advanced Setting filters:pinnedByDefault to true is the first change I make after installing Kibana, so filters set by Input Controls were always pinned for me. If input controls are "fixed" to ignore the global filter, then you can't leverage the global filter, pinned or not, to achieve dependency that I can see.

patrykkopycinski pushed a commit to patrykkopycinski/kibana that referenced this pull request May 6, 2026
* add useTimeFilter parameter to Controls visualization

* fix broken jest test

* add functional tests for useTimeFilter

* remove wrong comment

* use _.clone and _.isEqual for time comparision

* do not track time changes in vis_controller - use status.time instead
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants