Skip to content

feat(command): add replay subcommand#5200

Open
josedonizetti wants to merge 1 commit intoaquasecurity:mainfrom
josedonizetti:add-replay-flag
Open

feat(command): add replay subcommand#5200
josedonizetti wants to merge 1 commit intoaquasecurity:mainfrom
josedonizetti:add-replay-flag

Conversation

@josedonizetti
Copy link
Copy Markdown
Contributor

@josedonizetti josedonizetti commented Jan 17, 2026

Add tracee replay command

This PR introduces a new tracee replay subcommand that allows replaying previously captured events from a JSON Lines file and processing them through the detector engine.

Features

  • Replay events from JSON Lines format files (as produced by tracee --output json:file.json)
  • Process replayed events through detectors (both built-in Go detectors and YAML detectors)
  • Support for detector chaining (detector outputs can trigger other detectors)
  • Filter out detector events automatically (only low-level events are replayed)
  • Only detector outputs are printed (low-level events are processed but not printed)
  • Support for standard flags: --output, --detectors, --logging

Limitations

  • Enrichment (environment variables, exec hashes, container info) is not supported yet - coming in a future PR
  • Data stores are not supported yet - coming in a future PR

Implementation Notes

This is a first version that maintains the same event processing approach as the old analyze tracee command. The implementation uses a simplified event processing pipeline that reads events from a file and dispatches them to the detector engine.

In the future, we plan to refactor this to use the same unified pipeline as the main tracee command to ensure consistency and reduce code duplication.

Usage

# Capture events
tracee --events execve,openat --output json:events.json

# Replay events (all detector outputs)
tracee replay events.json --output table --detectors /path/to/detectors

# Replay with multiple detector directories
tracee replay events.json --detectors /path/to/detectors

@josedonizetti josedonizetti force-pushed the add-replay-flag branch 10 times, most recently from f4697e2 to ffa96f1 Compare January 28, 2026 07:55
@josedonizetti josedonizetti changed the title feat(flags): add replay flag feat(command): add replay flag Jan 28, 2026
@josedonizetti josedonizetti changed the title feat(command): add replay flag feat(command): add replay subcommand Jan 28, 2026
@josedonizetti josedonizetti force-pushed the add-replay-flag branch 3 times, most recently from 646494a to 115f048 Compare January 28, 2026 08:41
@josedonizetti josedonizetti marked this pull request as ready for review January 28, 2026 08:52
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 28, 2026

Codecov Report

❌ Patch coverage is 34.24318% with 265 lines in your changes missing coverage. Please review.
✅ Project coverage is 35.67%. Comparing base (235daa0) to head (84e73df).
⚠️ Report is 152 commits behind head on main.

Files with missing lines Patch % Lines
pkg/cmd/tracee.go 0.00% 89 Missing ⚠️
cmd/tracee/cmd/replay.go 25.25% 74 Missing ⚠️
pkg/replay/replay.go 70.62% 36 Missing and 11 partials ⚠️
pkg/cmd/cobra/cobra.go 0.00% 41 Missing ⚠️
pkg/events/event_id_translation.go 0.00% 14 Missing ⚠️

❌ Your patch check has failed because the patch coverage (34.24%) is below the target coverage (60.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5200      +/-   ##
==========================================
+ Coverage   33.51%   35.67%   +2.16%     
==========================================
  Files         250      239      -11     
  Lines       28908    31549    +2641     
==========================================
+ Hits         9688    11255    +1567     
- Misses      18609    19569     +960     
- Partials      611      725     +114     
Flag Coverage Δ
unit 35.67% <34.24%> (+2.16%) ⬆️
Files with missing lines Coverage Δ
pkg/events/event_id_translation.go 39.13% <0.00%> (-60.87%) ⬇️
pkg/cmd/cobra/cobra.go 0.00% <0.00%> (ø)
pkg/replay/replay.go 70.62% <70.62%> (ø)
cmd/tracee/cmd/replay.go 25.25% <25.25%> (ø)
pkg/cmd/tracee.go 0.00% <0.00%> (ø)

... and 98 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member

@geyslan geyslan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Dropped observations.

}

func (r Runner) Run(ctx context.Context) error {
// ReplayRunner handles replaying events from a file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about placing ReplayRunner definition/logic in its own file?

//
// Returns:
// - The corresponding internal event ID, or 0 if not found
func TranslateFromProtoEventID(protoEventID pb.EventId) ID {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TranslateFromProtoEventID does a linear search for every event replayed. Could we create the reversed table of EventTranslationTable in memory, in a init() for instance? And to not waste memory it could be instantiated only in replay mode.

fileReadCtx, stop := context.WithCancel(signalCtx)

// Producer: read events from file (protobuf JSON format)
fromFile := make(chan *v1beta1.Event, 100)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider making the channel size configurable or documenting the choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants