-
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
[data.search.aggs] Remove fieldFormats from AggConfig & AggConfigs #69762
Conversation
if (Object.keys(format).length < 1) { | ||
// If no format exists, fall back to string as a default | ||
format = { id: 'string' }; | ||
} |
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 fallback behavior existed previously in agg.fieldFormatter()
so we need to replicate it here or empty serialized formats ({}
) don't receive any formatting, like -
for an empty value.
/** @internal */ | ||
export const createFilterHistogram = (getInternalStartServices: GetInternalStartServicesFn) => { |
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.
Now that we don't have aggConfig.fieldFormatter
, these need to be wrapped in a provider function so that getInternalStartServices
can be passed in to access fieldFormats.deserialize
instead. (This is also one of the reasons agg types still depend on field formats, even though agg configs & agg config doesn't)
expect(filter).toHaveProperty('range'); | ||
expect(filter).toHaveProperty('meta'); | ||
expect(filter.meta).toHaveProperty('index', '1234'); | ||
expect(filter.range).toHaveProperty('bytes'); | ||
expect(filter.range.bytes).toHaveProperty('gte', 1024.0); | ||
expect(filter.range.bytes).toHaveProperty('lt', 2048.0); | ||
expect(filter.meta).toHaveProperty('formattedValue', '≥ 1,024 and < 2,048'); | ||
expect(filter.meta).toHaveProperty('formattedValue'); |
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.
We are no longer testing for specific values here since the mocks aren't returning any real values, but I don't think they were the right thing to test here anyway. Instead I'm just making sure a formattedValue is included, and also verifying that fieldFormats.deserialize
was called as expected. Whether the values are deserialized correctly is something to test in field formats.
deserialize: jest.fn().mockImplementation(() => { | ||
const DefaultFieldFormat = FieldFormat.from(identity); | ||
return new DefaultFieldFormat(); | ||
}), |
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.
Added a mock implementation to improve these somewhat. I just stole this from the getFormat
function inside of fieldFormats.deserialize
.
Important to note that since this is configured with identity
, any calls against this mock are just going to return whatever they are given. So you'll get a convert
function you can use, but of course it won't actually convert what you give to it.
type: { | ||
id: 'bytes', | ||
}, | ||
toJSON: () => ({ id: 'bytes' }), |
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.
These mocks were changed because this is basically the only part of field formats that AggConfig cares about: getting the serialized format for the field from the provided index pattern
@@ -54,6 +54,7 @@ export const getGeoHashBucketAgg = ({ getInternalStartServices }: GeoHashBucketA | |||
{ | |||
name: BUCKET_TYPES.GEOHASH_GRID, | |||
title: geohashGridTitle, | |||
makeLabel: () => geohashGridTitle, |
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.
Though not directly related to the other items in this PR, I added these makeLabel
methods to geo hash & filter aggs in this PR because I noticed they were missing, which causes column headers to be unformatted in the inspector.
864f503
to
bf8e6de
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bf8e6de
to
b035324
Compare
Pinging @elastic/kibana-app-arch (Team:AppArch) |
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.
Tested the change in table vis - the percentage column dropdown is still populated correctly. LGTM
Didn't do a thorough code review of the app arch code.
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.
KibanaApp owned code looks beautiful, table viz still works (tested in Chrome) ... finishing this review even @flash1293 overtook while had to take care of child logistics 🧒 -> 🐘 :)
This comment has been minimized.
This comment has been minimized.
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
@elasticmachine merge upstream |
💚 Build SucceededBuild metricspage load asset sizebeta
History
To update your PR or re-run it, just comment with: |
(3 of 3)
Part of #65793
Summary
In #69114 and #69586 we gave AggConfigs the ability to return a serializable representation of the field format for the particular field the agg was using. This
SerializedFieldFormat
could then be passed tofieldFormats.deserialize
so that downstream users could retrieve the actual format instance.Since that feature has been introduced, there is no longer a need for an AggConfig to expose a way to retrieve the format instance for a particular field. Instead, anyone needing this should use
toSerializedFieldFormat
anddeserialize
as described above.This also means that AggConfig no longer needs to depend directly on the fieldFormats service. (It does technically have an implicit dependency on field formats via
indexPattern.fields.someField.format
, but this has always been the case... ideally we would instead get the serialized field format off the index pattern instead).Note that each of the AggTypes still do have a dependency on fieldFormats. This is something we should ideally refactor out eventually, but wasn't feasible to do here without a significant overhaul. The main barriers to removing formats from AggType are a few places where
makeLabel
andcreateFilter
depend on field formats to format the values.Items changed in this PR include:
fieldFormatter
andfieldOwnFormatter
fromAggConfig
getFormat
from all of theAggType
sbuildTabularInspectorData
to retrieve the field format viatoSerializedFieldFormat
anddeserialize
Testing
This is simply a refactor of existing code and should introduce no functional changes. Areas to check for regressions are inspector and table vis. In the inspector, fields in the "data" tab should continue to have field formats applied as expected. In table vis, under the "options" tab, the
Percentage Column
dropdown should continue to only display numerical fields.Dev Docs
AggConfig
has been updated to no longer return a field format instance for the field it is aggregating on. As a result, thefieldFormatter
andfieldOwnFormatter
methods have been removed. Additionally, thegetFormat
method has been removed from each individual agg type.If you need to access a field format instance, use the newly-added
AggConfig.toSerializedFieldFormat
, orAggType.toSerializedFormat
to retrieve the serializable representation of the field's format, and then pass it to thedeserialize
method from the field formats service to get the actual format instance.In addition, the legacy formatting helpers that were exported from
ui/visualize/loader/pipeline_helpers/utilities
have been removed. If your plugin imports from this directory, please update your code to use thefieldFormats
service directly.