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] Fix indexpattern checks for missing references #88840

Merged
merged 13 commits into from
Jan 27, 2021

Conversation

dej611
Copy link
Contributor

@dej611 dej611 commented Jan 20, 2021

Summary

Fix #88786 , #89141

This PR addresses a regression on the indexpattern checks on the workspace side of the Lens editor.
For some operations, like the terms one, the indexpattern argument was required to perform a full check, and while this was correctly propagated on the dimension panel side, it was omitted when checking in the workspace.

This PR fixes this by adding the indexpattern as argument (when available).
Also a test to check for correct propagation has been added.

Screenshot 2020-11-02 at 12 05 27

Added

While working in the same area for the full reference operation fix, I've added also a fix for the #89141 bug.

If field is no longer valid it highlights it in the reference editor:

Screenshot 2021-01-25 at 18 50 54

Also the full reference operation is now validating against its internal sub-function as well and showing a warning sign in the panel:

Screenshot 2021-01-25 at 18 51 01

In case for some reason a saved chart gets into a state where there's a missing field and its saved operation is no longer valid, both fields gets highlighted now:

Screenshot 2021-01-25 at 18 52 12

Checklist

@dej611 dej611 added v8.0.0 release_note:skip Skip the PR/issue when compiling release notes Feature:Lens v7.12.0 labels Jan 20, 2021
@dej611 dej611 marked this pull request as ready for review January 20, 2021 16:46
@dej611 dej611 requested a review from a team January 20, 2021 16:46
@dej611 dej611 added the Team:Visualizations Visualization editors, elastic-charts and infrastructure label Jan 20, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

Tested on the same example as before and it worked as expected.

Comment on lines +873 to +877
// If we're transitioning to another operation, check for "new" incompleteColumns rather
// than "old" saved operation on the layer
const columnFinalRef =
layer.incompleteColumns?.[columnId]?.operationType || column.operationType;
const def = operationDefinitionMap[columnFinalRef];
Copy link
Contributor

Choose a reason for hiding this comment

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

This chunk could cause a merge conflict with my other open PR, but it should be fine to merge as-is and then fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But this is unchanged from master

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, checked your PR #88916 together with this one and it works as expected in all the various scenarios. So I'll skip to refactor this and approve your so the merge will provide a fix for both issues.

