mirror of
https://github.com/prometheus/prometheus
synced 2024-12-24 23:42:32 +00:00
Updated code based on Juliens comments (via Slack).
Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
This commit is contained in:
parent
fe3fe5740e
commit
a7d3a456d6
@ -34,23 +34,20 @@ func ContextWithPath(ctx context.Context, path string) context.Context {
|
||||
// ContextFromRequest returns a new context with identifiers of
|
||||
// the request to be used later when logging the query.
|
||||
func ContextFromRequest(ctx context.Context, r *http.Request) context.Context {
|
||||
reqCtxVal := map[string]string{
|
||||
"method": r.Method,
|
||||
}
|
||||
|
||||
var ip string
|
||||
if r.RemoteAddr != "" {
|
||||
// r.RemoteAddr has no defined format, so don't return error if we cannot split it into IP:Port.
|
||||
ip, _, _ := net.SplitHostPort(r.RemoteAddr)
|
||||
if ip != "" {
|
||||
reqCtxVal["clientIP"] = ip
|
||||
ip, _, _ = net.SplitHostPort(r.RemoteAddr)
|
||||
}
|
||||
|
||||
var path string
|
||||
if v := ctx.Value(pathParam); v != nil {
|
||||
path = v.(string)
|
||||
reqCtxVal["path"] = path
|
||||
}
|
||||
|
||||
return promql.NewOriginContext(ctx, map[string]interface{}{
|
||||
"httpRequest": reqCtxVal,
|
||||
"httpRequest": map[string]string{
|
||||
"clientIP": ip,
|
||||
"method": r.Method,
|
||||
"path": path,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user