Repository navigation
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two
MiddlewareConfigoptions,DisableRequestSizeMetricandDisableResponseSizeMetric. A disabled histogramis 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/hostcombination produces 41 series:
requests_totalrequest_duration_secondsrequest_size_bytesresponse_size_bytesThe 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:
HistogramOptsFunccan change the buckets but not remove a metric. The only optionleft 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_totalandrequest_duration_secondsare the core of the middlewareand stay always on. A duration switch would be easy to add in the same way if you think it's useful.
Tests
TestMiddlewareConfig_DisableSizeMetrics: with both options set,request_duration_secondsis still exportedand neither size metric is.
go vet,go test -raceandstaticcheckpass on Go 1.26.Co-Authored-By: Claude Opus 5.5 [email protected]