@@ -19,11 +19,30 @@ import (
1919 "github.com/prometheus/common/version"
2020
2121 "github.com/prometheus/client_golang/prometheus"
22+ "golang.org/x/exp/maps"
2223)
2324
2425// NewCollector returns a collector that exports metrics about current version
2526// information.
2627func NewCollector (program string ) prometheus.Collector {
28+ return NewCollectorWithLabels (program , nil )
29+ }
30+
31+ // NewCollectorWithLabels returns a collector that exports metrics about current
32+ // version information and allows to set additional custom labels.
33+ func NewCollectorWithLabels (program string , labels prometheus.Labels ) prometheus.Collector {
34+
35+ constLabels := prometheus.Labels {
36+ "version" : version .Version ,
37+ "revision" : version .GetRevision (),
38+ "branch" : version .Branch ,
39+ "goversion" : version .GoVersion ,
40+ "goos" : version .GoOS ,
41+ "goarch" : version .GoArch ,
42+ "tags" : version .GetTags (),
43+ }
44+ maps .Copy (constLabels , labels )
45+
2746 return prometheus .NewGaugeFunc (
2847 prometheus.GaugeOpts {
2948 Namespace : program ,
@@ -32,16 +51,9 @@ func NewCollector(program string) prometheus.Collector {
3251 "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." ,
3352 program ,
3453 ),
35- ConstLabels : prometheus.Labels {
36- "version" : version .Version ,
37- "revision" : version .GetRevision (),
38- "branch" : version .Branch ,
39- "goversion" : version .GoVersion ,
40- "goos" : version .GoOS ,
41- "goarch" : version .GoArch ,
42- "tags" : version .GetTags (),
43- },
54+ ConstLabels : constLabels ,
4455 },
4556 func () float64 { return 1 },
4657 )
58+
4759}
0 commit comments