Skip to content

Commit

Permalink
Apply the default numeric conversion on initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
hansmi committed Dec 10, 2024
1 parent 1ac44a2 commit c37044b
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions groupcollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@ import (
)

type groupField struct {
metricValue metricValueFunc
metricDesc *prometheus.Desc
convert metricValueFunc
metricDesc *prometheus.Desc
}

func (f *groupField) collect(ch chan<- prometheus.Metric, rawValue string, keyValues []string) error {
fn := f.metricValue

if fn == nil {
fn = fromNumeric
}

value, err := fn(rawValue)
value, err := f.convert(rawValue)
if err != nil {
return err
}
Expand Down Expand Up @@ -72,10 +66,14 @@ func newGroupCollector(g *group) *groupCollector {
c.infoDesc = prometheus.NewDesc(g.infoMetricName, "", infoLabelNames, nil)

for _, f := range g.numericFields {
c.numericFields[f.fieldName] = &groupField{
metricValue: f.metricValue,
metricDesc: prometheus.NewDesc(f.metricName, f.desc, keyLabelNames, nil),
info := &groupField{
convert: f.metricValue,
metricDesc: prometheus.NewDesc(f.metricName, f.desc, keyLabelNames, nil),
}
if info.convert == nil {
info.convert = fromNumeric
}
c.numericFields[f.fieldName] = info
c.knownFields[f.fieldName] = struct{}{}
}

Expand Down

0 comments on commit c37044b

Please sign in to comment.