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

[Lens] Bind all time fields to the time picker #63874

Merged
merged 34 commits into from
Apr 30, 2020

Conversation

timroes
Copy link
Contributor

@timroes timroes commented Apr 17, 2020

This changes esaggs and Lens to support auto date histograms on any time field the user wants:

Screenshot 2020-04-27 20 35 59

Fixes #63868

TODO:

  • Lens tests
  • Migration of Lens saved object
    • Remove lens_auto_date from expression
    • Specify all used date_fields in date_histograms as timeField parameters
    • Provide tests for Migrations
  • Solve problem with single bars hiding

Checklist

@@ -65,12 +75,15 @@ interface Arguments {
partialRows: boolean;
includeFormatHints: boolean;
aggConfigs: string;
timeField?: string[];
Copy link
Member

Choose a reason for hiding this comment

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

remove ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The parameter is not defined is required in the definition below, so it can be skipped and thus can be undefined. Actually the typing of the other parameters here is wrong, because they should also all have ? or being marked as required: true in their definition, but I didn't want to fix this in this PR.

Copy link
Member

Choose a reason for hiding this comment

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

so we have timeField and timeFields ?

Copy link
Member

Choose a reason for hiding this comment

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

Actually the typing of the other parameters here is wrong, because they should also all have ? or being marked as required: true in their definition, but I didn't want to fix this in this PR.

@timroes This actually highlights weird thing about the Expression function typings which I don't think we have been doing consistently:

The types are what get enforced inside the function body. So while any arg with default: 'whatever' set is technically optional for users of the expression function, once you are inside the expression function itself, if it is not marked with ? in the arguments interface, TS will warn that the arg can be possibly undefined (since TS doesn't know that the defaults get injected at runtime).

So which is right? Do we write the typings to be accurate for the users of the functions (which means lots of ?), at the expense of function authors needing a lot of unnecessary if (args.whatever) checks, or args.whatever! ... Or do we write the typings to be accurate for the function authors, at the expense of users of the functions not having accurate typings?

IMO your proposed approach is probably better (include ? if there's a default or no required: true). It just means needing to update many of our function definitions (including Canvas functions which seem to have this discrepancy as well).

Copy link
Member

Choose a reason for hiding this comment

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

^ Thinking about this more, in ExpressionFunctionDefinition we might be able to enforce the presence of required: true for non-optional args.

At any rate; that's a topic for a different thread 🙂

@@ -19,6 +19,11 @@

import { TabifyBuckets } from './buckets';
import { AggGroupNames } from '../aggs';
import moment from 'moment';

interface Bucket {
Copy link
Member

Choose a reason for hiding this comment

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

defining an interface in tests ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous definition is any and I just didn't want to continue using any below. I could have also inlined this type, but since I used it in multiple places just defined it as an interface on top.

Copy link
Member

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

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

looked at it quickly and seems good

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@lizozom lizozom left a comment

Choose a reason for hiding this comment

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

Added a few comment

import { getSearchService, getQueryService, getIndexPatterns } from '../../services';
import { buildTabularInspectorData } from './build_tabular_inspector_data';
import { getRequestInspectorStats, getResponseInspectorStats, serializeAggConfig } from './utils';
import { calculateBounds, getTimeForField } from '../../query/timefilter/get_time';
Copy link
Contributor

Choose a reason for hiding this comment

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

//nit

Should be exported from ../../query

timeFields && timeFields.length > 0
? timeFields
: [
indexPattern?.fields.find(field => field.name === indexPattern.timeFieldName)?.name,
Copy link
Contributor

Choose a reason for hiding this comment

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

indexPattern.getTimeField

return getTime(searchSource.getField('index'), timeRange);
return allTimeFields
.map(fieldName => getTimeForField(indexPattern, timeRange, fieldName))
.filter((rangeFilter): rangeFilter is RangeFilter => Boolean(rangeFilter));
Copy link
Contributor

Choose a reason for hiding this comment

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

//nit
Maybe simplify with isRangeFilter?


return createTimeRangeFilter(indexPattern, timeRange, field);
}

export function getTime(
Copy link
Contributor

Choose a reason for hiding this comment

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

getTimeFilter \ getTimeFilterDefault :)

Copy link
Member

Choose a reason for hiding this comment

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

++ The naming getTime and getTimeFilter is a bit unclear.

another nit - It would also be nice to maybe add an explanatory comment to each of the functions here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just took a harder look at this, thanks for the prodding to do this. The naming confusion was because both functions were basically 90% similar code with one extra input, so I've condensed these into the same function with an options argument instead of positional arguments.

@@ -153,20 +153,6 @@ export function tabifyAggResponse(
doc_count: esResponse.hits.total,
};

let timeRange: TabbedRangeFilterParams | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

yay

@timroes
Copy link
Contributor Author

timroes commented Apr 22, 2020

@elasticmachine merge upstream

Copy link
Member

@ppisljar ppisljar 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

@mbondyra
Copy link
Contributor

Tested in Lens in commit "Add full migration"

  1. migrations (from master -> this PR) date histogram with multiple layers both for primary and non-primary timefield, with auto interval and custom interval.
  2. the behaviour for for primary and non-primary timefield with verifying correct datatable returned
  3. Just in case, vertical bar date histogram visualization (not Lens)

@wylieconlon
Copy link
Contributor

Fixed the bug in both the Lens migration and the unmigrated Lens expression. It turns out that timeField was the expected argument to esaggs, and I had migrated it to use timeFields causing the errors.

Copy link
Contributor

@mbondyra mbondyra left a comment

Choose a reason for hiding this comment

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

tested locally, LGTM 🆗

@mbondyra mbondyra requested review from lizozom and ppisljar April 29, 2020 14:31
Copy link
Member

@ppisljar ppisljar 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


return createTimeRangeFilter(indexPattern, timeRange, field);
}

export function getTime(
Copy link
Member

Choose a reason for hiding this comment

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

++ The naming getTime and getTimeFilter is a bit unclear.

another nit - It would also be nice to maybe add an explanatory comment to each of the functions here.

@@ -59,18 +68,21 @@ const name = 'esaggs';
type Input = KibanaContext | null;
type Output = Promise<KibanaDatatable>;

interface Arguments {
export interface Arguments {
Copy link
Member

Choose a reason for hiding this comment

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

Why does this need to be exported now? (I might have missed it)

@wylieconlon
Copy link
Contributor

I think I've resolved all of the naming comments that I could find. Thanks for bringing them up- @lukeelmers @lizozom if you want to review again, feel free.

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.

Thanks @wylieconlon, I think those changes make things much clearer!

Otherwise, the code here LGTM (I only reviewed updates to the data plugin).

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@wylieconlon wylieconlon merged commit 9b65cbd into elastic:master Apr 30, 2020
wylieconlon added a commit to wylieconlon/kibana that referenced this pull request Apr 30, 2020
* Bind non primary time fields to timepicker

* Fix typescript argument types

* Allow auto interval on all fields

* Remove lens_auto_date function

* Fix existing jest tests and add test todos

* Remove lens_auto_date from esarchives

* Add TimeBuckets jest tests

* Fix typo in esarchiver

* Address review feedback

* Make code a bit better readable

* Fix default time field retrieval

* Fix TS errors

* Add esaggs interpreter tests

* Change public API doc of data plugin

* Add toExpression tests for index pattern datasource

* Add migration stub

* Add full migration

* Fix naming inconsistency in esaggs

* Fix naming issue

* Revert archives to un-migrated version

* Ignore expressions that are already migrated

* test: remove extra spaces and  timeField=\\"products.created_on\\"} to timeField=\"products.created_on\"}

* Rename all timeField -> timeFields

* Combine duplicate functions

* Fix boolean error and add test for it

* Commit API changes

Co-authored-by: Wylie Conlon <wylieconlon@gmail.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Marta Bondyra <marta.bondyra@elastic.co>
gmmorris added a commit to gmmorris/kibana that referenced this pull request Apr 30, 2020
* master: (42 commits)
  [Ingest] Allow aggent to send metadata compliant with ECS (elastic#64452)
  [Endpoint] Remove todos, urls to issues (elastic#64833)
  [Uptime] Remove hard coded value for monitor states histograms (elastic#64396)
  Feature/send feedback link (elastic#64845)
  [ML] Moving get filters capability to admin (elastic#64879)
  Remove edit alert button from alerts list (elastic#64643)
  [EPM] Handle constant_keyword type in KB index patterns and ES index templates (elastic#64876)
  [ML] Disable data frame anaylics clone button based on permission (elastic#64830)
  Dashboard url generator to preserve saved filters from destination dashboard (elastic#64767)
  add generic typings for SavedObjectMigrationFn (elastic#63943)
  Allow to define and update a defaultPath for applications (elastic#64498)
  [Event Log] add rel=primary to saved objects for query targets (elastic#64615)
  [Lens] Use a size of 5 for first string field in visualization (elastic#64726)
  [SIEM][Lists] Removes plugin dependencies, adds more unit tests, fixes more TypeScript types
  [Ingest] Edit datasource UI (elastic#64727)
  [Lens] Bind all time fields to the time picker (elastic#63874)
  [Lens] Use suggestion system in chart switcher for subtypes (elastic#64613)
  Improve alpha messaging (elastic#64692)
  [Ingest] Allow to enable monitoring of elastic agent (elastic#63598)
  [Metrics UI] Fix alerting when a filter query is present (elastic#64575)
  ...
wylieconlon pushed a commit that referenced this pull request Apr 30, 2020
* [Lens] Bind all time fields to the time picker (#63874)

* Bind non primary time fields to timepicker

* Fix typescript argument types

* Allow auto interval on all fields

* Remove lens_auto_date function

* Fix existing jest tests and add test todos

* Remove lens_auto_date from esarchives

* Add TimeBuckets jest tests

* Fix typo in esarchiver

* Address review feedback

* Make code a bit better readable

* Fix default time field retrieval

* Fix TS errors

* Add esaggs interpreter tests

* Change public API doc of data plugin

* Add toExpression tests for index pattern datasource

* Add migration stub

* Add full migration

* Fix naming inconsistency in esaggs

* Fix naming issue

* Revert archives to un-migrated version

* Ignore expressions that are already migrated

* test: remove extra spaces and  timeField=\\"products.created_on\\"} to timeField=\"products.created_on\"}

* Rename all timeField -> timeFields

* Combine duplicate functions

* Fix boolean error and add test for it

* Commit API changes

Co-authored-by: Wylie Conlon <wylieconlon@gmail.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Marta Bondyra <marta.bondyra@elastic.co>

* fix: fix migration

* types fix

Co-authored-by: Tim Roes <tim.roes@elastic.co>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Marta Bondyra <marta.bondyra@elastic.co>
jloleysens added a commit to jloleysens/kibana that referenced this pull request May 4, 2020
…bana into pipeline-editor-part-mvp-2

* 'feature/ingest-node-pipelines' of github.com:elastic/kibana: (90 commits)
  remove unused import
  address review feedback
  [Ingest pipelines] Cleanup (elastic#64794)
  [Ingest] Edit datasource UI (elastic#64727)
  [Lens] Bind all time fields to the time picker (elastic#63874)
  [Lens] Use suggestion system in chart switcher for subtypes (elastic#64613)
  Improve alpha messaging (elastic#64692)
  [Ingest] Allow to enable monitoring of elastic agent (elastic#63598)
  [Metrics UI] Fix alerting when a filter query is present (elastic#64575)
  skip flaky suite (elastic#64812) (elastic#64723)
  [Maps] do not display EMS or kibana layer wizards when not configured (elastic#64554)
  [Reporting/Test] Convert functional test code to Typescript (elastic#64601)
  make inserting timestamp with navigate methods optional with default true (elastic#64655)
  [EPM] Update UI to handle package versions and updates (elastic#64689)
  Minimize dependencies required by our telemetry middleware (elastic#64665)
  [Telemetry] oss api tests (elastic#64602)
  [ML] Adding endpoint capability checks (elastic#64662)
  Update jest config for coverage (elastic#64648)
  [SIEM][NP] Fixes bug in ML signals promotion (elastic#64720)
  share single data plugin bundle (elastic#64549)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Lens release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.8.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bind non primary timefields to timepicker in Lens
8 participants