-
Notifications
You must be signed in to change notification settings - Fork 29
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
feat: Add flag enable-policy-event-logs #48
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -175,48 +175,46 @@ func capturePolicyEvents(ringbufferdata <-chan []byte, log logr.Logger, enableCl | |
// Read from ringbuffer channel, perf buffer support is not there and 5.10 kernel is needed. | ||
go func(ringbufferdata <-chan []byte) { | ||
done := false | ||
for { | ||
if record, ok := <-ringbufferdata; ok { | ||
var logQueue []*cloudwatchlogs.InputLogEvent | ||
var message string | ||
if enableIPv6 { | ||
var rb ringBufferDataV6_t | ||
buf := bytes.NewBuffer(record) | ||
if err := binary.Read(buf, binary.LittleEndian, &rb); err != nil { | ||
log.Info("Failed to read from Ring buf", err) | ||
continue | ||
} | ||
|
||
protocol := getProtocol(int(rb.Protocol)) | ||
verdict := getVerdict(int(rb.Verdict)) | ||
|
||
log.Info("Flow Info: ", "Src IP", utils.ConvByteToIPv6(rb.SourceIP).String(), "Src Port", rb.SourcePort, | ||
"Dest IP", utils.ConvByteToIPv6(rb.DestIP).String(), "Dest Port", rb.DestPort, | ||
"Proto", protocol, "Verdict", verdict) | ||
|
||
message = "Node: " + nodeName + ";" + "SIP: " + utils.ConvByteToIPv6(rb.SourceIP).String() + ";" + "SPORT: " + strconv.Itoa(int(rb.SourcePort)) + ";" + "DIP: " + utils.ConvByteToIPv6(rb.DestIP).String() + ";" + "DPORT: " + strconv.Itoa(int(rb.DestPort)) + ";" + "PROTOCOL: " + protocol + ";" + "PolicyVerdict: " + verdict | ||
} else { | ||
var rb ringBufferDataV4_t | ||
buf := bytes.NewBuffer(record) | ||
if err := binary.Read(buf, binary.LittleEndian, &rb); err != nil { | ||
log.Info("Failed to read from Ring buf", err) | ||
continue | ||
} | ||
protocol := getProtocol(int(rb.Protocol)) | ||
verdict := getVerdict(int(rb.Verdict)) | ||
|
||
log.Info("Flow Info: ", "Src IP", utils.ConvByteArrayToIP(rb.SourceIP), "Src Port", rb.SourcePort, | ||
"Dest IP", utils.ConvByteArrayToIP(rb.DestIP), "Dest Port", rb.DestPort, | ||
"Proto", protocol, "Verdict", verdict) | ||
|
||
message = "Node: " + nodeName + ";" + "SIP: " + utils.ConvByteArrayToIP(rb.SourceIP) + ";" + "SPORT: " + strconv.Itoa(int(rb.SourcePort)) + ";" + "DIP: " + utils.ConvByteArrayToIP(rb.DestIP) + ";" + "DPORT: " + strconv.Itoa(int(rb.DestPort)) + ";" + "PROTOCOL: " + protocol + ";" + "PolicyVerdict: " + verdict | ||
for record := range ringbufferdata { | ||
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. Also changed this line to wait for data from the channel instead of dead spinning the CPU in the for loop. |
||
var logQueue []*cloudwatchlogs.InputLogEvent | ||
var message string | ||
if enableIPv6 { | ||
var rb ringBufferDataV6_t | ||
buf := bytes.NewBuffer(record) | ||
if err := binary.Read(buf, binary.LittleEndian, &rb); err != nil { | ||
log.Info("Failed to read from Ring buf", err) | ||
continue | ||
} | ||
|
||
if enableCloudWatchLogs { | ||
done = publishDataToCloudwatch(logQueue, message, log) | ||
if done { | ||
break | ||
} | ||
protocol := getProtocol(int(rb.Protocol)) | ||
verdict := getVerdict(int(rb.Verdict)) | ||
|
||
log.Info("Flow Info: ", "Src IP", utils.ConvByteToIPv6(rb.SourceIP).String(), "Src Port", rb.SourcePort, | ||
"Dest IP", utils.ConvByteToIPv6(rb.DestIP).String(), "Dest Port", rb.DestPort, | ||
"Proto", protocol, "Verdict", verdict) | ||
|
||
message = "Node: " + nodeName + ";" + "SIP: " + utils.ConvByteToIPv6(rb.SourceIP).String() + ";" + "SPORT: " + strconv.Itoa(int(rb.SourcePort)) + ";" + "DIP: " + utils.ConvByteToIPv6(rb.DestIP).String() + ";" + "DPORT: " + strconv.Itoa(int(rb.DestPort)) + ";" + "PROTOCOL: " + protocol + ";" + "PolicyVerdict: " + verdict | ||
} else { | ||
var rb ringBufferDataV4_t | ||
buf := bytes.NewBuffer(record) | ||
if err := binary.Read(buf, binary.LittleEndian, &rb); err != nil { | ||
log.Info("Failed to read from Ring buf", err) | ||
continue | ||
} | ||
protocol := getProtocol(int(rb.Protocol)) | ||
verdict := getVerdict(int(rb.Verdict)) | ||
|
||
log.Info("Flow Info: ", "Src IP", utils.ConvByteArrayToIP(rb.SourceIP), "Src Port", rb.SourcePort, | ||
"Dest IP", utils.ConvByteArrayToIP(rb.DestIP), "Dest Port", rb.DestPort, | ||
"Proto", protocol, "Verdict", verdict) | ||
|
||
message = "Node: " + nodeName + ";" + "SIP: " + utils.ConvByteArrayToIP(rb.SourceIP) + ";" + "SPORT: " + strconv.Itoa(int(rb.SourcePort)) + ";" + "DIP: " + utils.ConvByteArrayToIP(rb.DestIP) + ";" + "DPORT: " + strconv.Itoa(int(rb.DestPort)) + ";" + "PROTOCOL: " + protocol + ";" + "PolicyVerdict: " + verdict | ||
} | ||
|
||
if enableCloudWatchLogs { | ||
done = publishDataToCloudwatch(logQueue, message, log) | ||
if done { | ||
break | ||
} | ||
} | ||
} | ||
|
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.
Flow specific logs will be rather useful for debugging. Since this is an initial release, will be helpful to have it turned on by default for the first few releases. It should only log an entry per flow and not per packet (for accepted flows). Obviously, this change allows an user to turn it off if it becomes too verbose for them..
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.
The problem with turning it on by default is not the amount of logs being produced, but the fact that the busy loop which is collecting the decision logs is consuming a full CPU core on every node. From a users point of view this is unexpected and undesired default behavior.
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.
Sorry for the delay. We had some internal discussions on what the default should be for this flag and we agreed on disabling this by default considering the agent runs as a daemonset. So, we should be good with the current PR. We will look to enable it by default, once we find a way to optimize the CPU usage. Thanks for the PR.