From 36b2d3f5eb1939075d5eec8d74f7dc23741a7040 Mon Sep 17 00:00:00 2001 From: crandl201 Date: Fri, 16 Dec 2016 20:04:20 -0500 Subject: [PATCH] etcdmain: add --metrics flag for exposing histogram metrics this adds a new flag, --metrics, that can be used to enable extensive (histogram) metrics. Fixes #7024 --- Documentation/op-guide/configuration.md | 6 +++++- embed/config.go | 2 ++ etcdmain/config.go | 3 +++ etcdmain/etcd.go | 5 +++++ etcdmain/help.go | 4 +++- 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Documentation/op-guide/configuration.md b/Documentation/op-guide/configuration.md index a9e006e13..1ae45f51a 100644 --- a/Documentation/op-guide/configuration.md +++ b/Documentation/op-guide/configuration.md @@ -247,7 +247,7 @@ The security flags help to [build a secure etcd cluster][security]. + env variable: ETCD_DEBUG ### --log-package-levels -+ Set individual etcd subpackages to specific log levels. An example being `etcdserver=WARNING,security=DEBUG` ++ Set individual etcd subpackages to specific log levels. An example being `etcdserver=WARNING,security=DEBUG` + default: none (INFO for all packages) + env variable: ETCD_LOG_PACKAGE_LEVELS @@ -279,6 +279,10 @@ Follow the instructions when using these flags. + Enable runtime profiling data via HTTP server. Address is at client URL + "/debug/pprof/" + default: false +### --metrics ++ Set level of detail for exported metrics, specify 'extensive' to include histogram metrics. ++ default: basic + [build-cluster]: clustering.md#static [reconfig]: runtime-configuration.md [discovery]: clustering.md#discovery diff --git a/embed/config.go b/embed/config.go index ca69b6393..5dc267b59 100644 --- a/embed/config.go +++ b/embed/config.go @@ -115,6 +115,7 @@ type Config struct { Debug bool `json:"debug"` LogPkgLevels string `json:"log-package-levels"` EnablePprof bool + Metrics string `json:"metrics"` // ForceNewCluster starts a new cluster even if previously started; unsafe. ForceNewCluster bool `json:"force-new-cluster"` @@ -173,6 +174,7 @@ func NewConfig() *Config { ClusterState: ClusterStateFlagNew, InitialClusterToken: "etcd-cluster", StrictReconfigCheck: true, + Metrics: "basic", } cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name) return cfg diff --git a/etcdmain/config.go b/etcdmain/config.go index 816bf729b..4037ff768 100644 --- a/etcdmain/config.go +++ b/etcdmain/config.go @@ -198,6 +198,9 @@ func newConfig() *config { // pprof profiler via HTTP fs.BoolVar(&cfg.EnablePprof, "enable-pprof", false, "Enable runtime profiling data via HTTP server. Address is at client URL + \"/debug/pprof/\"") + // additional metrics + fs.StringVar(&cfg.Metrics, "metrics", cfg.Metrics, "Set level of detail for exported metrics, specify 'extensive' to include histogram metrics") + // ignored for _, f := range cfg.ignored { fs.Var(&flags.IgnoredFlag{Name: f}, f, "") diff --git a/etcdmain/etcd.go b/etcdmain/etcd.go index fd990950a..75cc9e499 100644 --- a/etcdmain/etcd.go +++ b/etcdmain/etcd.go @@ -42,6 +42,7 @@ import ( "github.com/coreos/go-systemd/daemon" systemdutil "github.com/coreos/go-systemd/util" "github.com/coreos/pkg/capnslog" + "github.com/grpc-ecosystem/go-grpc-prometheus" "github.com/prometheus/client_golang/prometheus" "google.golang.org/grpc" ) @@ -197,6 +198,10 @@ func startEtcd(cfg *embed.Config) (<-chan struct{}, <-chan error, error) { } } + if cfg.Metrics == "extensive" { + grpc_prometheus.EnableHandlingTimeHistogram() + } + e, err := embed.StartEtcd(cfg) if err != nil { return nil, nil, err diff --git a/etcdmain/help.go b/etcdmain/help.go index b2fc579d6..0ce4be636 100644 --- a/etcdmain/help.go +++ b/etcdmain/help.go @@ -149,9 +149,11 @@ given by the consensus protocol. --force-new-cluster 'false' force to create a new one-member cluster. - + profiling flags: --enable-pprof 'false' Enable runtime profiling data via HTTP server. Address is at client URL + "/debug/pprof/" + --metrics 'basic' + Set level of detail for exported metrics, specify 'extensive' to include histogram metrics. ` )