From 03e373bae2555438d0927f882ee63f353eb6bea0 Mon Sep 17 00:00:00 2001 From: Walter Fender Date: Tue, 4 Dec 2018 18:20:11 -0800 Subject: [PATCH] Add gauge metric for master of leader election. Fixes #71730 0 indicates standby, 1 indicates master, label indicates which lease. Tweaked name and documentation Factored in Mike Danese feedback. Removed dependency on prometheus from client-go using adapter. Centralized adapter import. Fixed godeps Fixed boilerplate. Put in fixes for caesarxuchao Kubernetes-commit: f1926573804ed2c172c91d1022203d0699210138 --- Godeps/Godeps.json | 626 ------------------------- Godeps/OWNERS | 2 - Godeps/Readme | 5 - tools/leaderelection/leaderelection.go | 15 +- tools/leaderelection/metrics.go | 109 +++++ 5 files changed, 120 insertions(+), 637 deletions(-) delete mode 100644 Godeps/Godeps.json delete mode 100644 Godeps/OWNERS delete mode 100644 Godeps/Readme create mode 100644 tools/leaderelection/metrics.go diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json deleted file mode 100644 index b21ef8e6..00000000 --- a/Godeps/Godeps.json +++ /dev/null @@ -1,626 +0,0 @@ -{ - "ImportPath": "k8s.io/client-go", - "GoVersion": "go1.11", - "GodepVersion": "v80", - "Packages": [ - "./..." - ], - "Deps": [ - { - "ImportPath": "cloud.google.com/go/compute/metadata", - "Rev": "3b1ae45394a234c385be014e9a488f2bb6eef821" - }, - { - "ImportPath": "cloud.google.com/go/internal", - "Rev": "3b1ae45394a234c385be014e9a488f2bb6eef821" - }, - { - "ImportPath": "github.com/Azure/go-autorest/autorest", - "Rev": "ea233b6412b0421a65dc6160e16c893364664a95" - }, - { - "ImportPath": "github.com/Azure/go-autorest/autorest/adal", - "Rev": "ea233b6412b0421a65dc6160e16c893364664a95" - }, - { - "ImportPath": "github.com/Azure/go-autorest/autorest/azure", - "Rev": "ea233b6412b0421a65dc6160e16c893364664a95" - }, - { - "ImportPath": "github.com/Azure/go-autorest/autorest/date", - "Rev": "ea233b6412b0421a65dc6160e16c893364664a95" - }, - { - "ImportPath": "github.com/Azure/go-autorest/logger", - "Rev": "ea233b6412b0421a65dc6160e16c893364664a95" - }, - { - "ImportPath": "github.com/Azure/go-autorest/version", - "Rev": "ea233b6412b0421a65dc6160e16c893364664a95" - }, - { - "ImportPath": "github.com/davecgh/go-spew/spew", - "Rev": "782f4967f2dc4564575ca782fe2d04090b5faca8" - }, - { - "ImportPath": "github.com/dgrijalva/jwt-go", - "Rev": "01aeca54ebda6e0fbfafd0a524d234159c05ec20" - }, - { - "ImportPath": "github.com/docker/spdystream", - "Rev": "449fdfce4d962303d702fec724ef0ad181c92528" - }, - { - "ImportPath": "github.com/docker/spdystream/spdy", - "Rev": "449fdfce4d962303d702fec724ef0ad181c92528" - }, - { - "ImportPath": "github.com/evanphx/json-patch", - "Rev": "36442dbdb585210f8d5a1b45e67aa323c197d5c4" - }, - { - "ImportPath": "github.com/gogo/protobuf/proto", - "Rev": "342cbe0a04158f6dcb03ca0079991a51a4248c02" - }, - { - "ImportPath": "github.com/gogo/protobuf/sortkeys", - "Rev": "342cbe0a04158f6dcb03ca0079991a51a4248c02" - }, - { - "ImportPath": "github.com/golang/groupcache/lru", - "Rev": "02826c3e79038b59d737d3b1c0a1d937f71a4433" - }, - { - "ImportPath": "github.com/golang/protobuf/proto", - "Rev": "b4deda0973fb4c70b50d226b1af49f3da59f5265" - }, - { - "ImportPath": "github.com/golang/protobuf/ptypes", - "Rev": "b4deda0973fb4c70b50d226b1af49f3da59f5265" - }, - { - "ImportPath": "github.com/golang/protobuf/ptypes/any", - "Rev": "b4deda0973fb4c70b50d226b1af49f3da59f5265" - }, - { - "ImportPath": "github.com/golang/protobuf/ptypes/duration", - "Rev": "b4deda0973fb4c70b50d226b1af49f3da59f5265" - }, - { - "ImportPath": "github.com/golang/protobuf/ptypes/timestamp", - "Rev": "b4deda0973fb4c70b50d226b1af49f3da59f5265" - }, - { - "ImportPath": "github.com/google/btree", - "Rev": "7d79101e329e5a3adf994758c578dab82b90c017" - }, - { - "ImportPath": "github.com/google/gofuzz", - "Rev": "44d81051d367757e1c7c6a5a86423ece9afcf63c" - }, - { - "ImportPath": "github.com/googleapis/gnostic/OpenAPIv2", - "Rev": "0c5108395e2debce0d731cf0287ddf7242066aba" - }, - { - "ImportPath": "github.com/googleapis/gnostic/compiler", - "Rev": "0c5108395e2debce0d731cf0287ddf7242066aba" - }, - { - "ImportPath": "github.com/googleapis/gnostic/extensions", - "Rev": "0c5108395e2debce0d731cf0287ddf7242066aba" - }, - { - "ImportPath": "github.com/gophercloud/gophercloud", - "Rev": "781450b3c4fcb4f5182bcc5133adb4b2e4a09d1d" - }, - { - "ImportPath": "github.com/gophercloud/gophercloud/openstack", - "Rev": "781450b3c4fcb4f5182bcc5133adb4b2e4a09d1d" - }, - { - "ImportPath": "github.com/gophercloud/gophercloud/openstack/identity/v2/tenants", - "Rev": "781450b3c4fcb4f5182bcc5133adb4b2e4a09d1d" - }, - { - "ImportPath": "github.com/gophercloud/gophercloud/openstack/identity/v2/tokens", - "Rev": "781450b3c4fcb4f5182bcc5133adb4b2e4a09d1d" - }, - { - "ImportPath": "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens", - "Rev": "781450b3c4fcb4f5182bcc5133adb4b2e4a09d1d" - }, - { - "ImportPath": "github.com/gophercloud/gophercloud/openstack/utils", - "Rev": "781450b3c4fcb4f5182bcc5133adb4b2e4a09d1d" - }, - { - "ImportPath": "github.com/gophercloud/gophercloud/pagination", - "Rev": "781450b3c4fcb4f5182bcc5133adb4b2e4a09d1d" - }, - { - "ImportPath": "github.com/gregjones/httpcache", - "Rev": "787624de3eb7bd915c329cba748687a3b22666a6" - }, - { - "ImportPath": "github.com/gregjones/httpcache/diskcache", - "Rev": "787624de3eb7bd915c329cba748687a3b22666a6" - }, - { - "ImportPath": "github.com/hashicorp/golang-lru", - "Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4" - }, - { - "ImportPath": "github.com/hashicorp/golang-lru/simplelru", - "Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4" - }, - { - "ImportPath": "github.com/imdario/mergo", - "Rev": "9316a62528ac99aaecb4e47eadd6dc8aa6533d58" - }, - { - "ImportPath": "github.com/json-iterator/go", - "Rev": "ab8a2e0c74be9d3be70b3184d9acc634935ded82" - }, - { - "ImportPath": "github.com/modern-go/concurrent", - "Rev": "bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94" - }, - { - "ImportPath": "github.com/modern-go/reflect2", - "Rev": "94122c33edd36123c84d5368cfb2b69df93a0ec8" - }, - { - "ImportPath": "github.com/peterbourgon/diskv", - "Rev": "5f041e8faa004a95c88a202771f4cc3e991971e6" - }, - { - "ImportPath": "github.com/pmezard/go-difflib/difflib", - "Rev": "d8ed2627bdf02c080bf22230dbb337003b7aba2d" - }, - { - "ImportPath": "github.com/spf13/pflag", - "Rev": "583c0c0531f06d5278b7d917446061adc344b5cd" - }, - { - "ImportPath": "github.com/stretchr/testify/assert", - "Rev": "c679ae2cc0cb27ec3293fea7e254e47386f05d69" - }, - { - "ImportPath": "golang.org/x/crypto/ssh/terminal", - "Rev": "de0752318171da717af4ce24d0a2e8626afaeb11" - }, - { - "ImportPath": "golang.org/x/net/context", - "Rev": "0ed95abb35c445290478a5348a7b38bb154135fd" - }, - { - "ImportPath": "golang.org/x/net/context/ctxhttp", - "Rev": "0ed95abb35c445290478a5348a7b38bb154135fd" - }, - { - "ImportPath": "golang.org/x/net/http2", - "Rev": "0ed95abb35c445290478a5348a7b38bb154135fd" - }, - { - "ImportPath": "golang.org/x/net/http2/hpack", - "Rev": "0ed95abb35c445290478a5348a7b38bb154135fd" - }, - { - "ImportPath": "golang.org/x/net/idna", - "Rev": "0ed95abb35c445290478a5348a7b38bb154135fd" - }, - { - "ImportPath": "golang.org/x/net/lex/httplex", - "Rev": "0ed95abb35c445290478a5348a7b38bb154135fd" - }, - { - "ImportPath": "golang.org/x/oauth2", - "Rev": "a6bd8cefa1811bd24b86f8902872e4e8225f74c4" - }, - { - "ImportPath": "golang.org/x/oauth2/google", - "Rev": "a6bd8cefa1811bd24b86f8902872e4e8225f74c4" - }, - { - "ImportPath": "golang.org/x/oauth2/internal", - "Rev": "a6bd8cefa1811bd24b86f8902872e4e8225f74c4" - }, - { - "ImportPath": "golang.org/x/oauth2/jws", - "Rev": "a6bd8cefa1811bd24b86f8902872e4e8225f74c4" - }, - { - "ImportPath": "golang.org/x/oauth2/jwt", - "Rev": "a6bd8cefa1811bd24b86f8902872e4e8225f74c4" - }, - { - "ImportPath": "golang.org/x/sys/unix", - "Rev": "95c6576299259db960f6c5b9b69ea52422860fce" - }, - { - "ImportPath": "golang.org/x/sys/windows", - "Rev": "95c6576299259db960f6c5b9b69ea52422860fce" - }, - { - "ImportPath": "golang.org/x/text/secure/bidirule", - "Rev": "b19bf474d317b857955b12035d2c5acb57ce8b01" - }, - { - "ImportPath": "golang.org/x/text/transform", - "Rev": "b19bf474d317b857955b12035d2c5acb57ce8b01" - }, - { - "ImportPath": "golang.org/x/text/unicode/bidi", - "Rev": "b19bf474d317b857955b12035d2c5acb57ce8b01" - }, - { - "ImportPath": "golang.org/x/text/unicode/norm", - "Rev": "b19bf474d317b857955b12035d2c5acb57ce8b01" - }, - { - "ImportPath": "golang.org/x/time/rate", - "Rev": "f51c12702a4d776e4c1fa9b0fabab841babae631" - }, - { - "ImportPath": "gopkg.in/inf.v0", - "Rev": "3887ee99ecf07df5b447e9b00d9c0b2adaa9f3e4" - }, - { - "ImportPath": "gopkg.in/yaml.v2", - "Rev": "5420a8b6744d3b0345ab293f6fcba19c978f1183" - }, - { - "ImportPath": "k8s.io/api/admissionregistration/v1alpha1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/admissionregistration/v1beta1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/apps/v1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/apps/v1beta1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/apps/v1beta2", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/auditregistration/v1alpha1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/authentication/v1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/authentication/v1beta1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/authorization/v1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/authorization/v1beta1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/autoscaling/v1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/autoscaling/v2beta1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/autoscaling/v2beta2", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/batch/v1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/batch/v1beta1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/batch/v2alpha1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/certificates/v1beta1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/coordination/v1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/coordination/v1beta1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/core/v1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/events/v1beta1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/extensions/v1beta1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/imagepolicy/v1alpha1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/networking/v1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/policy/v1beta1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/rbac/v1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/rbac/v1alpha1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/rbac/v1beta1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/scheduling/v1alpha1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/scheduling/v1beta1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/settings/v1alpha1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/storage/v1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/storage/v1alpha1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/api/storage/v1beta1", - "Rev": "173ce66c1e39d1d0f56e0b3347ff2988068aecd0" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/api/apitesting", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/api/apitesting/fuzzer", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/api/apitesting/roundtrip", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/api/equality", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/api/errors", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/api/meta", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/api/resource", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/fuzzer", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/internalversion", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1beta1", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/conversion", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/conversion/queryparams", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/fields", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/labels", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/runtime", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/runtime/schema", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/json", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/protobuf", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/recognizer", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/streaming", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/versioning", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/selection", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/types", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/util/cache", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/util/clock", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/util/diff", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/util/errors", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/util/framer", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/util/httpstream", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/util/httpstream/spdy", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/util/intstr", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/util/json", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/util/mergepatch", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/util/naming", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/util/net", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/util/remotecommand", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/util/runtime", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/util/sets", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/util/strategicpatch", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/util/validation", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/util/validation/field", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/util/wait", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/util/yaml", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/version", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/pkg/watch", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/third_party/forked/golang/json", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/third_party/forked/golang/netutil", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/apimachinery/third_party/forked/golang/reflect", - "Rev": "e086bfc51e5473a823963a7dd224934d6f3767e7" - }, - { - "ImportPath": "k8s.io/klog", - "Rev": "8139d8cb77af419532b33dfa7dd09fbc5f1d344f" - }, - { - "ImportPath": "k8s.io/kube-openapi/pkg/util/proto", - "Rev": "c59034cc13d587f5ef4e85ca0ade0c1866ae8e1d" - }, - { - "ImportPath": "sigs.k8s.io/yaml", - "Rev": "fd68e9863619f6ec2fdd8625fe1f02e7c877e480" - } - ] -} diff --git a/Godeps/OWNERS b/Godeps/OWNERS deleted file mode 100644 index 3d49f306..00000000 --- a/Godeps/OWNERS +++ /dev/null @@ -1,2 +0,0 @@ -approvers: -- dep-approvers diff --git a/Godeps/Readme b/Godeps/Readme deleted file mode 100644 index 4cdaa53d..00000000 --- a/Godeps/Readme +++ /dev/null @@ -1,5 +0,0 @@ -This directory tree is generated automatically by godep. - -Please do not edit. - -See https://github.com/tools/godep for more information. diff --git a/tools/leaderelection/leaderelection.go b/tools/leaderelection/leaderelection.go index 2096a599..19c57f31 100644 --- a/tools/leaderelection/leaderelection.go +++ b/tools/leaderelection/leaderelection.go @@ -89,10 +89,13 @@ func NewLeaderElector(lec LeaderElectionConfig) (*LeaderElector, error) { if lec.Lock == nil { return nil, fmt.Errorf("Lock must not be nil.") } - return &LeaderElector{ - config: lec, - clock: clock.RealClock{}, - }, nil + le := LeaderElector{ + config: lec, + clock: clock.RealClock{}, + metrics: globalMetricsFactory.newLeaderMetrics(), + } + le.metrics.leaderOff(le.config.Name) + return &le, nil } type LeaderElectionConfig struct { @@ -152,6 +155,8 @@ type LeaderElector struct { // clock is wrapper around time to allow for less flaky testing clock clock.Clock + metrics leaderMetricsAdapter + // name is the name of the resource lock for debugging name string } @@ -211,6 +216,7 @@ func (le *LeaderElector) acquire(ctx context.Context) bool { return } le.config.Lock.RecordEvent("became leader") + le.metrics.leaderOn(le.config.Name) klog.Infof("successfully acquired lease %v", desc) cancel() }, le.config.RetryPeriod, JitterFactor, true, ctx.Done()) @@ -246,6 +252,7 @@ func (le *LeaderElector) renew(ctx context.Context) { return } le.config.Lock.RecordEvent("stopped leading") + le.metrics.leaderOff(le.config.Name) klog.Infof("failed to renew lease %v: %v", desc, err) cancel() }, le.config.RetryPeriod, ctx.Done()) diff --git a/tools/leaderelection/metrics.go b/tools/leaderelection/metrics.go new file mode 100644 index 00000000..65917bf8 --- /dev/null +++ b/tools/leaderelection/metrics.go @@ -0,0 +1,109 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package leaderelection + +import ( + "sync" +) + +// This file provides abstractions for setting the provider (e.g., prometheus) +// of metrics. + +type leaderMetricsAdapter interface { + leaderOn(name string) + leaderOff(name string) +} + +// GaugeMetric represents a single numerical value that can arbitrarily go up +// and down. +type SwitchMetric interface { + On(name string) + Off(name string) +} + +type noopMetric struct{} + +func (noopMetric) On(name string) {} +func (noopMetric) Off(name string) {} + +// defaultLeaderMetrics expects the caller to lock before setting any metrics. +type defaultLeaderMetrics struct { + // leader's value indicates if the current process is the owner of name lease + leader SwitchMetric +} + +func (m *defaultLeaderMetrics) leaderOn(name string) { + if m == nil { + return + } + m.leader.On(name) +} + +func (m *defaultLeaderMetrics) leaderOff(name string) { + if m == nil { + return + } + m.leader.Off(name) +} + +type noMetrics struct{} + +func (noMetrics) leaderOn(name string) {} +func (noMetrics) leaderOff(name string) {} + +// MetricsProvider generates various metrics used by the leader election. +type MetricsProvider interface { + NewLeaderMetric() SwitchMetric +} + +type noopMetricsProvider struct{} + +func (_ noopMetricsProvider) NewLeaderMetric() SwitchMetric { + return noopMetric{} +} + +var globalMetricsFactory = leaderMetricsFactory{ + metricsProvider: noopMetricsProvider{}, +} + +type leaderMetricsFactory struct { + metricsProvider MetricsProvider + + onlyOnce sync.Once +} + +func (f *leaderMetricsFactory) setProvider(mp MetricsProvider) { + f.onlyOnce.Do(func() { + f.metricsProvider = mp + }) +} + +func (f *leaderMetricsFactory) newLeaderMetrics() leaderMetricsAdapter { + mp := f.metricsProvider + if mp == (noopMetricsProvider{}) { + return noMetrics{} + } + return &defaultLeaderMetrics{ + leader: mp.NewLeaderMetric(), + } +} + +// SetProvider sets the metrics provider for all subsequently created work +// queues. Only the first call has an effect. +func SetProvider(metricsProvider MetricsProvider) { + globalMetricsFactory.setProvider(metricsProvider) +}