[ML] Add runtime support for anomaly charts & add composite validations#96348
[ML] Add runtime support for anomaly charts & add composite validations#96348qn895 merged 12 commits intoelastic:masterfrom
Conversation
|
Pinging @elastic/ml-ui (:ml) |
| isPopulatedObject(buckets, ['composite']) && | ||
| isPopulatedObject(buckets.composite, ['sources']) |
There was a problem hiding this comment.
what do you think about extending isPopulatedObject guard to support nested props?
| isPopulatedObject(buckets, ['composite']) && | |
| isPopulatedObject(buckets.composite, ['sources']) | |
| isPopulatedObject(buckets, ['composite.sources']) |
There was a problem hiding this comment.
I think this is a good idea although I think we probably should have a different API for handling that type of nested cases as it is possible for an object to have keys with dots in the name.
const myObj = {"composite.sources": "value1", "composite": { "source": "value2" }}
| if ( | ||
| isPopulatedObject(buckets, ['composite']) && | ||
| isPopulatedObject(buckets.composite, ['sources']) && | ||
| buckets.composite.sources !== undefined |
There was a problem hiding this comment.
shall we check for an array instead?
| buckets.composite.sources !== undefined | |
| Array.isArray(buckets.composite.sources) |
|
The charts in the Anomaly Explorer are showing up empty for me for a population job using runtime fields: Job config is: The chart in the Single Metric Viewer is plotting correctly. Update: confirmed fixed by 9b8746b |
peteharverson
left a comment
There was a problem hiding this comment.
Tested latest edits and LGTM
| }); | ||
| // if job has at least one composite source that is not terms or date_histogram | ||
| const aggs = getDatafeedAggregations(job.datafeed_config); | ||
| if (aggs !== undefined) { |
There was a problem hiding this comment.
Nit: Suggest to use isPopulatedObject() here.
| if (aggs !== undefined) { | ||
| const aggBucketsName = getFirstKeyInObject(aggs); | ||
| if (aggBucketsName !== undefined && aggs[aggBucketsName] !== undefined) { | ||
| // if fieldName is a aggregated field under nested terms using bucket_script |
There was a problem hiding this comment.
Nit: Missing n for an aggregated field.
| return i18n.translate( | ||
| 'xpack.ml.timeSeriesJob.jobWithUnsupportedCompositeAggregationMessage', | ||
| { | ||
| defaultMessage: 'the datafeed contains unsupported composite sources', |
There was a problem hiding this comment.
Where does this show up? Should the first char be capitalized and the sentence end with a dot?
There was a problem hiding this comment.
Originally, the full message will show up like this. But I realized the extra message is redundant so I removed it here 058c5dd (#96348).
| */ | ||
| export const getFirstKeyInObject = (arg: unknown): string | undefined => { | ||
| if (isPopulatedObject(arg)) { | ||
| const keys = Object.keys(arg); |
There was a problem hiding this comment.
Since JS doesn't guarantee the order of keys, should we sort the keys alphabetically to make sure the function returns 100% consistent results?
There was a problem hiding this comment.
This is a good point. However, I don't think we should sort it alphabetically by default. We can have an extra argument like sorted or have another getFirstSortedKeyInObject function if that's needed. In this case where this function is used, for example if the aggregation config is like below, my_buckets should be used instead of buckets. Also in this specific case where we are accessing the datafeed config, it's already been validated and should be guaranteed to have only one definition in the object - we just don't know what the key is called.
"aggregations": {
"my_buckets": {
....
},
"buckets": {
....
}
},
💚 Build SucceededMetrics [docs]Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: cc @qn895 |
💔 Backport failed
To backport manually run: |


Summary
Part of #77462. This PR adds runtime support for anomaly charts without model plot enabled.
It also adds extra validations for datafeed with composite aggregations to require only

termsanddate_histogramfields in the composite sources.Checklist
Delete any items that are not applicable to this PR.