-
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
[ML] Add runtime support for anomaly charts & add composite validations #96348
Conversation
Pinging @elastic/ml-ui (:ml) |
isPopulatedObject(buckets, ['composite']) && | ||
isPopulatedObject(buckets.composite, ['sources']) |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we check for an array instead?
buckets.composite.sources !== undefined | |
Array.isArray(buckets.composite.sources) |
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.
Updated here 4987fc2
(#96348)
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 |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Suggest to use isPopulatedObject()
here.
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.
Updated here 058c5dd
(#96348)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Missing n
for an aggregated field
.
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.
Updated here 058c5dd
(#96348)
return i18n.translate( | ||
'xpack.ml.timeSeriesJob.jobWithUnsupportedCompositeAggregationMessage', | ||
{ | ||
defaultMessage: 'the datafeed contains unsupported composite sources', |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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": {
....
}
},
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.
Latest changes LGTM.
💚 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

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