From 725f8174b103e153b3c898f5d5ab1bb338c02e36 Mon Sep 17 00:00:00 2001 From: Thomas Jackson Date: Sat, 13 Jul 2024 21:36:50 -0700 Subject: [PATCH] Wire up Promql query logging Fixes #653 --- cmd/promxy/main.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cmd/promxy/main.go b/cmd/promxy/main.go index a55ec8813..7ed8a5030 100644 --- a/cmd/promxy/main.go +++ b/cmd/promxy/main.go @@ -38,6 +38,7 @@ import ( "github.com/prometheus/prometheus/rules" "github.com/prometheus/prometheus/scrape" "github.com/prometheus/prometheus/storage" + promlogging "github.com/prometheus/prometheus/util/logging" "github.com/prometheus/prometheus/util/strutil" "github.com/prometheus/prometheus/web" "github.com/sirupsen/logrus" @@ -369,6 +370,22 @@ func main() { return nil }})) + // PromQL query engine reloadable + reloadables = append(reloadables, proxyconfig.WrapPromReloadable(&proxyconfig.ApplyConfigFunc{func(cfg *config.Config) error { + if cfg.GlobalConfig.QueryLogFile == "" { + engine.SetQueryLogger(nil) + return nil + } + + l, err := promlogging.NewJSONFileLogger(cfg.GlobalConfig.QueryLogFile) + if err != nil { + return err + } + engine.SetQueryLogger(l) + + return nil + }})) + // We need an empty scrape manager, simply to make the API not panic and error out scrapeManager := scrape.NewManager(nil, kitlog.With(logger, "component", "scrape manager"), nil)