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

add log filter #339

Merged
merged 2 commits into from
Jan 23, 2025
Merged

add log filter #339

merged 2 commits into from
Jan 23, 2025

Conversation

satoren
Copy link
Member

@satoren satoren commented Jan 22, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced logging functionality with advanced filtering capabilities.
    • Added ability to conditionally log messages based on custom filter functions.
    • Introduced more granular control over log message processing.
  • Tests

    • Added comprehensive test cases for log filtering mechanisms.
    • Verified filtering behavior for different log levels and message patterns.

@satoren satoren requested a review from h3poteto as a code owner January 22, 2025 09:32
Copy link

coderabbitai bot commented Jan 22, 2025

Walkthrough

The changes introduce a new configuration option for the Mediasoup.LoggerProxy module, specifically adding a filter option to the config type. The config type has been modified to include a new tuple for :filter, which can be a function that evaluates log messages. The start_link function retrieves this filter and initializes the state accordingly. The handle_info function incorporates the filter logic to determine whether to process log messages based on the filter's evaluation. Additionally, the test suite has been enhanced with new cases to validate the filtering functionality.

Changes

File Change Summary
lib/logger_proxy.ex - Updated config type to include filter option
- Modified start_link to handle filter configuration
- Updated init and handle_info functions to support filtering logic
test/logger_proxy_test.exs - Added new describe block "log filter"
- Implemented two test cases validating filter functionality:
1. Filtering based on log level
2. Filtering based on message regex pattern

Sequence Diagram

sequenceDiagram
    participant Client
    participant LoggerProxy
    participant Filter
    participant Logger

    Client->>LoggerProxy: start_link(config)
    LoggerProxy->>Filter: Configure filter function
    Client->>LoggerProxy: Log message
    LoggerProxy->>Filter: Evaluate message
    alt Message passes filter
        Filter-->>LoggerProxy: true
        LoggerProxy->>Logger: Process log
    else Message filtered
        Filter-->>LoggerProxy: false
        LoggerProxy->>Logger: Ignore log
    end
Loading

Poem

🐰 A Logger's Tale of Selective Might
Filters dancing, log messages bright
Regex patterns, levels so keen
Only the worthy shall grace the screen
Rabbit's wisdom in logging's delight! 🔍📝


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 38da1df and 64533d6.

📒 Files selected for processing (1)
  • lib/logger_proxy.ex (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build and test (stable)
  • GitHub Check: lint (stable)
  • GitHub Check: Lint Rust (native/mediasoup_elixir/Cargo.toml)
🔇 Additional comments (3)
lib/logger_proxy.ex (3)

56-60: LGTM! The implementation matches the contract.

The function correctly:

  • Extracts configuration values with proper defaults
  • Initializes state with both max_level and filter
  • Matches the expected contract ([config()]) :: :ignore | {:error, any()} | {:ok, pid()}

65-65: LGTM! Proper state initialization.

The change correctly preserves the filter in state while maintaining the existing NIF functionality.


68-76: LGTM! Correct filter implementation.

The implementation:

  • Properly handles both filtered and unfiltered cases
  • Maintains all existing logging metadata
  • Uses the correct filter condition
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coveralls
Copy link

coveralls commented Jan 22, 2025

Coverage Status

coverage: 92.355% (+0.03%) from 92.324%
when pulling 64533d6 on mshiraki/log_filter
into 19c2fe3 on main.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 19c2fe3 and 5a89ce8.

📒 Files selected for processing (2)
  • lib/logger_proxy.ex (1 hunks)
  • test/logger_proxy_test.exs (1 hunks)
🧰 Additional context used
🪛 GitHub Check: Build and test (stable)
test/logger_proxy_test.exs

[warning] 105-105:
variable "ignore_can_consume_error" is unused (if the variable is not meant to be used, prefix it with an underscore)


[warning] 105-105:
variable "ignore_can_consume_error" is unused (if the variable is not meant to be used, prefix it with an underscore)


[warning] 105-105:
variable "ignore_can_consume_error" is unused (if the variable is not meant to be used, prefix it with an underscore)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Lint Rust (native/mediasoup_elixir/Cargo.toml)
🔇 Additional comments (2)
lib/logger_proxy.ex (2)

55-59: LGTM! Filter configuration is handled correctly.

The implementation properly extracts the optional filter from config with a sensible nil default.


64-64: LGTM! State initialization is correct.

The state is properly initialized with the provided configuration.

@h3poteto
Copy link
Contributor

test/integration/test_smoke.ex:6:call
The function call will not succeed.

Mediasoup.LoggerProxy.start_link([{:max_level, :info}])

breaks the contract
([config()]) :: :ignore | {:error, any()} | {:ok, pid()}

@satoren satoren force-pushed the mshiraki/log_filter branch from 5a89ce8 to f90732f Compare January 22, 2025 09:45
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
test/logger_proxy_test.exs (1)

102-132: Consider making the test more reliable.

While the test effectively verifies complex filtering functionality, the use of Process.sleep(10) could make the test flaky. Consider using a more reliable synchronization mechanism.

Example approaches:

  1. Use ExUnit.Callbacks.on_exit/2 to ensure cleanup
  2. Implement a wait_for_log helper that polls with timeout
  3. Use a message-based synchronization mechanism
# Example wait_for_log helper
defp wait_for_log(pattern, timeout \\ 100) do
  case Process.get(:log_messages, []) do
    [] ->
      if timeout > 0 do
        Process.sleep(10)
        wait_for_log(pattern, timeout - 10)
      else
        false
      end
    messages ->
      Enum.any?(messages, &(Regex.match?(pattern, &1)))
  end
end
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a89ce8 and f90732f.

📒 Files selected for processing (2)
  • lib/logger_proxy.ex (1 hunks)
  • test/logger_proxy_test.exs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build and test (stable)
  • GitHub Check: Lint Rust (native/mediasoup_elixir/Cargo.toml)
🔇 Additional comments (5)
lib/logger_proxy.ex (4)

49-52: LGTM! Type specification is well-defined.

The config type specification correctly defines the structure as a keyword list with optional filter, matching the implementation.


57-61: LGTM! Initialization logic is correct.

The start_link function properly extracts the filter from config with appropriate defaults and initializes the state correctly.


65-66: LGTM! State initialization is correct.

The init function properly uses the provided init_arg to maintain the filter in state.


69-77: LGTM! Filter logic is correctly implemented.

The handle_info function properly implements the filtering logic, only logging messages when the filter is nil or returns true.

test/logger_proxy_test.exs (1)

88-100: LGTM! Test case properly verifies basic filter functionality.

The test effectively verifies that the filter correctly allows info level messages while filtering out debug messages.

@satoren satoren force-pushed the mshiraki/log_filter branch from 38da1df to 64533d6 Compare January 23, 2025 00:50
Copy link
Contributor

@h3poteto h3poteto left a comment

Choose a reason for hiding this comment

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

LGTM

@satoren satoren merged commit 7a07b90 into main Jan 23, 2025
6 checks passed
@satoren satoren deleted the mshiraki/log_filter branch January 23, 2025 07:16
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.

3 participants