From c3b8582cf4b6e85b6d903fd872299484f173016b Mon Sep 17 00:00:00 2001 From: Manik Rana Date: Mon, 14 Oct 2024 14:48:15 +0530 Subject: [PATCH] [PERF] textparse: optimize OM `p.isCreatedSeries()` (#15150) * refac: remove p.Metric usage Signed-off-by: Manik Rana * perf: use bytes instead of strings Signed-off-by: Manik Rana * chore: comments Signed-off-by: Manik Rana --------- Signed-off-by: Manik Rana Signed-off-by: Manik Rana --- model/textparse/openmetricsparse.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/model/textparse/openmetricsparse.go b/model/textparse/openmetricsparse.go index 13629e66db..638e9619c9 100644 --- a/model/textparse/openmetricsparse.go +++ b/model/textparse/openmetricsparse.go @@ -652,10 +652,9 @@ func (p *OpenMetricsParser) parseLVals(offsets []int, isExemplar bool) ([]int, e // isCreatedSeries returns true if the current series is a _created series. func (p *OpenMetricsParser) isCreatedSeries() bool { - var newLbs labels.Labels - p.Metric(&newLbs) - name := newLbs.Get(model.MetricNameLabel) - if typeRequiresCT(p.mtype) && strings.HasSuffix(name, "_created") { + metricName := p.series[p.offsets[0]-p.start : p.offsets[1]-p.start] + // check length so the metric is longer than len("_created") + if typeRequiresCT(p.mtype) && len(metricName) >= 8 && string(metricName[len(metricName)-8:]) == "_created" { return true } return false