Skip to content

Commit

Permalink
gocollector: Attach original runtime/metrics metric name to help. (#1578
Browse files Browse the repository at this point in the history
)

This helps in filtering capabilities and generally in discovery/knowledge sharing.

Signed-off-by: bwplotka <[email protected]>
  • Loading branch information
bwplotka authored Aug 14, 2024
1 parent 062300e commit 7ce5089
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions prometheus/go_collector_latest.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector {
// to fail here. This condition is tested in TestExpectedRuntimeMetrics.
continue
}
help := attachOriginalName(d.Description.Description, d.Name)

sampleBuf = append(sampleBuf, metrics.Sample{Name: d.Name})
sampleMap[d.Name] = &sampleBuf[len(sampleBuf)-1]
Expand All @@ -216,7 +217,7 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector {
m = newBatchHistogram(
NewDesc(
BuildFQName(namespace, subsystem, name),
d.Description.Description,
help,
nil,
nil,
),
Expand All @@ -228,15 +229,15 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector {
Namespace: namespace,
Subsystem: subsystem,
Name: name,
Help: d.Description.Description,
Help: help,
},
)
} else {
m = NewGauge(GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: name,
Help: d.Description.Description,
Help: help,
})
}
metricSet = append(metricSet, m)
Expand Down Expand Up @@ -286,6 +287,10 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector {
}
}

func attachOriginalName(desc, origName string) string {
return fmt.Sprintf("%s Sourced from %s", desc, origName)
}

// Describe returns all descriptions of the collector.
func (c *goCollector) Describe(ch chan<- *Desc) {
c.base.Describe(ch)
Expand Down

0 comments on commit 7ce5089

Please sign in to comment.