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 configuration to filter out sql queries #60

Merged

Conversation

fdaugs
Copy link
Contributor

@fdaugs fdaugs commented Nov 8, 2024

This pull request introduces a new feature to filter SQL queries by name using a denylist configuration.

SQL Query Name Denylist

  • Added a query_name_denylist configuration option to filter out SQL queries by name using regular expressions.
  • Updated the valid? method in lib/lograge/active_record_log_subscriber.rb to use the denylist for filtering queries.
  • Added query_name_denylist attribute to the Lograge::Sql configuration and set default values for it.
  • Initialized the query_name_denylist in the test setup to ensure it has default values.
  • Added tests to verify the denylist functionality, ensuring that queries with names matching the denylist are not stored.

Default value

I addition to SCHEMA-queries, queries with names starting with SolidCable:: are now also skipped. This is to prevent a issue #59 that causes a memory leak.

Additional Information

I testing this implementation of this gem locally in my application and it successfully skips all queries of solid cable.

@fdaugs fdaugs force-pushed the skip-all-solid-cable-queries-by-default branch from 596539f to 3d0b023 Compare November 8, 2024 14:52
Copy link

sonarqubecloud bot commented Nov 8, 2024

Copy link
Owner

@iMacTia iMacTia left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you for adding the README section as well (complete with a ref to the memory leak bug 🙇)

@iMacTia iMacTia merged commit 0d72e79 into iMacTia:master Nov 11, 2024
19 of 20 checks passed

# Initialise configuration with fallback to default values
def setup(config)
Lograge::Sql.formatter = config.formatter || default_formatter
Lograge::Sql.extract_event = config.extract_event || default_extract_event
Lograge::Sql.min_duration_ms = config.min_duration_ms || 0
Lograge::Sql.query_filter = config.query_filter
Lograge::Sql.query_name_denylist = config.query_name_denylist || [/\ASCHEMA\z/, /\ASolidCable::/]
Copy link

Choose a reason for hiding this comment

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

@fdaugs @iMacTia
Perhaps this could be better for performance and avoiding runtime error.

Suggested change
Lograge::Sql.query_name_denylist = config.query_name_denylist || [/\ASCHEMA\z/, /\ASolidCable::/]
Lograge::Sql.query_name_denylist = Regexp.union(config.query_name_denylist || [/\ASCHEMA\z/, /\ASolidCable::/])

related: rails/rails#46452

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kakubin Thanks for the suggestion! #63

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