@@ -19,11 +19,30 @@ import (
19
19
"github.com/prometheus/common/version"
20
20
21
21
"github.com/prometheus/client_golang/prometheus"
22
+ "maps"
22
23
)
23
24
24
25
// NewCollector returns a collector that exports metrics about current version
25
26
// information.
26
27
func 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
+
27
46
return prometheus .NewGaugeFunc (
28
47
prometheus.GaugeOpts {
29
48
Namespace : program ,
@@ -32,16 +51,9 @@ func NewCollector(program string) prometheus.Collector {
32
51
"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." ,
33
52
program ,
34
53
),
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 ,
44
55
},
45
56
func () float64 { return 1 },
46
57
)
58
+
47
59
}
0 commit comments