Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
[Security Solution][Alerts] Replace schemas derived from FieldMaps with versioned alert schema #127218
[Security Solution][Alerts] Replace schemas derived from FieldMaps with versioned alert schema #127218
Changes from 18 commits
7dff107
b8c3c82
694180d
2ce2c37
2f60cf6
ecd7f49
3f29171
b1787a6
96a1a71
4753672
179c195
a52cf69
3371fb8
dac9ded
ed48a31
52ec700
be7965f
63d0545
d8bae7e
8ab1020
63223fe
70f24ad
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
curious to hear your thoughts about the naming convention here with
CommonAlertFieldName800
. If we plan to associate the version numbers with the release numbers I can see it getting a little awkward with no separators for the800
part. If we are going to bump it by one with each change then we probably don't need to start with 800. What do you think?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 agree that ending with
800
is a bit awkward. I initially wanted to use something more likeCommonAlertFieldName_8_0_0
at first, but the naming convention linter complains about using underscores if the type isn't all caps. Alerting uses a similar convention in the SO migrations logic which seems to have worked so far so I adopted that instead of trying to disable the linter rule for these type names.With this proposal we wouldn't bump the number by 1, instead we'd increment it to the version of Kibana that's shipping the change, e.g. the next one might be
CommonAlertFieldName830
for 8.3.0 if we make changes soon. But we haven't made changes in 8.1 or 8.2 so there would never be aCommonAlertFieldName810
or820
.In the past we used integer version numbers, starting at
1
and incrementing on each Kibana version that shipped changes, for the legacy signals mappings and it was pretty confusing IMO. Most of the time when looking at version numbers what I wanted to now was what version of Kibana a particular version number shipped with so it would have saved time to just version the signals mappings with the Kibana version. Instead with the integer it has to be cross-referenced with Git history to figure out when it shipped.The other possible option I considered was dropping the
800
from the name entirely and relying on the8.0.0
in the folder path to differentiate thisCommonAlertFieldName
type from possible futureCommonAlertFieldName
types. I worried that that would make it too easy to accidentally import the wrong type though.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 pretty nitpicky, but I'd be in favor of dropping the suffix entirely. This naming schema will become ambiguous if there's ever a minor or patch version > 10, or once we hit 10.x. Sure, it makes it easier to import the wrong version, but import paths matter and devs should be able to navigate that. If nothing else, code reviewers should be able to mitigate this possibility.
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.
Why these two id fields are not included in
CommonAlertFields800
and have their own union type?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.
These are used by Observability for the lifecycle rule executor logic. I'm not sure why they're separated out, but I kept them the same way they were in
get_common_alert_fields.ts
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.
Off-topic, but it would be great to eventually have a jsdoc comment for every field in the alert schema containing a description (what it means), examples of values, and any other important information.
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 all really great, thank you!
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'm not sure how union type is gonna work here, maybe missing something.
Please check this example where properties
x
,y
andz
are not accessible without an additional type casting:I'd expect similar issues with access to fields in the real
DetectionAlert800
:ALERT_GROUP_INDEX
is defined as anumber
but available asSearchTypes
inDetectionAlert800
I think it's going to get worse when we'll need to start adding more versions of
DetectionAlert
to the final union type:I think what we need here instead of using the union type is constructing an interface manually that would:
x | undefined
)Still, combining multiple versions into a single
DetectionAlert
interface is a little bit unclear 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.
Also, TS has a pretty nasty bug in the implementation of deeply nested type intersection (microsoft/TypeScript#47935) which can become a source of bugs in the code (unless all the fields in the alert schema will be flat).
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 working as intended IMO - when an alert is first retrieved, without additional checks at runtime the type of
ALERT_GROUP_INDEX
really could be anything. Once we add the full types forALERT_RULE_PARAMETERS
though, the fieldalert[ALERT_RULE_PARAMETERS].type
can be used as a discriminant at runtime to narrow the type down to EQL alerts only. At that point the type should beEqlBuildingBlockAlert800 | EqlShellAlert800
, so we'd still need some other discriminant between those 2 types. But in general for alerts from different types of rules, we can use a known field likealert[ALERT_RULE_PARAMETERS].type
as a discriminant.Alternatively, developers can fetch
ALERT_GROUP_INDEX
, accept that its type isSearchTypes
, and then do extra runtime validation on the retrieved value to ensure that it's not undefined or an object or some other unexpected value.In both cases though I think it's a feature that
ALERT_GROUP_INDEX
has a very general type if it's retrieved fromDetectionAlert
- we're warning developers that the value could be anything and they need to do more validation there. For fields that are common and required across all alert types, e.g.ALERT_RULE_DESCRIPTION
, the type system can convey that the value received from anyDetectionAlert
will always bestring
and extra validation isn't needed.