Currently, metrics are stored as Metric[Metric] inside a Registry. I think that it would be better to store them as Metric[Metric.Id] instead, where Metric.Id is a struct containing the Metric's name and labels (other properties could also be contained, the idea is taken from Micrometer where type, description and baseUnit are also part of the Id, but they are not relevant for hashing). Metric.Id added as a new property id to all metrics. We can then register metrics like this:
void register(Metric m)
{
synchronized(this)
{
this._metrics[m.id] = m;
}
}
There are several reasons for this:
- It makes sure we cannot register different
Metrics with the same name / labels, which currently is possible but makes no sense
- It allows to build convenience functions into the registry / metrics to get or register metrics by name and tags
Currently, metrics are stored as
Metric[Metric]inside aRegistry. I think that it would be better to store them asMetric[Metric.Id]instead, whereMetric.Idis astructcontaining theMetric'snameandlabels(other properties could also be contained, the idea is taken from Micrometer wheretype,descriptionandbaseUnitare also part of theId, but they are not relevant for hashing).Metric.Idadded as a new propertyidto all metrics. We can then register metrics like this:There are several reasons for this:
Metrics with the same name / labels, which currently is possible but makes no sense