Skip to content
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

WIP: deduplicate and filter logs #4689

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

europaul
Copy link
Contributor

This PR introduces log deduplication and filtering components to newlogd. The operations are performed as the logs are being compressed before sending them to the controller. The controller can configure which logs to filter out and which to count or deduplicate.

THIS IMPLEMENTATION IS STILL UNDER DEVELOPMENT & TESTING, PLEASE DON'T REVIEW OR MERGE!

europaul added 12 commits March 3, 2025 14:23
Signed-off-by: Paul Gaiduk <paulg@zededa.com>
Signed-off-by: Paul Gaiduk <paulg@zededa.com>
Signed-off-by: Paul Gaiduk <paulg@zededa.com>
Signed-off-by: Paul Gaiduk <paulg@zededa.com>
Signed-off-by: Paul Gaiduk <paulg@zededa.com>
Signed-off-by: Paul Gaiduk <paulg@zededa.com>
…ailable

Signed-off-by: Paul Gaiduk <paulg@zededa.com>
Signed-off-by: Paul Gaiduk <paulg@zededa.com>
Signed-off-by: Paul Gaiduk <paulg@zededa.com>
Signed-off-by: Paul Gaiduk <paulg@zededa.com>
Signed-off-by: Paul Gaiduk <paulg@zededa.com>
Signed-off-by: Paul Gaiduk <paulg@zededa.com>
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements log deduplication and filtering for newlogd, aiming to reduce redundant log entries before they reach the controller. Key changes include:

  • New modules for counting and deduplicating log entries (counter.go, dedup.go, filter.go).
  • Integration of deduplication and filtering logic into the log compression process (newlogd.go) together with corresponding tests (dedup_test.go).
  • Global configuration updates and minor logging improvements across related modules.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/newlog/cmd/counter.go Adds functions to count log occurrences with a minor spelling issue
pkg/newlog/cmd/dedup.go Implements deduplication logic using a ring buffer
pkg/newlog/cmd/dedup_test.go Adds tests for deduplication; one loop construct appears incorrect
pkg/newlog/cmd/filter.go Introduces filtering logic based on filename and function
pkg/newlog/cmd/newlogd.go Integrates deduplication and filtering into log file processing
pkg/pillar/types/global.go Adds new global settings for deduplication and filtering
Other pkg/pillar/* files Adjust logging and error formatting in cloud connectivity functions

Comment on lines +14 to +17
// countLogOccurances checks if the log entries should be merged into a single entry with a counter of occurances.
// If so it increments the counter for that log entry. It returns true if the log entry
// should be kept in the logs file (log's first occurance) and false otherwise.
func countLogOccurances(line []byte, filterMap map[string]int) error {
Copy link
Preview

Copilot AI Mar 18, 2025

Choose a reason for hiding this comment

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

The function name 'countLogOccurances' contains a misspelling. It should be 'countLogOccurrences'.

Suggested change
// countLogOccurances checks if the log entries should be merged into a single entry with a counter of occurances.
// If so it increments the counter for that log entry. It returns true if the log entry
// should be kept in the logs file (log's first occurance) and false otherwise.
func countLogOccurances(line []byte, filterMap map[string]int) error {
// countLogOccurrences checks if the log entries should be merged into a single entry with a counter of occurrences.
// If so it increments the counter for that log entry. It returns true if the log entry
// should be kept in the logs file (log's first occurrence) and false otherwise.
func countLogOccurrences(line []byte, filterMap map[string]int) error {

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
}

if count == 1 {
// no need to add additional count field if there is only one occurance
Copy link
Preview

Copilot AI Mar 18, 2025

Choose a reason for hiding this comment

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

The inline comment mentions 'occurance' instead of 'occurrence'. Update the spelling in the comment.

Suggested change
// no need to add additional count field if there is only one occurance
// no need to add additional count field if there is only one occurrence

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
// Start deduplicateLogs in a goroutine.
go deduplicateLogs(in, out)

for i := range totalLogs {
Copy link
Preview

Copilot AI Mar 18, 2025

Choose a reason for hiding this comment

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

Using 'for i := range totalLogs' is invalid as totalLogs is an integer. Consider replacing it with a conventional loop, e.g., 'for i := 0; i < totalLogs; i++ {'.

Suggested change
for i := range totalLogs {
for i := 0; i < totalLogs; i++ {

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a feature that was added in go1.22 https://go.dev/ref/spec#For_range.
But you are right, this should be fixed since we are still using go1.18.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant