From c1454029bd9f893c37987d4db19ea5f0284c3fcb Mon Sep 17 00:00:00 2001 From: Quanzheng Long Date: Thu, 7 Oct 2021 13:23:28 -0700 Subject: [PATCH 1/3] add metric comment --- common/config/config.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/common/config/config.go b/common/config/config.go index b6797afad67..8c5f8e2ac57 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -340,6 +340,12 @@ type ( // Statsd is the configuration for statsd reporter Statsd *Statsd `yaml:"statsd"` // Prometheus is the configuration for prometheus reporter + // Some documentation below because the tally library is missing it: + // In this configuration, default timerType is "histogram", alternatively "summary" is also supported. + // In some cases, summary is better. Choose it wisely. + // For histogram, default buckets are defined in https://github.com/uber/cadence/blob/master/common/metrics/tally/prometheus/buckets.go#L34 + // For summary, default objectives are defined in https://github.com/uber-go/tally/blob/137973e539cd3589f904c23d0b3a28c579fd0ae4/prometheus/reporter.go#L70 + // You can customize the buckets/objectives if the default is not good enough. Prometheus *prometheus.Configuration `yaml:"prometheus"` // Tags is the set of key-value pairs to be reported // as part of every metric From c67279d61c4cce34a3970fcd045222db02d0af93 Mon Sep 17 00:00:00 2001 From: Quanzheng Long Date: Thu, 7 Oct 2021 13:43:53 -0700 Subject: [PATCH 2/3] Add console as logging encoding type --- common/config/config.go | 10 ++++++++-- common/config/log.go | 10 +++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/common/config/config.go b/common/config/config.go index 8c5f8e2ac57..a9852279022 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -317,14 +317,20 @@ type ( // Logger contains the config items for logger Logger struct { - // Stdout is true if the output needs to goto standard out + // Stdout is true then the output needs to goto standard out + // By default this is false and output will go to standard error Stdout bool `yaml:"stdout"` // Level is the desired log level Level string `yaml:"level"` // OutputFile is the path to the log output file + // Stdout must be false, otherwise Stdout will take precedence OutputFile string `yaml:"outputFile"` - // levelKey is the desired log level, defaults to "level" + // LevelKey is the desired log level, defaults to "level" LevelKey string `yaml:"levelKey"` + // Encoding decides the format, supports "console" and "json". + // "json" will print the log in JSON format(better for machine), while "console" will print in plain-text format(more human friendly) + // Default is "json" + Encoding string `yaml:"encoding"` } // DCRedirectionPolicy contains the frontend datacenter redirection policy diff --git a/common/config/log.go b/common/config/log.go index e5ac50111a2..85e634dcb4b 100644 --- a/common/config/log.go +++ b/common/config/log.go @@ -21,6 +21,7 @@ package config import ( + "fmt" "os" "strings" @@ -60,11 +61,18 @@ func (cfg *Logger) NewZapLogger() (*zap.Logger, error) { } } + encoding := "json" + if cfg.Encoding == "json" || cfg.Encoding == "console" { + encoding = cfg.Encoding + } else { + return nil, fmt.Errorf("invalid encoding for log, only supporting json or console") + } + config := zap.Config{ Level: zap.NewAtomicLevelAt(parseZapLevel(cfg.Level)), Development: false, Sampling: nil, // consider exposing this to config for our external customer - Encoding: "json", + Encoding: encoding, EncoderConfig: encodeConfig, OutputPaths: []string{outputPath}, ErrorOutputPaths: []string{outputPath}, From 70c8ac0100d3429d5fb21ecf6c69a2cdabad5706 Mon Sep 17 00:00:00 2001 From: Quanzheng Long Date: Thu, 7 Oct 2021 14:50:04 -0700 Subject: [PATCH 3/3] fix --- common/config/log.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/common/config/log.go b/common/config/log.go index 85e634dcb4b..c30b3744d2f 100644 --- a/common/config/log.go +++ b/common/config/log.go @@ -62,10 +62,12 @@ func (cfg *Logger) NewZapLogger() (*zap.Logger, error) { } encoding := "json" - if cfg.Encoding == "json" || cfg.Encoding == "console" { - encoding = cfg.Encoding - } else { - return nil, fmt.Errorf("invalid encoding for log, only supporting json or console") + if cfg.Encoding != "" { + if cfg.Encoding == "json" || cfg.Encoding == "console" { + encoding = cfg.Encoding + } else { + return nil, fmt.Errorf("invalid encoding for log, only supporting json or console") + } } config := zap.Config{