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

Deprecate DataView.flattenHit in favor of data plugin flattenHit #114517

Merged
merged 15 commits into from
Oct 14, 2021

Conversation

timroes
Copy link
Contributor

@timroes timroes commented Oct 11, 2021

Summary

We currently have too many flattenHit implementations in Kibana. After talking with @ppisljar we decided to deprecate the one in index patterns data views, and instead get people to use the one from the data plugin (from tabifyDocs).

This PR solves solves those things:

  • Deprecate the flattenHit implementation in data view in favor of the one from the data plugin.
  • Make Discover use the flattenHit from the data plugin.
  • Remove the flattenHitWrapper API that was only used in Discover from the data plugin.

There are a couple of changes I made, please have a look at my inline comments in this PR, but the actual functionality should not be affected by this PR and the expectations would be, that everything works the same as beforehand.

⚠️ There is one main difference that I did not moved over to the new implementation. The old implementation converted arrays of single elements into flat values (relevant code). I could not find any difference in behavior without this while testing different field formatters, filtering, etc. Thus I decided to leave it out, unless someone still knows why this would be needed.

For reviewers: Ideally hide whitespace changes when reviewing code, there are a lot of indentation changes.
For testers: To test this, you should make sure documents in Discover are still shown correctly under all circumstances. Also please make sure CSV export is still working as expected.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@timroes timroes added Feature:Discover Discover Application buildkite-ci Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. labels Oct 11, 2021
@timroes
Copy link
Contributor Author

timroes commented Oct 12, 2021

@elasticmachine merge upstream

@timroes
Copy link
Contributor Author

timroes commented Oct 13, 2021

@elasticmachine merge upstream

hits: {
hits: [
describe('tabify_docs', () => {
describe('flattenHit', () => {
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 moved the tests from the flattenHit implementation in data view over here, so they will also be applied to this implementation.

},
},
},
metaFields: ['_id', '_index', '_score', '_type'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ℹ️ Since the implementation now uses the metaFields from the index pattern (which are set from the metaFields advanced setting), tests must correctly set those.

return flat;
// Merge all valid meta fields into the flattened object
// expect for _source (in case that was specified as a meta field)
indexPattern?.metaFields?.forEach((metaFieldName) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ℹ️ So far the implementation in the data plugin just hard-coded loaded a couple of meta fields. We have an advanced setting for this, that should be used, so changing this implementation to read the metaFields from the index pattern (which is fed by that advanced setting - and also will leave us the possibility to later make that an index pattern level setting).

// Merge all valid meta fields into the flattened object
// expect for _source (in case that was specified as a meta field)
indexPattern?.metaFields?.forEach((metaFieldName) => {
if (!isValidMetaFieldName(metaFieldName) || metaFieldName === '_source') {
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 am filtering out for valid metaField names now. The data view implementation did not do that. This will prevent TypeScript from complaining here, and also potentially add a bit safetyness to not mess up objects completely.


// Use a proxy to make sure that keys are always returned in a specific order,
// so we have a guarantee on the flattened order of keys.
return new Proxy(flat, {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ℹ️ This has been added via #93344 and so I also added it to this implementation now.

@@ -17,6 +17,17 @@ import { esHits } from '../../../__mocks__/es_hits';
import { indexPatternMock } from '../../../__mocks__/index_pattern';
import { DiscoverGridContext } from './discover_grid_context';

const baseContextMock = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ℹ️ This is a left over of an slightly different implementation I went with originally, but since it's deduplicating some code, I decided to leave it in this PR.

source?: boolean;
meta?: boolean;
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 removed this parameter. All places that are using this are requiring meta to be loaded. Also I couldn't find any place we flatten documents in Kibana, where we don't want this. So removing this for now, until we really have a use-case for this.

Comment on lines +474 to +476
"__html": Array [
100,
],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ℹ️ This change in snapshot is caused by the change described in the PR, of single element arrays no longer being unwrapped.

Copy link
Member

Choose a reason for hiding this comment

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

this is a more accurate behavior 👍

@timroes timroes added auto-backport Deprecated - use backport:version if exact versions are needed release_note:skip Skip the PR/issue when compiling release notes labels Oct 13, 2021
@timroes timroes marked this pull request as ready for review October 13, 2021 09:33
@timroes timroes requested review from a team as code owners October 13, 2021 09:33
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

@timroes timroes changed the title [Discover] Deprecate indexPattern.flattenHit [skip ci] [Discover] Deprecate indexPattern.flattenHit Oct 13, 2021
@timroes timroes changed the title [Discover] Deprecate indexPattern.flattenHit Deprecate DataView.flattenHit in favor of data plugin flattenHit Oct 13, 2021
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

@timroes
Copy link
Contributor Author

timroes commented Oct 13, 2021

Buildkite, test this

Anyway waiting for review, so I try to turn this 💛 into a 💚

@majagrubic
Copy link
Contributor

I've tested this quite extensively and all seems to be working fine. Working through the code still.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
data 2807 2803 -4

Async chunks

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

id before after diff
discover 327.7KB 327.8KB +76.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
data 465.1KB 465.5KB +444.0B
dataViews 38.6KB 38.5KB -86.0B
total +358.0B
Unknown metric groups

References to deprecated APIs

id before after diff
dataViews 228 236 +8
discover 1821 1801 -20
maps 1689 1697 +8
total -4

History

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

Copy link
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

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

I read the code for reporting and changes LGTM. It's a little tricky to evaluate whether there is a regression since I'm not very familiar with flattenHit but I did a local test of CSV generation it worked as expected 👍🏻 .

@@ -75,6 +75,7 @@ const mockSearchSourceGetFieldDefault = jest.fn().mockImplementation((key: strin
getByName: jest.fn().mockImplementation(() => []),
getByType: jest.fn().mockImplementation(() => []),
},
metaFields: ['_id', '_index', '_type', '_score'],
Copy link
Contributor

Choose a reason for hiding this comment

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

I did a grep on the code, looks like these are still present on the deprecated csv export type that is using another implementation of flattenHits that I am guessing will be removed at a future date when that export type is removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the legacy csv implementation actually is something we need/started discussing parallel to this, if this still needs to be adjusted to changes we will make from now on to this, or if we're fine with them diverging from each other.

@timroes timroes merged commit b21e1eb into elastic:master Oct 14, 2021
@timroes timroes deleted the dataview/flatten-hit-deprecation branch October 14, 2021 12:43
@kibanamachine
Copy link
Contributor

💔 Backport failed

Status Branch Result
7.x Commit could not be cherrypicked due to conflicts

To backport manually run:
node scripts/backport --pr 114517

timroes pushed a commit that referenced this pull request Oct 14, 2021
…4517) (#114991)

* WIP replacing indexPattern.flattenHit by tabify

* Fix jest tests

* Read metaFields from index pattern

* Remove old test code

* remove unnecessary changes

* Remove flattenHitWrapper APIs

* Fix imports

* Fix missing metaFields

* Add all meta fields to allowlist

* Improve inline comments

* Move flattenHit test to new implementation

* Add deprecation comment to implementation

Co-authored-by: Kibana Machine <[email protected]>
# Conflicts:
#	src/plugins/data_views/public/index.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed buildkite-ci Feature:Discover Discover Application release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. v7.16.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants