From 4ed4a2e28f83d4474a927d57ecccdf8ef3325505 Mon Sep 17 00:00:00 2001 From: zhanghjster Date: Thu, 5 Nov 2020 14:42:09 +0800 Subject: [PATCH 1/2] add tail_proxy_url option to the query_frontend_config section of configuration doc --- docs/sources/configuration/_index.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/sources/configuration/_index.md b/docs/sources/configuration/_index.md index 2d297b626f2a..04b4d2f1e38f 100644 --- a/docs/sources/configuration/_index.md +++ b/docs/sources/configuration/_index.md @@ -296,6 +296,10 @@ The query_frontend_config configures the Loki query-frontend. # Set to < 0 to enable on all queries. # CLI flag: -frontend.log-queries-longer-than [log_queries_longer_than: | default = 0s] + +# URL of querier for tail proxy. +# CLI flag: -frontend.tail-proxy-url +[tail_proxy_url: | default = ""] ``` ## queryrange_config From 064abc08b51aef6709164c0699ec34724d86db6f Mon Sep 17 00:00:00 2001 From: zhanghjster Date: Thu, 5 Nov 2020 16:27:50 +0800 Subject: [PATCH 2/2] If queryFrontend run in tail proxy mode, append the Host of the tail_proxy_url to the request header, because in some scenario queryFrontend forward tail to the queriers deployed behind nginx and "Host" is required. --- pkg/loki/modules.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/loki/modules.go b/pkg/loki/modules.go index 57640983211f..0de2559c146a 100644 --- a/pkg/loki/modules.go +++ b/pkg/loki/modules.go @@ -383,6 +383,13 @@ func (t *Loki) initQueryFrontend() (_ services.Service, err error) { return nil, err } tp := httputil.NewSingleHostReverseProxy(tailURL) + + director := tp.Director + tp.Director = func(req *http.Request) { + director(req) + req.Host = tailURL.Host + } + defaultHandler = httpMiddleware.Wrap(tp) } else { defaultHandler = frontendHandler