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 IgnoredPaths option #111

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

angristan
Copy link

@angristan angristan commented Feb 8, 2022

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

@angristan angristan requested a review from slok as a code owner February 8, 2022 12:54
@angristan angristan changed the title Add IgnorePaths option Add IgnoredPaths option Feb 8, 2022
@slok
Copy link
Owner

slok commented Feb 11, 2022

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?

@angristan
Copy link
Author

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

@Miaourt
Copy link

Miaourt commented Dec 2, 2022

Hello @slok !
Would it be possible to merge this ?

@kudiyarov
Copy link

Would be very helpful even only with StaticPaths

@FedeBev
Copy link

FedeBev commented Dec 18, 2023

Hey @slok

is there any plan to merge this?

Thank you!

@slok
Copy link
Owner

slok commented Apr 19, 2024

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 :)

@angristan
Copy link
Author

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 :)

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.

Set ignore path
5 participants