-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Remove dependencies from index pattern field and index pattern list #75185
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
Remove dependencies from index pattern field and index pattern list #75185
Conversation
| esTypes?: ES_FIELD_TYPES[], | ||
| params: Record<string, any> = {} | ||
| ): FieldFormat { | ||
| ): FieldFormat => { |
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.
fixes scope on this reference
kindsun
left a comment
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.
Thanks for the updates! Maps changes lgtm!
- code review
- tested locally in chrome
…ibana into field_list_without_construtor
walterra
left a comment
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.
LGTM - Tested for both data grid view in transform wizard and anomaly table in single metric viewer.
kertal
left a comment
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, KibanaApp team code review, checked out, tested Discover and Input Controls in Chrome/Firefox, works and also fixes the 'unknown field' bug in Discover (#75025).
patrykkopycinski
left a comment
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.
SIEM changes look great! Thank you @mattkime 💪
|
|
||
| public toSpec() { | ||
| public toSpec({ | ||
| getFormatterForField, |
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.
// nit Maybe getFieldFormatter is a more consistent name?
I'm also not sure I understand why it was necessary to remove the indexPattern from the constructor?
If there's a good reason for this, I think a comment both on the constructor of this class and on the toSpec function would be appropriate.
ppisljar
left a comment
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 think now it would be really beneficial to move format to field and get rid of the format map. i guess we could still use the format map to keep the instances of field formats around if we are worried about creating to many instances (each time someone requests it), but i would put the serialized version on the field directly.
| } | ||
| this.typeMeta = spec.typeMeta; | ||
|
|
||
| this.fieldFormatMap = _.mapValues(fieldFormatMap, (mapping) => { |
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.
lets add the format to the Field (non deserialized, SerializedFieldFormat)
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.
and lets get rid of the fieldFormatMap
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.
Luckily the field formatter registry already memoizes the creation of field formatter instances so I don't think we need to worry about performance concerns.
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 can't really get rid of the fieldFormatMap because thats how field formats are persisted. Because we wish to load the field list dynamically, we need to save the fieldFormat info separately from the field list. There are also cases where we'd like to be able to save fieldFormat info without the field existing.
Can you explain the desire to provide a serialized fieldFormat on the IndexPatternField class? Strikes me as an odd mix of serialized and nonserialized code.
The additional implication of providing a FieldFormat instance on a IndexPatternField instance is that the creator would need access to the FieldFormatsRegistry. Currently the index pattern has a reference. Perhaps we need indexPattern.addField. This is something I considered while working in the Fields class which is too cleverly overloaded. It would make sense to me to have the field list modification methods directly on the IndexPattern class.
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.
lets add the format to the Field (non deserialized, SerializedFieldFormat)
I like this idea of having the SerializedFieldFormat stored on the index pattern field directly, (but not the instance itself). IMO this creates a nice separation of concerns for downstream users; if you need the field format, you can get the serialized version from the index pattern, but must go to the field formats service and use fieldFormats.deserialize if you want the actual formatter instance.
It doesn't change the dependencies of index patterns internally (you still need access to the field formats registry), but it forces external users to be explicit about whether or not they rely on the field formatters.
const formatter = fieldFormats.deserialize(indexPattern.getFieldByName('myField').format);The current implementation also feels a little awkward in scenarios where you only want a serialized format -- for example the changes that were made to aggs now look like this:
const format = agg.params.field
? agg.aggConfigs.indexPattern.getFormatterForField(agg.params.field).toJSON()
: { id: undefined, params: undefined };Whereas if you provided the serialized format, it would be simpler:
const format = agg.aggConfigs.indexPattern.getFieldByName(agg.params.field.name).format
?? { id: undefined, params: undefined };Providing the serialized formats this way would also remove the need to pass getFormatterForField into that field toSpec method, which feels somewhat odd to me too (I would assume that if I have an instance which I need to serialize, I don't need to provide more dependencies to it in order to perform the serialization).
An approach like this is not without precedent -- it is how we handle things inside agg config at the moment. There's an aggConfig.toSerializedFieldFormat() which will return SerializedFieldFormat for the field you are aggregating on. This was done intentionally so that you must use fieldFormats.deserialize if you need the formatter instance, rather than getting that instance from a different service.
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.
but it forces external users to be explicit about whether or not they rely on the field formatters.
I think this specifically is worth resolving. Is there value in forcing users to be explicit about dependencies? Consider it in abstract - one situation you grab the IndexPattern service which includes field formatters, another you need to grab the Index Pattern service and the field formatter service. Which is better?
As best I understand, the cases where IndexPatterns is used without field formatting is pretty small. You'd be querying for documents but not formatting the result.
In the case where the dev needs two dependencies - how are they benefitting from this additional work? I'm having trouble finding a benefit.
In the case where a dev doesn't need formatting - is there something undesirable about its presence? I could see it affecting bundle size, but I think this is a premature optimization unless we back it up with numbers.
Side note - the IndexPattern class currently handles looking up default formatters. Needs to be accounted for but should be simple to move. Actually, the reason why the getFormatterForField is there is to get the default field formatter. Maybe this would be better addressed where the SerializedFieldFormat is being consumed rather than supplying it to all FieldSpecs
| specs.forEach(this.add); | ||
| }; | ||
| public toSpec({ | ||
| getFormatterForField, |
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.
then we don't need this one here, as we already have the serialized field format on the field.
| timeFieldName: this.timeFieldName, | ||
| sourceFilters: this.sourceFilters, | ||
| fields: this.fields.toSpec(), | ||
| fields: this.fields.toSpec({ getFormatterForField: this.getFormatterForField.bind(this) }), |
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.
the getFormatterForField function https://github.com/elastic/kibana/pull/75185/files#diff-0b63d2b724ba854c7057cfe7ac846028R488 can then change to:
this.fieldFormats.getInstance(field.format.id, field.format.params)
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.
the link isn't opening to a line of code so I'm not sure I understand.
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 was trying to link to the getFormatterForField method on the index pattern class.
|
@elasticmachine merge upstream |
ppisljar
left a comment
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 don't see any of the above comments as blockers for this PR so approving this.
|
@elasticmachine merge upstream |
💚 Build SucceededBuild metrics@kbn/optimizer bundle module count
async chunks size
page load bundle size
oss distributable file count
distributable file count
History
To update your PR or re-run it, just comment with: |
…lastic#75185) * Remove dependencies from index pattern field and index pattern list
Summary
The index pattern
fieldsclass has the following changesfilterand similar were called, producing an error. Its only created once by IndexPattern.The index pattern
fieldclass has the following changesformatattribute no longer exists. UseIndexPattern.getFormatterForFieldinstead.FieldTypeUnknownErrortoSpecnow takes an optional argument,{ getFormatterForField }which takes the field as an argument and returns a formatter.Checklist
Dev docs
The index pattern
fieldsclass has the following changesfilterand similar were called, producing an error. Its only created once by IndexPattern.The index pattern
fieldclass has the following changesformatattribute no longer exists. UseIndexPattern.getFormatterForFieldinstead.FieldTypeUnknownErrortoSpecnow takes an optional argument,{ getFormatterForField }which takes the field as an argument and returns a formatter.