-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added show-provider-address-in-metrics flag for provider metrics
- Loading branch information
Showing
5 changed files
with
86 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package metrics | ||
|
||
import "github.com/prometheus/client_golang/prometheus" | ||
|
||
// MappedLabelsCounterVec is a wrapper around prometheus.CounterVec that allows for setting labels dynamically. | ||
// We use if for the metrics that have a dynamic number of labels, based on flags given upon startup. | ||
type MappedLabelsCounterVec struct { | ||
*prometheus.CounterVec | ||
labels []string | ||
} | ||
|
||
type MappedLabelsCounterVecOpts struct { | ||
Name string | ||
Help string | ||
Labels []string | ||
} | ||
|
||
func NewMappedLabelsCounterVec(opts MappedLabelsCounterVecOpts) *MappedLabelsCounterVec { | ||
metric := &MappedLabelsCounterVec{ | ||
labels: opts.Labels, | ||
CounterVec: prometheus.NewCounterVec(prometheus.CounterOpts{ | ||
Name: opts.Name, | ||
Help: opts.Help, | ||
}, opts.Labels), | ||
} | ||
|
||
prometheus.MustRegister(metric.CounterVec) | ||
|
||
return metric | ||
} | ||
|
||
func (mlgv *MappedLabelsCounterVec) getLabelValues(labelsWithValues map[string]string) []string { | ||
labelValues := make([]string, len(mlgv.labels)) | ||
for i, label := range mlgv.labels { | ||
labelValues[i] = labelsWithValues[label] | ||
} | ||
return labelValues | ||
} | ||
|
||
func (mlgv *MappedLabelsCounterVec) WithLabelValues(labelsWithValues map[string]string) prometheus.Counter { | ||
return mlgv.CounterVec.WithLabelValues(mlgv.getLabelValues(labelsWithValues)...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters