From 8f77d271b15d4f8a9416181f1efd09e364f9cf52 Mon Sep 17 00:00:00 2001 From: Matti Savolainen Date: Tue, 11 Oct 2016 21:48:03 +0300 Subject: [PATCH] validate the label name --- relabel/relabel.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/relabel/relabel.go b/relabel/relabel.go index 69ec66e26..6ce37296c 100644 --- a/relabel/relabel.go +++ b/relabel/relabel.go @@ -61,17 +61,17 @@ func relabel(labels model.LabelSet, cfg *config.RelabelConfig) model.LabelSet { if indexes == nil { break } - res := cfg.Regex.ExpandString([]byte{}, cfg.Replacement, val, indexes) - if len(res) == 0 { + target := model.LabelName(cfg.Regex.ExpandString([]byte{}, string(cfg.TargetLabel), val, indexes)) + if !target.IsValid() { delete(labels, cfg.TargetLabel) break } - target := cfg.Regex.ExpandString([]byte{}, string(cfg.TargetLabel), val, indexes) - if len(target) == 0 { + res := cfg.Regex.ExpandString([]byte{}, cfg.Replacement, val, indexes) + if len(res) == 0 { delete(labels, cfg.TargetLabel) break } - labels[model.LabelName(target)] = model.LabelValue(res) + labels[target] = model.LabelValue(res) case config.RelabelHashMod: mod := sum64(md5.Sum([]byte(val))) % cfg.Modulus labels[cfg.TargetLabel] = model.LabelValue(fmt.Sprintf("%d", mod))