Skip to content

Commit

Permalink
use prometheus/common package
Browse files Browse the repository at this point in the history
Signed-off-by: yeya24 <yb532204897@gmail.com>
  • Loading branch information
yeya24 committed Jan 5, 2021
1 parent e804ae9 commit 58c0014
Show file tree
Hide file tree
Showing 12 changed files with 3,024 additions and 105 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ TAG_PREFIX = v
VERSION = $(shell cat VERSION)
TAG ?= $(TAG_PREFIX)$(VERSION)
LATEST_RELEASE_BRANCH := release-$(shell grep -ohE "[0-9]+.[0-9]+" VERSION)
BRANCH = $(strip $(shell git rev-parse --abbrev-ref HEAD))
DOCKER_CLI ?= docker
PKGS = $(shell go list ./... | grep -v /vendor/ | grep -v /tests/e2e)
ARCH ?= $(shell go env GOARCH)
BUILD_DATE = $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
ALL_ARCH = amd64 arm arm64 ppc64le s390x
PKG = k8s.io/kube-state-metrics/v2/pkg
PKG = github.com/prometheus/common
GO_VERSION = 1.15.3
IMAGE = $(REGISTRY)/kube-state-metrics
MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)
USER ?= $(shell id -u -n)
HOST ?= $(shell hostname)

export DOCKER_CLI_EXPERIMENTAL=enabled

Expand Down Expand Up @@ -52,7 +55,7 @@ doccheck: generate
@echo OK

build-local:
GOOS=$(shell uname -s | tr A-Z a-z) GOARCH=$(ARCH) CGO_ENABLED=0 go build -ldflags "-s -w -X ${PKG}/version.Release=${TAG} -X ${PKG}/version.Commit=${GIT_COMMIT} -X ${PKG}/version.BuildDate=${BUILD_DATE}" -o kube-state-metrics
GOOS=$(shell uname -s | tr A-Z a-z) GOARCH=$(ARCH) CGO_ENABLED=0 go build -ldflags "-s -w -X ${PKG}/version.Version=${TAG} -X ${PKG}/version.Revision=${GIT_COMMIT} -X ${PKG}/version.Branch=${BRANCH} -X ${PKG}/version.BuildUser=${USER}@${HOST} -X ${PKG}/version.BuildDate=${BUILD_DATE}" -o kube-state-metrics

build: kube-state-metrics

Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module k8s.io/kube-state-metrics/v2

require (
github.com/Azure/go-autorest/autorest v0.10.0 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/brancz/gojsontoyaml v0.0.0-20190425155809-e8bd32d46b3d
github.com/campoy/embedmd v1.0.0
github.com/dgryski/go-jump v0.0.0-20170409065014-e1f439676b57
Expand All @@ -15,7 +14,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.7.1
github.com/prometheus/client_model v0.2.0
github.com/prometheus/common v0.10.0
github.com/prometheus/common v0.15.0
github.com/prometheus/prometheus v2.5.0+incompatible
github.com/robfig/cron/v3 v3.0.0
github.com/spf13/pflag v1.0.5
Expand Down
222 changes: 205 additions & 17 deletions go.sum

Large diffs are not rendered by default.

24 changes: 4 additions & 20 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"net/http"
"net/http/pprof"
"os"
"runtime"
"strconv"
"time"

Expand All @@ -32,6 +31,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/version"
vpaclientset "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/clientset/versioned"
clientset "k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth"
Expand All @@ -43,7 +43,6 @@ import (
"k8s.io/kube-state-metrics/v2/pkg/metricshandler"
"k8s.io/kube-state-metrics/v2/pkg/options"
"k8s.io/kube-state-metrics/v2/pkg/util/proc"
"k8s.io/kube-state-metrics/v2/pkg/version"
)

const (
Expand All @@ -70,7 +69,7 @@ func main() {
}

if opts.Version {
fmt.Printf("%#v\n", version.GetVersion())
fmt.Printf("%s\n", version.Print("kube-state-metrics"))
os.Exit(0)
}

Expand All @@ -81,7 +80,7 @@ func main() {
storeBuilder := store.NewBuilder()

ksmMetricsRegistry := prometheus.NewRegistry()
registerBuildInfo(ksmMetricsRegistry)
ksmMetricsRegistry.MustRegister(version.NewCollector("kube_state_metrics"))
durationVec := promauto.With(ksmMetricsRegistry).NewHistogramVec(
prometheus.HistogramOpts{
Name: "http_request_duration_seconds",
Expand Down Expand Up @@ -217,7 +216,7 @@ func createKubeClient(apiserver string, kubeconfig string) (clientset.Interface,
return nil, nil, err
}

config.UserAgent = version.GetVersion().String()
config.UserAgent = version.Version
config.AcceptContentTypes = "application/vnd.kubernetes.protobuf,application/json"
config.ContentType = "application/vnd.kubernetes.protobuf"

Expand Down Expand Up @@ -297,18 +296,3 @@ func buildMetricsServer(m *metricshandler.MetricsHandler, durationObserver prome
})
return mux
}

func registerBuildInfo(r prometheus.Registerer) {
v := version.GetVersion()
promauto.With(r).NewGaugeFunc(prometheus.GaugeOpts{
Name: "kube_state_metrics_build_info",
Help: "A metric with a constant '1' value labeled by version, revision, and " +
"goversion from which kube-state-metrics was built.",
ConstLabels: prometheus.Labels{
"version": v.Release,
"revision": v.GitCommit,
"goversion": runtime.Version(),
}},
func() float64 { return 1 },
)
}
64 changes: 0 additions & 64 deletions pkg/version/version.go

This file was deleted.

Loading

0 comments on commit 58c0014

Please sign in to comment.