[Alerting]: get type-checking, tests, and ui working for index threshold#59064
[Alerting]: get type-checking, tests, and ui working for index threshold#59064pmuellr merged 4 commits intoelastic:masterfrom
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
YulNaumenko
left a comment
There was a problem hiding this comment.
LGTM! Tested this in UI and it works awesome!
gmmorris
left a comment
There was a problem hiding this comment.
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, | ||
| }, | ||
| }); |
| 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.
I might be missing something - why do we no longer need this check? 🤔
There was a problem hiding this comment.
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.
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.
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.
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.
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 OutStack TraceKibana 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 OutStack TraceKibana 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 OutStack TraceTo 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.