sigs.k8s.io/prow@v0.0.0-20240503223140-c5e374dc7eb1/pkg/version/metrics.go (about) 1 /* 2 Copyright 2020 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package version 18 19 import ( 20 "github.com/prometheus/client_golang/prometheus" 21 "github.com/sirupsen/logrus" 22 ) 23 24 var ( 25 prowVersion = prometheus.NewGauge(prometheus.GaugeOpts{ 26 Name: "prow_version", 27 Help: "Prow version.", 28 }) 29 ) 30 31 func init() { 32 prometheus.MustRegister(prowVersion) 33 // For components that import current package, if `gatherProwVersion` if not 34 // explicitly called, there will be no metrics for `prow_version`, and when 35 // querying prometheus for `prow_version` the value will be zero, which 36 // is inaccurate. Since the version would not change for the running binary, 37 // doing this once when binary starts should be fine. 38 gatherProwVersion() 39 } 40 41 // gatherProwVersion reports prow version 42 func gatherProwVersion() { 43 // record prow version 44 version, err := VersionTimestamp() 45 if err != nil { 46 // Not worth panicking 47 logrus.WithError(err).Debug("Failed to get version timestamp") 48 prowVersion.Set(-1) 49 } else { 50 prowVersion.Set(float64(version)) 51 } 52 }