From 59de361f61e91fc98fa414de5ccc5ad98390b53c Mon Sep 17 00:00:00 2001 From: Gilles Miraillet Date: Thu, 20 Jun 2024 14:28:32 +0200 Subject: [PATCH] use github.com/prometheus/client_golang/prometheus/collectors/version/version.NewCollector which replaces github.com/prometheus/common/version.NewCollector --- main.go | 3 +- .../prometheus/collectors/version/version.go | 47 +++++++++++++++++++ vendor/modules.txt | 1 + 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 vendor/github.com/prometheus/client_golang/prometheus/collectors/version/version.go diff --git a/main.go b/main.go index ee9ca358..4a77ecdb 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "github.com/cloudfoundry/cf_exporter/fetcher" "github.com/cloudfoundry/cf_exporter/filters" "github.com/prometheus/client_golang/prometheus" + versionCollector "github.com/prometheus/client_golang/prometheus/collectors/version" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/common/version" log "github.com/sirupsen/logrus" @@ -99,7 +100,7 @@ var ( ) func init() { - prometheus.MustRegister(version.NewCollector(*metricsNamespace)) + prometheus.MustRegister(versionCollector.NewCollector(*metricsNamespace)) } type basicAuthHandler struct { diff --git a/vendor/github.com/prometheus/client_golang/prometheus/collectors/version/version.go b/vendor/github.com/prometheus/client_golang/prometheus/collectors/version/version.go new file mode 100644 index 00000000..c96e1871 --- /dev/null +++ b/vendor/github.com/prometheus/client_golang/prometheus/collectors/version/version.go @@ -0,0 +1,47 @@ +// Copyright 2016 The Prometheus 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 version + +import ( + "fmt" + + "github.com/prometheus/common/version" + + "github.com/prometheus/client_golang/prometheus" +) + +// NewCollector returns a collector that exports metrics about current version +// information. +func NewCollector(program string) prometheus.Collector { + return prometheus.NewGaugeFunc( + prometheus.GaugeOpts{ + Namespace: program, + Name: "build_info", + Help: fmt.Sprintf( + "A metric with a constant '1' value labeled by version, revision, branch, goversion from which %s was built, and the goos and goarch for the build.", + program, + ), + ConstLabels: prometheus.Labels{ + "version": version.Version, + "revision": version.GetRevision(), + "branch": version.Branch, + "goversion": version.GoVersion, + "goos": version.GoOS, + "goarch": version.GoArch, + "tags": version.GetTags(), + }, + }, + func() float64 { return 1 }, + ) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 4f10e2da..67bc997a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -247,6 +247,7 @@ github.com/onsi/gomega/types # github.com/prometheus/client_golang v1.19.1 ## explicit; go 1.20 github.com/prometheus/client_golang/prometheus +github.com/prometheus/client_golang/prometheus/collectors/version github.com/prometheus/client_golang/prometheus/internal github.com/prometheus/client_golang/prometheus/promhttp # github.com/prometheus/client_model v0.6.1