Skip to content

Commit

Permalink
Loki: add -print-config-stderr flag to dump loki's runtime config to …
Browse files Browse the repository at this point in the history
…stderr
  • Loading branch information
slim-bean committed Jul 11, 2020
1 parent 7889e01 commit ff43ca7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cmd/loki/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 6 additions & 0 deletions docs/best-practices/current-best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
14 changes: 14 additions & 0 deletions docs/configuration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit ff43ca7

Please sign in to comment.