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

Implement QueryUnescape function #232

Open
javierlga opened this issue May 15, 2023 · 0 comments
Open

Implement QueryUnescape function #232

javierlga opened this issue May 15, 2023 · 0 comments

Comments

@javierlga
Copy link

Hello,

When using Prometheus service discovery configuration in Kubernetes along with some relabel configs for the address, the parameters in the target are decoded, example: http://metrics_exporter.namespace:7979/probe?module=default&target=X.X.X.X%3A5000%2Fv1%2Fmetrics

This is causing the following errors in Prometheus and the exporter:

Get "http://metrics_exporter.namespace:7979/probe?module=default&target=X.X.X.X%3A5000%2Fv1%2Fmetrics": EOF

JSON exporter:

2023/05/15 17:44:10 http: panic serving 240.9.188.6:49122: runtime error: invalid memory address or nil pointer dereference
goroutine 2972 [running]:
net/http.(*conn).serve.func1()
	/usr/local/go/src/net/http/server.go:1825 +0xbf
panic({0x98f180, 0xe9d3a0})
	/usr/local/go/src/runtime/panic.go:844 +0x258
net/http.(*Request).WithContext(...)
	/usr/local/go/src/net/http/request.go:360
github.com/prometheus-community/json_exporter/exporter.(*JSONFetcher).FetchJSON(0xc0000e6480, {0xc0000b60e0, 0x1d})
	/app/exporter/util.go:158 +0x1bb
github.com/prometheus-community/json_exporter/cmd.probeHandler({0xb0e140, 0xc0004ae460}, 0xc0003d2800, {0xb09e20, 0xc00002ad40}, {0x4f13a9?})
	/app/cmd/main.go:117 +0x7ba
github.com/prometheus-community/json_exporter/cmd.Run.func1({0xb0e140?, 0xc0004ae460?}, 0x0?)
	/app/cmd/main.go:74 +0x2f
net/http.HandlerFunc.ServeHTTP(0x7fdba281ec58?, {0xb0e140?, 0xc0004ae460?}, 0x40d485?)
	/usr/local/go/src/net/http/server.go:2084 +0x2f
net/http.(*ServeMux).ServeHTTP(0xc00051b9fb?, {0xb0e140, 0xc0004ae460}, 0xc0003d2800)
	/usr/local/go/src/net/http/server.go:2462 +0x149
net/http.serverHandler.ServeHTTP({0xc00041ce40?}, {0xb0e140, 0xc0004ae460}, 0xc0003d2800)
	/usr/local/go/src/net/http/server.go:2916 +0x43b
net/http.(*conn).serve(0xc0006681e0, {0xb0e700, 0xc0002b6d50})
	/usr/local/go/src/net/http/server.go:1966 +0x5d7
created by net/http.(*Server).Serve
	/usr/local/go/src/net/http/server.go:3071 +0x4db

Looking at the FetchJSON function, this is expecting the URL to be a regular string https://github.com/prometheus-community/json_exporter/blob/master/exporter/util.go#L162-L217, but in some uses cases, the URL must be decoded first, so ideally the QueryUnescape function should be used for those scenarios.

Thanks.

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

No branches or pull requests

1 participant