Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion model/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ func EscapeMetricFamily(v *dto.MetricFamily, scheme EscapingScheme) *dto.MetricF
} else {
out.Name = proto.String(EscapeName(v.GetName(), scheme))
}
if v.Metric != nil {
out.Metric = make([]*dto.Metric, 0, len(v.Metric))
}
for _, m := range v.Metric {
if !metricNeedsEscaping(m) {
out.Metric = append(out.Metric, m)
Expand All @@ -369,7 +372,9 @@ func EscapeMetricFamily(v *dto.MetricFamily, scheme EscapingScheme) *dto.MetricF
Histogram: m.Histogram,
TimestampMs: m.TimestampMs,
}

if m.Label != nil {
escaped.Label = make([]*dto.LabelPair, 0, len(m.Label))
}
for _, l := range m.Label {
if l.GetName() == MetricNameLabel {
if l.Value == nil || IsValidLegacyMetricName(l.GetValue()) {
Expand Down Expand Up @@ -424,6 +429,7 @@ func EscapeName(name string, scheme EscapingScheme) string {
if IsValidLegacyMetricName(name) {
return name
}
escaped.Grow(len(name))
for i, b := range name {
if isValidLegacyRune(b, i) {
escaped.WriteRune(b)
Expand Down
Loading