fixup uniq labels
Some checks failed
build / test (push) Has been cancelled
build / lint (push) Has been cancelled
codeql / analyze (go) (push) Has been cancelled

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2024-03-27 11:49:31 +03:00
parent 4e64f3f994
commit e02f291db2
3 changed files with 884 additions and 6 deletions

View File

@@ -293,7 +293,7 @@ func (m *prometheusMeter) Write(w io.Writer, opts ...meter.Option) error {
return err
}
enc := expfmt.NewEncoder(w, expfmt.FmtText)
enc := expfmt.NewEncoder(w, expfmt.NewFormat(expfmt.TypeTextPlain))
for name, metrics := range m.counter {
mf := &dto.MetricFamily{
@@ -521,12 +521,18 @@ func newHash(labels []string) uint64 {
}
func fillMetric(m *dto.Metric, labels []string) *dto.Metric {
var ok bool
seen := make(map[string]bool, len(labels)/2)
m.Label = make([]*dto.LabelPair, 0, len(labels)/2)
for idx := 0; idx < len(labels); idx += 2 {
if _, ok = seen[labels[idx]]; ok {
continue
}
m.Label = append(m.Label, &dto.LabelPair{
Name: newString(labels[idx]),
Value: newString(labels[idx+1]),
})
seen[labels[idx]] = true
}
return m
}