go-http-metrics
go-http-metrics copied to clipboard
Add IgnoredPaths option
Close #100
With this diff:
diff --git a/examples/default/main.go b/examples/default/main.go
index b5bcc33..3c69f1e 100644
--- a/examples/default/main.go
+++ b/examples/default/main.go
@@ -29,7 +29,8 @@ const (
func main() {
// Create our middleware.
mdlw := middleware.New(middleware.Config{
- Recorder: metrics.NewRecorder(metrics.Config{}),
+ Recorder: metrics.NewRecorder(metrics.Config{}),
+ IgnoredPaths: []string{"/test1"},
})
// Create our server.
➜ curl localhost:8080/test1
➜ curl localhost:8080/test2
Resulting metrics:
➜ curl -s localhost:8081/metrics | grep -v '#' | grep -v 'go_' | grep -v promhttp
http_request_duration_seconds_bucket{code="204",handler="/test2",method="GET",service="",le="0.005"} 1
http_request_duration_seconds_bucket{code="204",handler="/test2",method="GET",service="",le="0.01"} 1
http_request_duration_seconds_bucket{code="204",handler="/test2",method="GET",service="",le="0.025"} 1
http_request_duration_seconds_bucket{code="204",handler="/test2",method="GET",service="",le="0.05"} 1
http_request_duration_seconds_bucket{code="204",handler="/test2",method="GET",service="",le="0.1"} 1
http_request_duration_seconds_bucket{code="204",handler="/test2",method="GET",service="",le="0.25"} 1
http_request_duration_seconds_bucket{code="204",handler="/test2",method="GET",service="",le="0.5"} 1
http_request_duration_seconds_bucket{code="204",handler="/test2",method="GET",service="",le="1"} 1
http_request_duration_seconds_bucket{code="204",handler="/test2",method="GET",service="",le="2.5"} 1
http_request_duration_seconds_bucket{code="204",handler="/test2",method="GET",service="",le="5"} 1
http_request_duration_seconds_bucket{code="204",handler="/test2",method="GET",service="",le="10"} 1
http_request_duration_seconds_bucket{code="204",handler="/test2",method="GET",service="",le="+Inf"} 1
http_request_duration_seconds_sum{code="204",handler="/test2",method="GET",service=""} 3.558e-06
http_request_duration_seconds_count{code="204",handler="/test2",method="GET",service=""} 1
http_requests_inflight{handler="/test1",service=""} 0
http_requests_inflight{handler="/test2",service=""} 0
http_response_size_bytes_bucket{code="204",handler="/test2",method="GET",service="",le="100"} 1
http_response_size_bytes_bucket{code="204",handler="/test2",method="GET",service="",le="1000"} 1
http_response_size_bytes_bucket{code="204",handler="/test2",method="GET",service="",le="10000"} 1
http_response_size_bytes_bucket{code="204",handler="/test2",method="GET",service="",le="100000"} 1
http_response_size_bytes_bucket{code="204",handler="/test2",method="GET",service="",le="1e+06"} 1
http_response_size_bytes_bucket{code="204",handler="/test2",method="GET",service="",le="1e+07"} 1
http_response_size_bytes_bucket{code="204",handler="/test2",method="GET",service="",le="1e+08"} 1
http_response_size_bytes_bucket{code="204",handler="/test2",method="GET",service="",le="1e+09"} 1
http_response_size_bytes_bucket{code="204",handler="/test2",method="GET",service="",le="+Inf"} 1
http_response_size_bytes_sum{code="204",handler="/test2",method="GET",service=""} 0
http_response_size_bytes_count{code="204",handler="/test2",method="GET",service=""} 1
Hi @angristan Thanks for the PR!
This proposed feature by #100 is indeed a very nice feature.
Taking your feature and thinking a bit more in the use cases, would make sense to use a list of complied Regexes instead of raw strings?
The only tradeoff that I would see with string comparison VS regex, is that the regexes are less efficient
WDYT?
@slok Sure, why not!
My current need is only a static list of paths, but I think that regexes probably make sense for most of the use cases.
I would be fine with going regex-only, otherwise a tradeoff could be to have two options, or a single option with two fields like so:
IgnoredPaths struct {
StaticPaths []string
RegexPaths []string
}
Hello @slok ! Would it be possible to merge this ?
Would be very helpful even only with StaticPaths
Hey @slok
is there any plan to merge this?
Thank you!
Lets do this then, however I would suggest using an map instead of a list as the list and the loop would have performance impact on the hot path and using an index would be faster. Also lets add some tests please :)
I would suggest using an map instead of a list as the list and the loop would have performance impact on the hot path and using an index would be faster.
Very good point!
Also lets add some tests please :)
I added a test :)