-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loki: add -print-config-stderr flag to dump loki's runtime config to …
…stderr (#2336) * Loki: add -print-config-stderr flag to dump loki's runtime config to stderr * add ability to print inline config for better readability in grafana * add an option to log the config in reverse order to make viewing in Grafana easier. Also added this capability to Promtail
- Loading branch information
Showing
6 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package util | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"strings" | ||
|
||
"github.com/cortexproject/cortex/pkg/util" | ||
"github.com/go-kit/kit/log/level" | ||
"github.com/prometheus/common/version" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
// LogConfig takes a pointer to a config object, marshalls it to YAML and prints each line in REVERSE order | ||
// The reverse order makes display in Grafana in easier which typically sorts newest entries at the top. | ||
func LogConfig(cfg interface{}) error { | ||
lc, err := yaml.Marshal(cfg) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cfgStr := string(lc) | ||
cfgStrs := strings.Split(cfgStr, "\n") | ||
for i := len(cfgStrs) - 1; i >= 0; i-- { | ||
level.Info(util.Logger).Log("type", "config", "msg", cfgStrs[i]) | ||
} | ||
return nil | ||
} | ||
|
||
// PrintConfig will takes a pointer to a config object, marshalls it to YAML and prints the result to the provided writer | ||
// unlike LogConfig, PrintConfig prints the object in naturally ocurring order. | ||
func PrintConfig(w io.Writer, config interface{}) error { | ||
lc, err := yaml.Marshal(config) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Fprintf(w, "---\n# Loki Config\n# %s\n%s\n\n", version.Info(), string(lc)) | ||
return nil | ||
} |