airbnb / streamalert

StreamAlert is a serverless, realtime data analysis framework which empowers you to ingest, analyze, and alert on data from any environment, using datasources and alerting logic you define.
https://streamalert.io
Apache License 2.0
2.86k stars 334 forks source link

Fixes a bug where alert merging context is not correct #1310

Closed Ryxias closed 3 years ago

Ryxias commented 3 years ago

to: @ryandeivert @chunyong-lin cc: @airbnb/streamalert-maintainers

Background

Alert Merging doesn't properly merge context together, which makes it really tough for rules to pass information from individual records to a consolidated alert publisher. This means the alert publisher has to be "super smart" in order to extract out the proper fields and this is just too much work.

Changes

Example

Suppose two alerts:

alert 1

{
  alert_id: abc123,
  context: {"foo": "bar"},
  ...
}

alert 2

{
  alert_id: def456,
  context: {"baz": "buzz"},
  ...
}

Old way The merged alert would look like:

{
  alert_id: ghi789,
  context: {"foo": "bar"},  # it just takes alert.context[0]
  ... merged stuff here
}

NEW way The merged alert now looks like:

{
  alert_id: ghi789,
  context: {
    "abc123": {"foo": "bar"},
    "def456": {"baz": "buzz"},
  },
  ... merged stuff here
}

Testing

Deployed internally.

Steps for how this change was tested and verified