Skip to content

Commit 464a83d

Browse files
committed
Yolo, add units.
Signed-off-by: bwplotka <[email protected]>
1 parent 242b076 commit 464a83d

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

prometheus/desc.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ type Desc struct {
4747
fqName string
4848
// help provides some helpful information about this metric.
4949
help string
50+
// unit is a OpenMetrics unit.
51+
unit string
5052
// constLabelPairs contains precalculated DTO label pairs based on
5153
// the constant labels.
5254
constLabelPairs []*dto.LabelPair
@@ -76,7 +78,7 @@ type Desc struct {
7678
// For constLabels, the label values are constant. Therefore, they are fully
7779
// specified in the Desc. See the Collector example for a usage pattern.
7880
func NewDesc(fqName, help string, variableLabels []string, constLabels Labels) *Desc {
79-
return V2.NewDesc(fqName, help, UnconstrainedLabels(variableLabels), constLabels)
81+
return V2.NewDesc(fqName, help, "", UnconstrainedLabels(variableLabels), constLabels)
8082
}
8183

8284
// NewDesc allocates and initializes a new Desc. Errors are recorded in the Desc
@@ -89,10 +91,11 @@ func NewDesc(fqName, help string, variableLabels []string, constLabels Labels) *
8991
//
9092
// For constLabels, the label values are constant. Therefore, they are fully
9193
// specified in the Desc. See the Collector example for a usage pattern.
92-
func (v2) NewDesc(fqName, help string, variableLabels ConstrainableLabels, constLabels Labels) *Desc {
94+
func (v2) NewDesc(fqName, help, unit string, variableLabels ConstrainableLabels, constLabels Labels) *Desc {
9395
d := &Desc{
9496
fqName: fqName,
9597
help: help,
98+
unit: unit,
9699
variableLabels: variableLabels.compile(),
97100
}
98101
if !model.IsValidMetricName(model.LabelValue(fqName)) {

prometheus/histogram.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ type HistogramOpts struct {
371371
Namespace string
372372
Subsystem string
373373
Name string
374+
Unit string
374375

375376
// Help provides information about this Histogram.
376377
//
@@ -522,9 +523,10 @@ type HistogramVecOpts struct {
522523
// for each bucket.
523524
func NewHistogram(opts HistogramOpts) Histogram {
524525
return newHistogram(
525-
NewDesc(
526+
V2.NewDesc(
526527
BuildFQName(opts.Namespace, opts.Subsystem, opts.Name),
527528
opts.Help,
529+
opts.Unit,
528530
nil,
529531
opts.ConstLabels,
530532
),

prometheus/registry.go

+4
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,10 @@ func processMetric(
685685
metricFamily = &dto.MetricFamily{}
686686
metricFamily.Name = proto.String(desc.fqName)
687687
metricFamily.Help = proto.String(desc.help)
688+
if desc.unit != "" {
689+
metricFamily.Unit = proto.String(desc.unit)
690+
}
691+
688692
// TODO(beorn7): Simplify switch once Desc has type.
689693
switch {
690694
case dtoMetric.Gauge != nil:

0 commit comments

Comments
 (0)