-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Deprecate DataView.flattenHit in favor of data plugin flattenHit #114517
Conversation
@elasticmachine merge upstream |
…/kibana into dataview/flatten-hit-deprecation
@elasticmachine merge upstream |
hits: { | ||
hits: [ | ||
describe('tabify_docs', () => { | ||
describe('flattenHit', () => { |
There was a problem hiding this comment.
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'], |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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, { |
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
"__html": Array [ | ||
100, | ||
], |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 👍
Pinging @elastic/kibana-data-discovery (Team:DataDiscovery) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code LGTM
Buildkite, test this Anyway waiting for review, so I try to turn this 💛 into a 💚 |
I've tested this quite extensively and all seems to be working fine. Working through the code still. |
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Async chunks
Page load bundle
Unknown metric groupsReferences to deprecated APIs
History
To update your PR or re-run it, just comment with: |
There was a problem hiding this 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'], |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
💔 Backport failed
To backport manually run: |
…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
Summary
We currently have too many
flattenHit
implementations in Kibana. After talking with @ppisljar we decided to deprecate the one inindex patternsdata views, and instead get people to use the one from the data plugin (fromtabifyDocs
).This PR solves solves those things:
flattenHit
implementation in data view in favor of the one from the data plugin.flattenHit
from the data plugin.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.
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.
[ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support[ ] Documentation was added for features that require explanation or tutorials[ ] Any UI touched in this PR is usable by keyboard only (learn more about keyboard accessibility)[ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: FF, Chrome)[ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the docker list[ ] This renders correctly on smaller devices using a responsive layout. (You can test this in your browser)[ ] This was checked for cross-browser compatibilityFor maintainers
[ ] This was checked for breaking API changes and was labeled appropriately