Add internal ID to metric

This commit is contained in:
Daniel 2023-09-05 12:48:55 +02:00
parent 8d792bdacc
commit a34de1ce8e
2 changed files with 8 additions and 0 deletions

View file

@ -43,6 +43,10 @@ type Options struct {
// Name defines an optional human readable name for the metric.
Name string
// InternalID specifies an alternative internal ID that will be used when
// exposing the metric via the API in a structured format.
InternalID string
// AlertLimit defines an upper limit that triggers an alert.
AlertLimit float64

View file

@ -92,6 +92,10 @@ func register(m Metric) error {
if m.LabeledID() == registeredMetric.LabeledID() {
return ErrAlreadyRegistered
}
if m.Opts().InternalID != "" &&
m.Opts().InternalID == registeredMetric.Opts().InternalID {
return fmt.Errorf("%w with this internal ID", ErrAlreadyRegistered)
}
}
// Add new metric to registry and sort it.