Skip to content

feat: allow disabling the request and response size histograms - #6

Open
brommell wants to merge 1 commit into
labstack:mainfrom
brommell:feat/disable-size-histograms
Open

brommell wants to merge 1 commit into
labstack:mainfrom
brommell:feat/disable-size-histograms

Conversation

@brommell

Copy link
Copy Markdown

Summary

Adds two MiddlewareConfig options, DisableRequestSizeMetric and DisableResponseSizeMetric. A disabled histogram
is neither registered nor observed, and the approximate request size is no longer computed when nothing uses it.
Defaults are unchanged: both histograms stay on unless switched off.

Why

The middleware always registers four metrics. With the default buckets, every url/method/code/host
combination produces 41 series:

Metric Series per combination
requests_total 1
request_duration_seconds 14
request_size_bytes 13
response_size_bytes 13

The two size histograms are 26 of the 41, more than half of what the middleware stores, and many services never look
at them. Request and response sizes are often already measured by a proxy or ingress in front of the application.

There was no way to drop them: HistogramOptsFunc can change the buckets but not remove a metric. The only option
left was copying the whole middleware, which is what was suggested in labstack/echo-contrib#109 ("Disable certain
prometheus metrics", open since 2024-02). That issue asked whether such an option would be accepted; this PR is the
implementation.

Scope

Only the size histograms get a switch. requests_total and request_duration_seconds are the core of the middleware
and stay always on. A duration switch would be easy to add in the same way if you think it's useful.

Tests

  • New TestMiddlewareConfig_DisableSizeMetrics: with both options set, request_duration_seconds is still exported
    and neither size metric is.
  • go vet, go test -race and staticcheck pass on Go 1.26.

Co-Authored-By: Claude Opus 5.5 [email protected]

The two size histograms make up 26 of the 41 series created for every
url/method/code combination, and there was no way to turn them off
short of copying the middleware (labstack/echo-contrib#109).

DisableRequestSizeMetric and DisableResponseSizeMetric skip
registering and observing them. The request size is no longer
computed when its histogram is disabled. Defaults are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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