-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Migrate system socket fields metricset to ECS #10339
Merged
Merged
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
81204e1
Migrate system socket fields to ECS
jsoriano 80c597b
Add changelog
jsoriano 8c07763
Move comment to review :)
jsoriano c211ecc
Rename incoming/outgoing to inbound/outbound
jsoriano 5e5eda2
Format uid as string
jsoriano 5c31194
Add event filtering for data generation with V2 reporters
jsoriano 5027a5b
Generate data for inbound and outbound connections too
jsoriano 6725f1e
Merge remote-tracking branch 'origin/master' into mb-system-socket-ecs
jsoriano 2c95080
Remove wrong changelog entry
jsoriano 6f36c67
Fix direction mapping
jsoriano 0d5ebbb
Collect both name and full name
jsoriano 864767e
Merge remote-tracking branch 'origin/master' into mb-system-socket-ecs
jsoriano 1ffc5bb
Fix migration field for full name
jsoriano 5b45931
Remove resolved question
jsoriano 0cc1a92
Rename incoming/outgoing also in tests
jsoriano c2bdef3
Merge remote-tracking branch 'origin/master' into mb-system-socket-ecs
jsoriano 764df33
Rename incoming/outgoing also on auditbeat
jsoriano 7df1ffb
Merge remote-tracking branch 'origin/master' into mb-system-socket-ecs
jsoriano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,29 +77,25 @@ func WriteEventsCond(f mb.EventsFetcher, t testing.TB, cond func(e common.MapStr | |
return fmt.Errorf("no events were generated") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changes in this file moved to its own PR #10367 |
||
} | ||
|
||
var event *common.MapStr | ||
if cond == nil { | ||
event = &events[0] | ||
} else { | ||
for _, e := range events { | ||
if cond(e) { | ||
event = &e | ||
break | ||
} | ||
} | ||
if event == nil { | ||
return fmt.Errorf("no events satisfied the condition") | ||
} | ||
event, err := SelectEvent(events, cond) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fullEvent := CreateFullEvent(f, *event) | ||
fullEvent := CreateFullEvent(f, event) | ||
WriteEventToDataJSON(t, fullEvent, "") | ||
return nil | ||
} | ||
|
||
// WriteEventsReporterV2 fetches events and writes the first event to a ./_meta/data.json | ||
// file. | ||
func WriteEventsReporterV2(f mb.ReportingMetricSetV2, t testing.TB, path string) error { | ||
return WriteEventsReporterV2Cond(f, t, path, nil) | ||
} | ||
|
||
// WriteEventsReporterV2Cond fetches events and writes the first event that matches | ||
// the condition to a file. | ||
func WriteEventsReporterV2Cond(f mb.ReportingMetricSetV2, t testing.TB, path string, cond func(common.MapStr) bool) error { | ||
if !*dataFlag { | ||
t.Skip("skip data generation tests") | ||
} | ||
|
@@ -113,7 +109,12 @@ func WriteEventsReporterV2(f mb.ReportingMetricSetV2, t testing.TB, path string) | |
return fmt.Errorf("no events were generated") | ||
} | ||
|
||
e := StandardizeEvent(f, events[0], mb.AddMetricSetInfo) | ||
match, err := SelectEventV2(f, events, cond) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
e := StandardizeEvent(f, match, mb.AddMetricSetInfo) | ||
|
||
WriteEventToDataJSON(t, e, path) | ||
return nil | ||
|
@@ -169,7 +170,11 @@ func WriteEventToDataJSON(t testing.TB, fullEvent beat.Event, postfixPath string | |
t.Fatal(err) | ||
} | ||
|
||
p = path.Join(p, postfixPath, "_meta", "data.json") | ||
if stat, err := os.Stat(postfixPath); err == nil && stat.IsDir() { | ||
p = path.Join(p, postfixPath, "_meta", "data.json") | ||
} else { | ||
p = postfixPath | ||
} | ||
|
||
fields := fullEvent.Fields | ||
fields["@timestamp"] = fullEvent.Timestamp | ||
|
@@ -183,3 +188,30 @@ func WriteEventToDataJSON(t testing.TB, fullEvent beat.Event, postfixPath string | |
t.Fatal(err) | ||
} | ||
} | ||
|
||
// SelectEvent selects the first event that matches an specific condition | ||
func SelectEvent(events []common.MapStr, cond func(e common.MapStr) bool) (common.MapStr, error) { | ||
if cond == nil && len(events) > 0 { | ||
return events[0], nil | ||
} | ||
for _, e := range events { | ||
if cond(e) { | ||
return e, nil | ||
} | ||
} | ||
return nil, fmt.Errorf("no events satisfied the condition") | ||
} | ||
|
||
// SelectEventV2 selects the first event that matches an specific condition | ||
func SelectEventV2(f mb.ReportingMetricSetV2, events []mb.Event, cond func(e common.MapStr) bool) (mb.Event, error) { | ||
if cond == nil && len(events) > 0 { | ||
return events[0], nil | ||
} | ||
for _, e := range events { | ||
fields := StandardizeEvent(f, e, mb.AddMetricSetInfo).Fields | ||
if cond(fields) { | ||
return e, nil | ||
} | ||
} | ||
return mb.Event{}, fmt.Errorf("no events satisfied the condition") | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
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.
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.
@simianhacker Could you see that and of the fields change in this file could have an effect on Infra UI?