app/vmselect/promql: make sure that label_replace() doesn't create an empty dst_label if the src_label doesn't match regex

This commit is contained in:
Aliaksandr Valialkin 2022-12-21 20:19:58 -08:00
parent 31886aef3d
commit d3de110070
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1

View File

@ -1873,12 +1873,12 @@ func labelReplace(tss []*timeseries, srcLabel string, r *regexp.Regexp, dstLabel
replacementBytes := []byte(replacement)
for _, ts := range tss {
mn := &ts.MetricName
dstValue := getDstValue(mn, dstLabel)
srcValue := mn.GetTagValue(srcLabel)
if !r.Match(srcValue) {
continue
}
b := r.ReplaceAll(srcValue, replacementBytes)
dstValue := getDstValue(mn, dstLabel)
*dstValue = append((*dstValue)[:0], b...)
if len(b) == 0 {
mn.RemoveTag(dstLabel)