Skip to content

perf: configurable HTTP compression, NR auto-disable, response time log config#58

Merged
ankurs merged 6 commits intomainfrom
perf/throughput-improvements
Apr 3, 2026
Merged

perf: configurable HTTP compression, NR auto-disable, response time log config#58
ankurs merged 6 commits intomainfrom
perf/throughput-improvements

Conversation

@ankurs
Copy link
Copy Markdown
Member

@ankurs ankurs commented Apr 2, 2026

Summary

  • HTTP compression config: DISABLE_HTTP_COMPRESSION and HTTP_COMPRESSION_MIN_SIZE (default: 256 bytes). Applies to both gzip and zstd. Responses smaller than min-size are sent uncompressed.
  • NR auto-disable: When DISABLE_NEW_RELIC is false but NEW_RELIC_LICENSE_KEY is empty, NR is auto-disabled to avoid interceptor overhead.
  • Response time log level: RESPONSE_TIME_LOG_LEVEL config (default: "info"). Invalid values fall back to info.
  • Error-only response time logging: RESPONSE_TIME_LOG_ERROR_ONLY config (default: false). When true, only logs response time for errored requests.

Note: Requires go-coldbrew/interceptors with SetResponseTimeLogErrorOnly (PR go-coldbrew/interceptors#28). Uses replace directive for local testing; will bump interceptors version after merge.

Test plan

  • go test -race ./... passes (with local replace)
  • Verify gzip min-size threshold works
  • Verify NR auto-disable when license empty
  • Verify response time log level config

Summary by CodeRabbit

  • New Features
    • Added HTTP compression controls—disable compression or configure minimum payload size threshold
    • Configurable response time logging with adjustable verbosity levels and error-only filtering option
    • Automatic New Relic deactivation when license key is not provided

…og config

- Add DISABLE_HTTP_COMPRESSION and HTTP_COMPRESSION_MIN_SIZE config
  (default: 256 bytes). Applies to both gzip and zstd.
- Auto-disable NewRelic when license key is empty to avoid interceptor
  overhead for services that don't use NR.
- Add RESPONSE_TIME_LOG_LEVEL config (default: "info"). Invalid values
  fall back to info. Wired via ConfigureInterceptors.
- Add RESPONSE_TIME_LOG_ERROR_ONLY config (default: false). When true,
  only logs response time for requests that return errors.
Copilot AI review requested due to automatic review settings April 2, 2026 18:24
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 2, 2026

Warning

Rate limit exceeded

@ankurs has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 9 minutes and 24 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 9 minutes and 24 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c126919f-36f8-46ee-981a-032335aa6496

📥 Commits

Reviewing files that changed from the base of the PR and between aad70fb and 4a46e81.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (4)
  • config/config.go
  • core.go
  • go.mod
  • initializers.go
📝 Walkthrough

Walkthrough

The pull request adds four new configuration fields to the Config struct for HTTP compression control (DisableHTTPCompression, HTTPCompressionMinSize) and response-time logging (ResponseTimeLogLevel, ResponseTimeLogErrorOnly). It updates HTTP compression middleware setup to conditionally apply gzip based on these settings, modifies the ConfigureInterceptors function signature to accept the logging parameters, and adds a New Relic auto-disable logic based on license key presence.

Changes

Cohort / File(s) Summary
Configuration
config/config.go
Added four new config fields: DisableHTTPCompression, HTTPCompressionMinSize (default 256), ResponseTimeLogLevel (default "info"), and ResponseTimeLogErrorOnly (default false), each with corresponding environment variable mappings.
HTTP Compression & Interceptor Setup
core.go, initializers.go
Updated HTTP compression middleware to conditionally apply gzip wrapper based on DisableHTTPCompression flag; extended ConfigureInterceptors signature to accept responseTimeLogLevel and responseTimeLogErrorOnly parameters; added log level parsing via loggers.ParseLevel with fallback to InfoLevel; applied parsed level and error-only flag to interceptors package.
New Relic Initialization
core.go
Added automatic config mutation to set DisableNewRelic to true when NewRelicLicenseKey is empty and DisableNewRelic is initially false.
Test Updates
core_coverage_test.go
Updated test call to ConfigureInterceptors to pass the two new parameters ("info", false) matching the updated function signature.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • svetha-cvl

Poem

🐰 Hops of compression and logging delight,
Config fields dance in the morning light,
With gzip and traces all set just right,
The rabbit approves—what a thoughtful sight! 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures all three main features: configurable HTTP compression, New Relic auto-disable, and response time logging configuration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/throughput-improvements

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

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 adds new runtime configuration knobs for HTTP response compression and response-time logging, and reduces New Relic overhead when it’s effectively unconfigured.

Changes:

  • Add HTTP compression toggles and a minimum-size threshold for applying compression.
  • Auto-disable New Relic when DISABLE_NEW_RELIC=false but no license key is set.
  • Add interceptor configuration for response-time log level and “error-only” response-time logging.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
core.go Adds NR auto-disable logic and makes HTTP compression conditional with a configurable min-size.
initializers.go Extends ConfigureInterceptors to configure response-time logging settings.
config/config.go Introduces new env-configured fields for compression and response-time logging.
core_coverage_test.go Updates the interceptor configuration call site for the new signature.
go.sum Removes go-coldbrew/interceptors sums (currently inconsistent with go.mod).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core.go Outdated
Comment thread core.go Outdated
Comment thread config/config.go
Comment thread core.go Outdated
Comment thread core.go Outdated
Copy link
Copy Markdown

@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.

🧹 Nitpick comments (2)
config/config.go (1)

138-151: New configuration fields are well-structured.

The new throughput tuning fields are properly documented with sensible defaults. A few observations:

  1. The comment on line 141 mentions "gzip/zstd compression" but the implementation in core.go only uses gzhttp (gzip). Consider updating the comment to reflect the actual implementation or add zstd support if intended.

  2. Consider adding validation for HTTPCompressionMinSize in the Validate() method to warn if negative values are configured.

Optional: Add validation for HTTPCompressionMinSize
 func (c Config) Validate() []string {
 	var warnings []string
 
+	if c.HTTPCompressionMinSize < 0 {
+		warnings = append(warnings, "HTTPCompressionMinSize should be non-negative")
+	}
 	if c.GRPCPort < 0 || c.GRPCPort > 65535 {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@config/config.go` around lines 138 - 151, Update the config comments and
validation: change the comment on DisableHTTPCompression/HTTPCompressionMinSize
to reflect that only gzip is currently used (gzhttp in core.go) or note "gzip
(zstd not implemented)" so it matches the implementation, and add a validation
check inside the existing Validate() method to ensure HTTPCompressionMinSize is
non-negative (return or log a validation error if HTTPCompressionMinSize < 0);
reference the config struct fields DisableHTTPCompression,
HTTPCompressionMinSize, ResponseTimeLogLevel and the Validate() function and
mention gzhttp/core.go as the place tied to gzip behavior.
core_coverage_test.go (1)

1167-1168: Test updated to match new signature.

The test correctly passes the new responseTimeLogLevel and responseTimeLogErrorOnly parameters.

Consider adding test cases for edge conditions:

  • Invalid log level string (to verify fallback behavior)
  • responseTimeLogErrorOnly set to true
  • Empty responseTimeLogLevel string
Optional: Additional test cases
 func TestConfigureInterceptors_BothBranches(t *testing.T) {
 	ConfigureInterceptors(true, "X-My-Trace", "info", false)
 }
+
+func TestConfigureInterceptors_InvalidLogLevel(t *testing.T) {
+	// Should not panic; falls back to info level
+	ConfigureInterceptors(false, "", "invalid-level", false)
+}
+
+func TestConfigureInterceptors_ErrorOnly(t *testing.T) {
+	ConfigureInterceptors(false, "", "debug", true)
+}
+
+func TestConfigureInterceptors_EmptyLogLevel(t *testing.T) {
+	// Empty log level should skip SetResponseTimeLogLevel call
+	ConfigureInterceptors(false, "", "", true)
+}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core_coverage_test.go` around lines 1167 - 1168, Add unit tests for
ConfigureInterceptors to cover edge conditions: create separate Test cases that
call ConfigureInterceptors using an invalid log level string (e.g., "invalid")
to assert it falls back to the default level, a case with
responseTimeLogErrorOnly set to true to verify only error responses are logged,
and a case with an empty responseTimeLogLevel string to confirm default
behavior; reference the ConfigureInterceptors function and assert expected
logging behavior or no panics for each scenario.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@config/config.go`:
- Around line 138-151: Update the config comments and validation: change the
comment on DisableHTTPCompression/HTTPCompressionMinSize to reflect that only
gzip is currently used (gzhttp in core.go) or note "gzip (zstd not implemented)"
so it matches the implementation, and add a validation check inside the existing
Validate() method to ensure HTTPCompressionMinSize is non-negative (return or
log a validation error if HTTPCompressionMinSize < 0); reference the config
struct fields DisableHTTPCompression, HTTPCompressionMinSize,
ResponseTimeLogLevel and the Validate() function and mention gzhttp/core.go as
the place tied to gzip behavior.

In `@core_coverage_test.go`:
- Around line 1167-1168: Add unit tests for ConfigureInterceptors to cover edge
conditions: create separate Test cases that call ConfigureInterceptors using an
invalid log level string (e.g., "invalid") to assert it falls back to the
default level, a case with responseTimeLogErrorOnly set to true to verify only
error responses are logged, and a case with an empty responseTimeLogLevel string
to confirm default behavior; reference the ConfigureInterceptors function and
assert expected logging behavior or no panics for each scenario.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bfa55c2b-c9f9-4c2e-9ae4-82b6cb38139f

📥 Commits

Reviewing files that changed from the base of the PR and between cf671db and aad70fb.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (4)
  • config/config.go
  • core.go
  • core_coverage_test.go
  • initializers.go

Copy link
Copy Markdown
Contributor

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

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread initializers.go
Comment thread config/config.go
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread config/config.go Outdated
ankurs added 3 commits April 3, 2026 15:33
- options v0.2.6 -> v0.2.7 (RWMutex+map)
- log v0.2.8 -> v0.2.9 (RWMutex+map, nil ctx guard)
- errors v0.2.6 -> v0.2.9 (OTEL trace ID linkage)
- interceptors v0.1.13 -> v0.1.15 (NR short-circuit, error-only logging)
- Remove replace directive
@ankurs ankurs merged commit bf21de6 into main Apr 3, 2026
7 checks passed
@ankurs ankurs deleted the perf/throughput-improvements branch April 3, 2026 08:10
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.

2 participants