From ff43ca7a2e0f736bd2d7ba595f028a9b31f0b510 Mon Sep 17 00:00:00 2001 From: Edward Welch Date: Fri, 10 Jul 2020 10:34:11 -0400 Subject: [PATCH] Loki: add -print-config-stderr flag to dump loki's runtime config to stderr --- cmd/loki/main.go | 11 +++++++++++ docs/best-practices/current-best-practices.md | 6 ++++++ docs/configuration/README.md | 14 ++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/cmd/loki/main.go b/cmd/loki/main.go index fb2725e14932..c287b3f6b202 100644 --- a/cmd/loki/main.go +++ b/cmd/loki/main.go @@ -11,6 +11,7 @@ import ( "github.com/prometheus/common/version" "github.com/weaveworks/common/logging" "github.com/weaveworks/common/tracing" + "gopkg.in/yaml.v2" _ "github.com/grafana/loki/pkg/build" "github.com/grafana/loki/pkg/cfg" @@ -27,6 +28,7 @@ func init() { func main() { printVersion := flag.Bool("version", false, "Print this builds version information") + printConfig := flag.Bool("print-config-stderr", false, "Dump the entire YAML config Loki will run with to stderr") var config loki.Config if err := cfg.Parse(&config); err != nil { @@ -58,6 +60,15 @@ func main() { os.Exit(1) } + if *printConfig { + lc, err := yaml.Marshal(&config) + if err != nil { + level.Error(util.Logger).Log("msg", "failed to marshal config for pretty printing", "err", err.Error()) + } else { + fmt.Fprintf(os.Stderr, "---\n# Loki Config\n# %s\n%s\n\n", version.Info(), string(lc)) + } + } + if config.Tracing.Enabled { // Setting the environment variable JAEGER_AGENT_HOST enables tracing trace, err := tracing.NewFromEnv(fmt.Sprintf("loki-%s", config.Target)) diff --git a/docs/best-practices/current-best-practices.md b/docs/best-practices/current-best-practices.md index de95aeeb0044..4a160ead6479 100644 --- a/docs/best-practices/current-best-practices.md +++ b/docs/best-practices/current-best-practices.md @@ -86,3 +86,9 @@ Depending on the compression used (we have been using snappy which has less comp Lots of small, unfilled chunks are currently kryptonite for Loki. We are always working to improve this and may consider a compactor to improve this in some situations. But, in general, the guidance should stay about the same: Try your best to fill chunks! If you have an application that can log fast enough to fill these chunks quickly (much less than `max_chunk_age`), then it becomes more reasonable to use dynamic labels to break that up into separate streams. + +## 8. Use `-print-config-stderr` + +Starting in version 1.6.0 Loki has a flag which will dump the entire config object to stderr when Loki starts. + +We run Loki with this flag in all our environments and suggest you do too, it can be invaluable for debugging configuration issues as well as confirming the configuration Loki is currently running with. \ No newline at end of file diff --git a/docs/configuration/README.md b/docs/configuration/README.md index d1666e328cb7..18e0d24daed9 100644 --- a/docs/configuration/README.md +++ b/docs/configuration/README.md @@ -6,6 +6,7 @@ depending on which mode Loki is launched in. Configuration examples can be found in the [Configuration Examples](examples.md) document. +* [Printing Loki Config At Runtime](#printing-loki-config-at-runtime) * [Configuration File Reference](#configuration-file-reference) * [server_config](#server_config) * [distributor_config](#distributor_config) @@ -29,6 +30,19 @@ Configuration examples can be found in the [Configuration Examples](examples.md) * [tracing_config](#tracing_config) * [Runtime Configuration file](#runtime-configuration-file) +## Printing Loki Config At Runtime + +If you pass Loki the flag `-print-config-stderr`, (or `-print-config-stderr=true`) +Loki will dump the entire config object it has created from the built in defaults combined first with +overrides from config file, and second by overrides from flags. + +The result is the value for every config object in the Loki config struct, which is very large... + +Many values will not be relevant to your install such as storage configs which you are not using and which you did not define, +this is expected as every option has a default value if it is being used or not. + +This config is what Loki will use to run, it can be invaluable for debugging issues related to configuration and +is especially useful in making sure your config files and flags are being read and loaded properly. ## Configuration File Reference