indexPattern?: IndexPattern
): string[] | undefined {
const errors: string[] = Object.entries(layer.columns)
.flatMap(([columnId, column]) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

So in terms of style, you're using flatMap and then filter as opposed to forEach- seems fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was just hoping to use a simple .filter(Boolean) at the end, but Typescript wasn't happy about that., therefore I had to god for an explicit typeguard.

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

Looks like in x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/index.ts the index pattern parameter for getErrorMessage is still marked as optional, it seems like we pass it in everywhere now so we can make it required, right?

@dej611
Copy link
Contributor Author

dej611 commented Jan 21, 2021

Not all definitions require the indexPattern as argument, I think it has been designed on the minimal set of arguments to work in general.
It could be imposed and just discard when not used.

@flash1293
Copy link
Contributor

@dej611 I meant this ? in particular:

The consumers don't have to use it, but they can be sure it will always be available if they need it.

@dej611
Copy link
Contributor Author

dej611 commented Jan 25, 2021

@elasticmachine merge upstream

@flash1293
Copy link
Contributor

@elasticmachine merge upstream

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

Tested and LGTM - I also checked the case we talked about (problem in a "hidden" dimension ) and it's not correctly propagated. I will open a separate issue for this

@dej611
Copy link
Contributor Author

dej611 commented Jan 25, 2021

@elasticmachine merge upstream

@dej611
Copy link
Contributor Author

dej611 commented Jan 25, 2021

I've added a couple more fixes in the area while debugging this PR.

@dej611
Copy link
Contributor Author

dej611 commented Jan 26, 2021

@elasticmachine merge upstream

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

I tested and it seems like the error is shown too often:

  • Create vis with "moving average of percentile of val"
  • Change "val" field to type string
  • Go back to Lens (shows as broken as expected)
  • Change oepration to "moving average of unique count of val.keyword"
  • Still shown as error

Even on recreating this configuration, the dimension is shown as error.

Uncaught error in the logs:

Uncaught (in promise) TypeError: Cannot read property 'getErrorMessage' of undefined
    at utils.ts:43
    at Array.map (<anonymous>)
    at isColumnInvalid (utils.ts:38)
    at dimension_panel.tsx:32
    at Object.useMemo (kbn-ui-shared-deps.js:375)
    at useMemo (kbn-ui-shared-deps.js:353)
    at IndexPatternDimensionTrigger (dimension_panel.tsx:32)
    at ua (kbn-ui-shared-deps.js:375)
    at Ga (kbn-ui-shared-deps.js:375)
    at qa (kbn-ui-shared-deps.js:375)

operationDefinition.getErrorMessage &&
operationDefinition.getErrorMessage(layer, columnId, indexPattern)
// check also references for errors
const referencesHaveErrors = (column as ReferenceBasedIndexPatternColumn).references
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: You don't need to cast here, 'references' in column && will do it in a type safe way

return !!(
operationDefinition.getErrorMessage &&
operationDefinition.getErrorMessage(layer, columnId, indexPattern)
// check also references for errors
Copy link
Contributor

Choose a reason for hiding this comment

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

Fine for now, but note: Once we introduce formula, we have to extend this to follow references through multiple columns, not just a single "hop"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've refactor that to be in a distinct function, so we could easily change it later.

@dej611
Copy link
Contributor Author

dej611 commented Jan 26, 2021

@flash1293 you are quite right. There was a missing .length there (the errors array was correctly empty). This should be fixed right now.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
lens 851.7KB 853.3KB +1.6KB

History

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

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

I manually tested both cases that you're fixing, and I'm glad you've added some unit tests for these cases. So LGTM!

@dej611 dej611 merged commit ba1e795 into elastic:master Jan 27, 2021
@dej611 dej611 deleted the fix/88786 branch January 27, 2021 13:23
jloleysens added a commit to jloleysens/kibana that referenced this pull request Jan 27, 2021
…y-tests

* 'master' of github.com:elastic/kibana: (276 commits)
  [Telemetry] Settings Collector: redact sensitive reported values (elastic#88675)
  [CI] Combines Jest test jobs (elastic#85850)
  [Upgrade Assistant] Migrate server to new es-js client (elastic#89207)
  Migrate maps_legacy, maps_oss, region_map, and tile_map plugions to TS projects (elastic#89351)
  [Vega Docs] Add experimental flag on the vega maps title (elastic#89402)
  Increase the time needed to locate the save viz toast (elastic#89301)
  [Enterprise Search] Add links to doc links service (elastic#89260)
  Fixed regex bug in Safari (elastic#89399)
  [Lens] Fix indexpattern checks for missing references (elastic#88840)
  [Lens] Clean up usage collector (elastic#89109)
  update apm index pattern (elastic#89395)
  [APM] Upgrade ES client (elastic#86594)
  Enable v2 so migrations, disable in FTR tests (elastic#89297)
  [Search Sessions] Make search session indicator UI opt-in, refactor per-app capabilities (elastic#88699)
  Cleanup OSS code from visualizations wizard (elastic#89092)
  [APM] Optimize API test order (elastic#88654)
  Rename conversion function, extract to module scope and add tests. (elastic#89018)
  [core.logging] Add ops logs to the KP logging system (elastic#88070)
  chore(NA): improve ts build refs performance on kbn bootstrap (elastic#89333)
  skip flaky suite (elastic#89379)
  ...

# Conflicts:
#	x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/timeline.tsx
#	x-pack/test/accessibility/config.ts
gmmorris added a commit to gmmorris/kibana that referenced this pull request Jan 27, 2021
…ana into task-manager/shift-on-trend

* 'task-manager/shift-on-trend' of github.com:gmmorris/kibana: (74 commits)
  [Metrics UI] Fix Host Overview boxes in Host Detail page (elastic#89299)
  [Telemetry] Settings Collector: redact sensitive reported values (elastic#88675)
  [CI] Combines Jest test jobs (elastic#85850)
  [Upgrade Assistant] Migrate server to new es-js client (elastic#89207)
  Migrate maps_legacy, maps_oss, region_map, and tile_map plugions to TS projects (elastic#89351)
  [Vega Docs] Add experimental flag on the vega maps title (elastic#89402)
  Increase the time needed to locate the save viz toast (elastic#89301)
  [Enterprise Search] Add links to doc links service (elastic#89260)
  Fixed regex bug in Safari (elastic#89399)
  [Lens] Fix indexpattern checks for missing references (elastic#88840)
  [Lens] Clean up usage collector (elastic#89109)
  update apm index pattern (elastic#89395)
  [APM] Upgrade ES client (elastic#86594)
  Enable v2 so migrations, disable in FTR tests (elastic#89297)
  [Search Sessions] Make search session indicator UI opt-in, refactor per-app capabilities (elastic#88699)
  Cleanup OSS code from visualizations wizard (elastic#89092)
  [APM] Optimize API test order (elastic#88654)
  Rename conversion function, extract to module scope and add tests. (elastic#89018)
  [core.logging] Add ops logs to the KP logging system (elastic#88070)
  chore(NA): improve ts build refs performance on kbn bootstrap (elastic#89333)
  ...
@wylieconlon
Copy link
Contributor

This PR was somehow missing a backport. Fixing now.

wylieconlon pushed a commit to wylieconlon/kibana that referenced this pull request Jan 28, 2021
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
wylieconlon pushed a commit that referenced this pull request Jan 28, 2021
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.12.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Error message for missing fields is not bubbled up from dimension level
5 participants