prometheus-community/json_exporter

Implement QueryUnescape function

javierlga opened this issue · 0 comments

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.