From 0ab75f577a4c43c8bd3be2bad3c2a48182f3d58a Mon Sep 17 00:00:00 2001 From: Mikhail Alpinskiy Date: Mon, 25 Nov 2024 13:05:35 +0300 Subject: [PATCH] PromQL engine update * Prefer mapped values --- internal/api/handler.go | 13 ++++++------- internal/api/sql.go | 9 +++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/internal/api/handler.go b/internal/api/handler.go index d74ce96de..49a42485f 100644 --- a/internal/api/handler.go +++ b/internal/api/handler.go @@ -2847,14 +2847,13 @@ func (c *pointsSelectCols) rowAt(i int) tsSelectRow { row.val[j] = c.val[j][i] } for j := range c.tag { - var hasSTag bool - if len(c.stag) != 0 { - hasSTag = c.stag[j].Pos[i].Start < c.stag[j].Pos[i].End && c.stag[j].Pos[i].End <= len(c.stag[j].Buf) - } - if hasSTag { - row.stag[c.tagIx[j]] = string(c.stag[j].Buf[c.stag[j].Pos[i].Start:c.stag[j].Pos[i].End]) - } else { + if c.tag[j][i] != 0 { row.tag[c.tagIx[j]] = c.tag[j][i] + } else if len(c.stag) != 0 { + hasSTag := c.stag[j].Pos[i].Start < c.stag[j].Pos[i].End && c.stag[j].Pos[i].End <= len(c.stag[j].Buf) + if hasSTag { + row.stag[c.tagIx[j]] = string(c.stag[j].Buf[c.stag[j].Pos[i].Start:c.stag[j].Pos[i].End]) + } } } if c.tagStr.Pos != nil && i < len(c.tagStr.Pos) { diff --git a/internal/api/sql.go b/internal/api/sql.go index 5944cc7f9..847c3994b 100644 --- a/internal/api/sql.go +++ b/internal/api/sql.go @@ -55,8 +55,13 @@ const ( func (pq *pointsQuery) cacheKey() string { var sb strings.Builder - sb.WriteString(";v=") - sb.WriteString(fmt.Sprint(pq.version)) + sb.WriteString("v=") + switch pq.version { + case Version1: + sb.WriteString(Version1) + default: + sb.WriteString(Version2) + } sb.WriteString(";m=") sb.WriteString(fmt.Sprint(pq.metricID)) sb.WriteString(";pk=")