weetime / remote_storage_adapter

support clickhouse
Apache License 2.0
32 stars 11 forks source link

fix wrong match tagFormat in clickhouse when promql use regex. #13

Closed zxcvf closed 1 year ago

zxcvf commented 1 year ago

update clickhouse/query.go

zxcvf commented 1 year ago

` switch m.Type { case prompb.LabelMatcher_EQ, prompb.LabelMatcher_NEQ:

    case prompb.LabelMatcher_RE, prompb.LabelMatcher_NRE:
        var tagFormat string
        var val string

                    // BUG here,  prompb.LabelMatcher_EQ  should be  prompb.LabelMatcher_RE
        if m.Type == prompb.LabelMatcher_EQ {
            tagFormat = ` AND arrayExists(x -> 1 == match(x, '^%s=%s'),tags) = 1 `
        } else {
            tagFormat = ` AND arrayExists(x -> 1 == match(x, '^%s=%s'),tags) = 0 `
        }

        if strings.HasPrefix(m.Value, "^") {
            val = strings.Replace(m.Value, "^", "", 1)
        }
        val = strings.Replace(val, `/`, `\/`, -1)
        str := fmt.Sprintf(tagFormat, m.Name, val)
        s.sqlStr.WriteString(str)
    }

`