diff --git a/Makefile.common b/Makefile.common index 8e135c554..5547c9bad 100644 --- a/Makefile.common +++ b/Makefile.common @@ -140,8 +140,9 @@ else ifdef GO111MODULE @echo ">> running check for unused/missing packages in go.mod" GO111MODULE=$(GO111MODULE) $(GO) mod tidy +ifeq (,$(wildcard vendor)) @git diff --exit-code -- go.sum go.mod -ifneq (,$(wildcard vendor)) +else @echo ">> running check for unused packages in vendor/" GO111MODULE=$(GO111MODULE) $(GO) mod vendor @git diff --exit-code -- go.sum go.mod vendor/ diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index a7b593f11..a10744db9 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -34,6 +34,7 @@ import ( "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" + "github.com/golang/glog" "github.com/oklog/oklog/pkg/group" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -41,7 +42,6 @@ import ( "github.com/prometheus/common/version" prom_runtime "github.com/prometheus/prometheus/pkg/runtime" "gopkg.in/alecthomas/kingpin.v2" - k8s_runtime "k8s.io/apimachinery/pkg/util/runtime" "github.com/mwitkow/go-conntrack" "github.com/prometheus/common/promlog" @@ -236,14 +236,9 @@ func main() { logger := promlog.New(&cfg.promlogConfig) - // XXX(fabxc): Kubernetes does background logging which we can only customize by modifying - // a global variable. - // Ultimately, here is the best place to set it. - k8s_runtime.ErrorHandlers = []func(error){ - func(err error) { - level.Error(log.With(logger, "component", "k8s_client_runtime")).Log("err", err) - }, - } + // Above level 6, the k8s client would log bearer tokens in clear-text. + glog.ClampLevel(6) + glog.SetLogger(log.With(logger, "component", "k8s_client_runtime")) level.Info(logger).Log("msg", "Starting Prometheus", "version", version.Info()) level.Info(logger).Log("build_context", version.BuildContext()) diff --git a/discovery/kubernetes/client_metrics.go b/discovery/kubernetes/client_metrics.go index 19dc7023e..97b83d004 100644 --- a/discovery/kubernetes/client_metrics.go +++ b/discovery/kubernetes/client_metrics.go @@ -163,6 +163,13 @@ var ( ) ) +// gaugeSetFunc is an adapter that allows the use of functions as gauge metric setters. +type gaugeSetFunc func(float64) + +func (s gaugeSetFunc) Set(value float64) { + s(value) +} + // Definition of dummy metric used as a placeholder if we don't want to observe some data. type noopMetric struct{} @@ -262,7 +269,11 @@ func (f *clientGoWorkqueueMetricsProvider) NewUnfinishedWorkSecondsMetric(name s return clientGoWorkqueueUnfinishedWorkSecondsMetricVec.WithLabelValues(name) } func (f *clientGoWorkqueueMetricsProvider) NewLongestRunningProcessorMicrosecondsMetric(name string) workqueue.SettableGaugeMetric { - return clientGoWorkqueueLongestRunningProcessorMetricVec.WithLabelValues(name) + metric := clientGoWorkqueueLongestRunningProcessorMetricVec.WithLabelValues(name) + return gaugeSetFunc(func(v float64) { + metric.Set(v / 1e6) + }) + } func (clientGoWorkqueueMetricsProvider) NewRetriesMetric(name string) workqueue.CounterMetric { // Retries are not used so the metric is omitted. diff --git a/go.mod b/go.mod index f8b26ac08..2d6160b23 100644 --- a/go.mod +++ b/go.mod @@ -40,6 +40,7 @@ require ( github.com/go-sql-driver/mysql v1.4.0 // indirect github.com/go-stack/stack v1.5.4 // indirect github.com/gogo/protobuf v0.0.0-20171123125729-971cbfd2e72b + github.com/golang/glog v0.0.0-20141105023935-44145f04b68c github.com/golang/groupcache v0.0.0-20180924190550-6f2cf27854a4 // indirect github.com/golang/protobuf v0.0.0-20180622174009-9eb2c01ac278 // indirect github.com/golang/snappy v0.0.0-20160529050041-d9eb7a3d35ec @@ -150,3 +151,5 @@ require ( launchpad.net/gocheck v0.0.0-20140225173054-000000000087 // indirect sigs.k8s.io/yaml v1.1.0 // indirect ) + +replace github.com/golang/glog => github.com/kubermatic/glog-gokit v0.0.0-20181129151237-8ab7e4c2d352 diff --git a/go.sum b/go.sum index e228153f9..a573c8361 100644 --- a/go.sum +++ b/go.sum @@ -151,6 +151,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kubermatic/glog-gokit v0.0.0-20181129151237-8ab7e4c2d352 h1:IwAUUBomA7q2TedTHQ3ebjwXVp8aHwi453m7AFn0vCk= +github.com/kubermatic/glog-gokit v0.0.0-20181129151237-8ab7e4c2d352/go.mod h1:WUD00rCUd6ntFOOuzJbT/MRrM+6X0Zufa6wWYBcf4zY= github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lightstep/lightstep-tracer-go v0.15.6 h1:D0GGa7afJ7GcQvu5as6ssLEEKYXvRgKI5d5cevtz8r4= diff --git a/vendor/github.com/golang/glog/LICENSE b/vendor/github.com/golang/glog/LICENSE new file mode 100644 index 000000000..b3dcbe455 --- /dev/null +++ b/vendor/github.com/golang/glog/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Kubermatic + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/golang/glog/README.md b/vendor/github.com/golang/glog/README.md new file mode 100644 index 000000000..e3c5d4311 --- /dev/null +++ b/vendor/github.com/golang/glog/README.md @@ -0,0 +1,65 @@ +# glog-gokit + +This packages is a replacement for [glog](github.com/golang/glog) +in projects that use the [go-kit logger](https://godoc.org/github.com/go-kit/kit/log). + +It is inspired by istio's glog package for zap: +https://github.com/istio/glog + +## Usage + +Override the official glog package with this one. +This simply replaces the code in `vendor/golang/glog` with the code of this package. + +In your `Gopkg.toml`: +```toml +[[override]] + name = "github.com/golang/glog" + source = "github.com/kubermatic/glog-gokit" +``` + +In your `main.go`: +```go +// Import the package like it is original glog +import "github.com/golang/glog" + + +// Create go-kit logger in your main.go +logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout)) +logger = log.With(logger, "ts", log.DefaultTimestampUTC) +logger = log.With(logger, "caller", log.DefaultCaller) +logger = level.NewFilter(logger, level.AllowAll()) + +// Overriding the default glog with our go-kit glog implementation. +// Thus we need to pass it our go-kit logger object. +glog.SetLogger(logger) +``` + +Setting the logger to the glog package **MUST** happen before using glog in any package. + +## Function Levels + +| glog | gokit | +| ------------ | ----- | +| Info | Debug | +| InfoDepth | Debug | +| Infof | Debug | +| Infoln | Debug | +| Warning | Warn | +| WarningDepth | Warn | +| Warningf | Warn | +| Warningln | Warn | +| Error | Error | +| ErrorDepth | Error | +| Errorf | Error | +| Errorln | Error | +| Exit | Error | +| ExitDepth | Error | +| Exitf | Error | +| Exitln | Error | +| Fatal | Error | +| FatalDepth | Error | +| Fatalf | Error | +| Fatalln | Error | + +This table is rather opinionated and build for use with the Kubernetes' [Go client](https://github.com/kubernetes/client-go). diff --git a/vendor/github.com/golang/glog/glog.go b/vendor/github.com/golang/glog/glog.go new file mode 100644 index 000000000..d4ad3c497 --- /dev/null +++ b/vendor/github.com/golang/glog/glog.go @@ -0,0 +1,143 @@ +package glog + +import ( + "fmt" + "math" + "os" + "sync" + + "github.com/go-kit/kit/log" + "github.com/go-kit/kit/log/level" +) + +var maxLevel Level = math.MaxInt32 +var logger = log.NewNopLogger() +var mu = sync.Mutex{} + +// SetLogger redirects glog logging to the given logger. +// It must be called prior any call to glog. +func SetLogger(l log.Logger) { + mu.Lock() + logger = l + mu.Unlock() +} + +// ClampLevel clamps the leveled logging at the specified value. +// It must be called prior any call to glog. +func ClampLevel(l Level) { + mu.Lock() + maxLevel = l + mu.Unlock() +} + +type Level int32 + +type Verbose bool + +func V(level Level) Verbose { return level <= maxLevel } + +func (v Verbose) Info(args ...interface{}) { + if v { + level.Debug(logger).Log("func", "Verbose.Info", "msg", fmt.Sprint(args...)) + } +} + +func (v Verbose) Infoln(args ...interface{}) { + if v { + level.Debug(logger).Log("func", "Verbose.Infoln", "msg", fmt.Sprint(args...)) + } +} + +func (v Verbose) Infof(format string, args ...interface{}) { + if v { + level.Debug(logger).Log("func", "Verbose.Infof", "msg", fmt.Sprintf(format, args...)) + } +} + +func Info(args ...interface{}) { + level.Debug(logger).Log("func", "Info", "msg", fmt.Sprint(args...)) +} + +func InfoDepth(depth int, args ...interface{}) { + level.Debug(logger).Log("func", "InfoDepth", "msg", fmt.Sprint(args...)) +} + +func Infoln(args ...interface{}) { + level.Debug(logger).Log("func", "Infoln", "msg", fmt.Sprint(args...)) +} + +func Infof(format string, args ...interface{}) { + level.Debug(logger).Log("func", "Infof", "msg", fmt.Sprintf(format, args...)) +} + +func Warning(args ...interface{}) { + level.Warn(logger).Log("func", "Warning", "msg", fmt.Sprint(args...)) +} + +func WarningDepth(depth int, args ...interface{}) { + level.Warn(logger).Log("func", "WarningDepth", "msg", fmt.Sprint(args...)) +} + +func Warningln(args ...interface{}) { + level.Warn(logger).Log("func", "Warningln", "msg", fmt.Sprint(args...)) +} + +func Warningf(format string, args ...interface{}) { + level.Warn(logger).Log("func", "Warningf", "msg", fmt.Sprintf(format, args...)) +} + +func Error(args ...interface{}) { + level.Error(logger).Log("func", "Error", "msg", fmt.Sprint(args...)) +} + +func ErrorDepth(depth int, args ...interface{}) { + level.Error(logger).Log("func", "ErrorDepth", "msg", fmt.Sprint(args...)) +} + +func Errorln(args ...interface{}) { + level.Error(logger).Log("func", "Errorln", "msg", fmt.Sprint(args...)) +} + +func Errorf(format string, args ...interface{}) { + level.Error(logger).Log("func", "Errorf", "msg", fmt.Sprintf(format, args...)) +} + +func Fatal(args ...interface{}) { + level.Error(logger).Log("func", "Fatal", "msg", fmt.Sprint(args...)) + os.Exit(255) +} + +func FatalDepth(depth int, args ...interface{}) { + level.Error(logger).Log("func", "FatalDepth", "msg", fmt.Sprint(args...)) + os.Exit(255) +} + +func Fatalln(args ...interface{}) { + level.Error(logger).Log("func", "Fatalln", "msg", fmt.Sprint(args...)) + os.Exit(255) +} + +func Fatalf(format string, args ...interface{}) { + level.Error(logger).Log("func", "Fatalf", "msg", fmt.Sprintf(format, args...)) + os.Exit(255) +} + +func Exit(args ...interface{}) { + level.Error(logger).Log("func", "Exit", "msg", fmt.Sprint(args...)) + os.Exit(1) +} + +func ExitDepth(depth int, args ...interface{}) { + level.Error(logger).Log("func", "ExitDepth", "msg", fmt.Sprint(args...)) + os.Exit(1) +} + +func Exitln(args ...interface{}) { + level.Error(logger).Log("func", "Exitln", "msg", fmt.Sprint(args...)) + os.Exit(1) +} + +func Exitf(format string, args ...interface{}) { + level.Error(logger).Log("func", "Exitf", "msg", fmt.Sprintf(format, args...)) + os.Exit(1) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index bbb4cb86b..98d29f51c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -71,6 +71,8 @@ github.com/gogo/protobuf/proto github.com/gogo/protobuf/types github.com/gogo/protobuf/sortkeys github.com/gogo/protobuf/jsonpb +# github.com/golang/glog v0.0.0-20141105023935-44145f04b68c => github.com/kubermatic/glog-gokit v0.0.0-20181129151237-8ab7e4c2d352 +github.com/golang/glog # github.com/golang/protobuf v0.0.0-20180622174009-9eb2c01ac278 github.com/golang/protobuf/proto github.com/golang/protobuf/jsonpb @@ -321,7 +323,6 @@ k8s.io/api/storage/v1 k8s.io/api/storage/v1alpha1 k8s.io/api/storage/v1beta1 # k8s.io/apimachinery v0.0.0-20181127025237-2b1284ed4c93 -k8s.io/apimachinery/pkg/util/runtime k8s.io/apimachinery/pkg/apis/meta/v1 k8s.io/apimachinery/pkg/runtime k8s.io/apimachinery/pkg/watch @@ -333,6 +334,7 @@ k8s.io/apimachinery/pkg/conversion k8s.io/apimachinery/pkg/fields k8s.io/apimachinery/pkg/labels k8s.io/apimachinery/pkg/selection +k8s.io/apimachinery/pkg/util/runtime k8s.io/apimachinery/pkg/conversion/queryparams k8s.io/apimachinery/pkg/util/errors k8s.io/apimachinery/pkg/util/json