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

internal/log: allow RecordLogger to ignore certain logs #1810

Merged
merged 4 commits into from
Mar 16, 2023

Conversation

lievan
Copy link
Contributor

@lievan lievan commented Mar 16, 2023

What does this PR do?

Some unit tests in the tracer assert based on the content or positioning of log messages (example). When new log messages are added (e.g. by appsec) these tests will fail. To workaround this, we've previously introduced a removeAppsec method that removes strings which contain appsec: from recorded logs. This PR introduces an alternate solution to directly ignore certain substrings using RecordLogger while logging.

More specifically, this PR:

  • removes testLogger from the tracer package. testLogger has a near identical implementation to RecordLogger in the internal/log package, so we can just use RecordLogger instead.
  • adds a Ignore method to RecordLogger that allows us to ignore logs which contain certain substrings.
  • edits unit tests in the tracer package to use RecordLogger and Ignore to ignore appsec logs

Motivation

Introduces a slightly friendlier interface for ignoring logs in comparison to creating custom functions that remove log messages, which may be useful when new features that use logging (e.g. instrumentation telemetry) are introduced.

Describe how to test/QA your changes

Reviewer's Checklist

  • If known, an appropriate milestone has been selected; otherwise the Triage milestone is set.
  • Changed code has unit tests for its functionality.
  • If this interacts with the agent in a new way, a system test has been added.

Sorry, something went wrong.

@lievan lievan requested a review from a team March 16, 2023 16:01
@lievan lievan requested a review from a team as a code owner March 16, 2023 16:01
@lievan lievan added this to the v1.49.0 milestone Mar 16, 2023
@ajgajg1134
Copy link
Contributor

This seems pretty reasonable to me! Perhaps at some point in the future we can use / interact with more structured logs that would make this sort of thing easier and less error-prone than just a string contains, but I think that's a conversation for another day perhaps as this is an improvement over what exists now.

@pr-commenter
Copy link

pr-commenter bot commented Mar 16, 2023

Benchmarks

Comparing candidate commit 182085e in PR branch evan.li/ignore-logs with baseline commit 3895e95 in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 18 metrics, 0 unstable metrics.

@lievan lievan merged commit 7686ff9 into main Mar 16, 2023
@lievan lievan deleted the evan.li/ignore-logs branch March 16, 2023 18:05
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.

None yet

2 participants