From 21f870d8239c835cc5487bbbe5ee312b669a731d Mon Sep 17 00:00:00 2001 From: AlonMaor14 Date: Wed, 9 Jun 2021 12:52:06 +0300 Subject: [PATCH 1/2] set logger format json --- cmd/prometheus/main.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index 974df615ea6..9e718ed4146 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -256,6 +256,11 @@ func main() { os.Exit(2) } + err = cfg.promlogConfig.Format.Set("json") + if err != nil { + fmt.Fprintln(os.Stderr, errors.Wrapf(err, "could not set log format json")) + os.Exit(2) + } logger := promlog.New(&cfg.promlogConfig) cfg.web.ExternalURL, err = computeExternalURL(cfg.prometheusURL, cfg.web.ListenAddress) From 56b07461c846071a75eb3672797d996200e2ca39 Mon Sep 17 00:00:00 2001 From: AlonMaor14 Date: Wed, 9 Jun 2021 15:18:39 +0300 Subject: [PATCH 2/2] log levels --- storage/tsdb/v3io.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/storage/tsdb/v3io.go b/storage/tsdb/v3io.go index c506ea08cc0..e0d2500f542 100644 --- a/storage/tsdb/v3io.go +++ b/storage/tsdb/v3io.go @@ -56,7 +56,7 @@ type ReadyStorage struct { func (s *ReadyStorage) SetUseV3ioAggregations(useV3ioAggregations bool) { s.useV3ioAggregations = useV3ioAggregations configPath := s.getConfigPath() - s.logger.Log("msg", "Creating v3io adapter after changing v3io aggregation indicator", "configPath", configPath, "useV3ioAggregations", useV3ioAggregations) + level.Info(s.logger).Log("msg", "Creating v3io adapter after changing v3io aggregation indicator", "configPath", configPath, "useV3ioAggregations", useV3ioAggregations) // create the initial v3io adapter adapter, _, err := s.createV3ioPromAdapater(configPath) @@ -81,7 +81,7 @@ func (s *ReadyStorage) Set(db *tsdb.DB, startTimeMargin int64) { // get the config path configPath := s.getConfigPath() - s.logger.Log("msg", "Creating initial v3io adapter", "configPath", configPath) + level.Info(s.logger).Log("msg", "Creating initial v3io adapter", "configPath", configPath) // create the initial v3io adapter adapter, v3ioConfig, err := s.createV3ioPromAdapater(configPath) @@ -122,7 +122,7 @@ func (s *ReadyStorage) Config() *config.V3ioConfig { // Querier implements the Storage interface. func (s *ReadyStorage) Querier(ctx context.Context, mint, maxt int64) (storage.Querier, error) { - s.logger.Log("msg", "Querier requested", "mint", mint, "maxt", maxt) + level.Info(s.logger).Log("msg", "Querier requested", "mint", mint, "maxt", maxt) if s.error != nil { return nil, errors.Wrap(s.error, "cannot return a querier without an adapter") @@ -137,7 +137,7 @@ func (s *ReadyStorage) Querier(ctx context.Context, mint, maxt int64) (storage.Q // Appender implements the Storage interface. func (s *ReadyStorage) Appender() (storage.Appender, error) { - s.logger.Log("msg", "Appender requested") + level.Info(s.logger).Log("msg", "Appender requested") if s.error != nil { return nil, errors.Wrap(s.error, "cannot return an appender without an adapter") @@ -168,7 +168,7 @@ func (s *ReadyStorage) getConfigPath() string { } func (s *ReadyStorage) watchConfigForChanges(configPath string) error { - s.logger.Log("msg", "Starting to watch configuration for changes", "configPath", configPath) + level.Info(s.logger).Log("msg", "Starting to watch configuration for changes", "configPath", configPath) // get initial file mtime lastConfigFileInfo, err := os.Stat(configPath) @@ -195,7 +195,7 @@ func (s *ReadyStorage) watchConfigForChanges(configPath string) error { if lastConfigFileInfo.ModTime() != currentConfigFileInfo.ModTime() { lastConfigFileInfo = currentConfigFileInfo - s.logger.Log("msg", "Config file modification detected, recreating adapter", "configPath", configPath) + level.Debug(s.logger).Log("msg", "Config file modification detected, recreating adapter", "configPath", configPath) config.UpdateConfig(configPath) newV3ioPromAdapter, _, err := s.createV3ioPromAdapater(configPath) @@ -209,7 +209,7 @@ func (s *ReadyStorage) watchConfigForChanges(configPath string) error { } } - s.logger.Log("msg", "Stopping config file change watch") + level.Debug(s.logger).Log("msg", "Stopping config file change watch") }() return nil @@ -223,11 +223,11 @@ func (s *ReadyStorage) createV3ioPromAdapater(configPath string) (*V3ioPromAdapt // if the disabled flag is set, don't create an adapter if loadedConfig.Disabled { - s.logger.Log("msg", "Adapter is disabled, not creating") + level.Info(s.logger).Log("msg", "Adapter is disabled, not creating") return nil, nil, nil } - s.logger.Log("msg", "Creating v3io adapter", "config", loadedConfig.String()) + level.Info(s.logger).Log("msg", "Creating v3io adapter", "config", loadedConfig.String()) adapter, err := NewV3ioProm(loadedConfig, nil) adapter.SetUseV3ioAggregations(s.useV3ioAggregations)