-
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
[Alerting]: get type-checking, tests, and ui working for index threshold #59064
[Alerting]: get type-checking, tests, and ui working for index threshold #59064
Conversation
Pinging @elastic/kibana-alerting-services (Team:Alerting Services) |
This is a follow-on to elastic#57030 , "[alerting] initial index threshold alertType and supporting APIs", to get it working with the existing alerting UI. The parameter shape was different between the two, so the alertType was changed to fix the existing UI shapes expected.
d99291d
to
c5a0e4c
Compare
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 this in UI and it works awesome!
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
Made a couple of comments, but they're nitty in nature ;)
if (betweenComparators.has(thresholdComparator) && threshold.length === 1) { | ||
return i18n.translate('xpack.alertingBuiltins.indexThreshold.invalidThreshold2ErrorMessage', { | ||
defaultMessage: | ||
'[threshold]: must have two elements for the "{thresholdComparator}" comparator', | ||
values: { | ||
thresholdComparator, | ||
}, | ||
}); |
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.
Nice clean up 👍
if (aggType === 'count' && aggField) { | ||
return i18n.translate('xpack.alertingBuiltins.indexThreshold.aggTypeNotEmptyErrorMessage', { | ||
defaultMessage: '[aggField]: must not have a value when [aggType] is "{aggType}"', | ||
values: { | ||
aggType, | ||
}, | ||
}); | ||
} | ||
|
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 might be missing something - why do we no longer need this check? 🤔
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 UI sends parameters it doesn't need to be sending. We could tighten this up later, but if you're using count
, you don't need an aggField
, we used to error if you did, now it's silently ignored. shrug
if (groupBy === 'all' || groupBy === 'top') return; | ||
return i18n.translate('xpack.alertingBuiltins.indexThreshold.invalidGroupByErrorMessage', { | ||
defaultMessage: 'invalid groupBy: "{groupBy}"', | ||
values: { | ||
groupBy, | ||
}, | ||
}); |
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.
I find early returns like this are easy to miss and misread.
Would it be possible to flip it so that the invalid group is only returned when groupBy !== 'all' && groupBy !== 'top'
and then the function's implicit void
return would mean it's valid?
Just feels cleaner to me.
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.
Or better yet, use the type? Something like this should work:
schema.oneOf([
schema.literal('all'),
schema.literal('top'),
])
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 use schema.oneOf([schema.literal('foo'), ...])
at one point for things like this. But I changed back to strings with a custom validation, because the schema
way produced an error message with submessages for each valid literal (eg, "it wasn't a foo; and it wasn't a bar; and it wasn't a ...", but even longer). Heh. I'll open an issue on kbn-schema for that, I think there's probably a way to fix that ...
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 opted to make the early return more obvious; put it in a block, with an empty line behind it.I like early returns, but you're right, sometimes they aren't obvious ...
@elasticmachine merge upstream |
💛 Build succeeded, but was flaky
Test FailuresKibana Pipeline / kibana-xpack-agent / X-Pack Spaces API Integration Tests -- security_and_spaces.x-pack/test/spaces_api_integration/security_and_spaces/apis/resolve_copy_to_space_conflicts·ts.spaces api with security resolve copy to spaces conflicts user with no access from the default space "before each" hook for "should return 404 when overwriting, without references"Standard Out
Stack Trace
Kibana Pipeline / kibana-xpack-agent / X-Pack Spaces API Integration Tests -- security_and_spaces.x-pack/test/spaces_api_integration/security_and_spaces/apis/resolve_copy_to_space_conflicts·ts.spaces api with security resolve copy to spaces conflicts user with no access from the default space "after each" hook for "should return 404 when overwriting, without references"Standard Out
Stack Trace
Kibana Pipeline / kibana-xpack-agent / X-Pack Spaces API Integration Tests -- security_and_spaces.x-pack/test/spaces_api_integration/security_and_spaces/apis/resolve_copy_to_space_conflicts·ts.spaces api with security resolve copy to spaces conflicts user with no access from the default space "before each" hook for "should return 404 when overwriting, without references"Standard Out
Stack Trace
To update your PR or re-run it, just comment with: |
…old (elastic#59064) This is a follow-on to elastic#57030 , "[alerting] initial index threshold alertType and supporting APIs", to get it working with the existing alerting UI. The parameter shape was different between the two, so the alertType was changed to fix the existing UI shapes expected.
This is a follow-on to #57030 , "[alerting] initial index threshold alertType and supporting APIs", to get it working with the existing alerting UI. The parameter shape was different between the two, so the alertType was changed to fix the existing UI shapes expected.
Summary
Summarize your PR. If it involves visual changes include a screenshot or gif.
Checklist
Delete any items that are not applicable to this PR.