-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
config.go
48 lines (41 loc) · 1.34 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package util
import (
"fmt"
"io"
"strings"
"time"
"github.com/go-kit/log/level"
"github.com/prometheus/common/version"
"gopkg.in/yaml.v2"
util_log "github.com/grafana/loki/v3/pkg/util/log"
)
// 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_log.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
}
// IngesterQueryOptions exists because querier.Config cannot be passed directly to the queryrange package
// due to an import cycle.
type IngesterQueryOptions interface {
QueryStoreOnly() bool
QueryIngestersWithin() time.Duration
}