From 8b602110eacfe14e7a81c2dbb16a6d88bad84ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Pazos?= Date: Wed, 31 Jul 2024 14:39:22 -0300 Subject: [PATCH] fix name tag for movingMedian --- expr/functions/movingMedian/function.go | 3 ++- expr/functions/movingMedian/function_test.go | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/expr/functions/movingMedian/function.go b/expr/functions/movingMedian/function.go index e60881bae..5e7b63dcd 100644 --- a/expr/functions/movingMedian/function.go +++ b/expr/functions/movingMedian/function.go @@ -118,7 +118,8 @@ func (f *movingMedian) Do(ctx context.Context, eval interfaces.Evaluator, e pars result := make([]*types.MetricData, len(arg)) for n, a := range arg { - r := a.CopyName("movingMedian(" + a.Name + "," + argstr + ")") + r := a.CopyLink() + r.Name = "movingMedian(" + a.Name + "," + argstr + ")" if windowSize == 0 { if *f.config.ReturnNaNsIfStepMismatch { diff --git a/expr/functions/movingMedian/function_test.go b/expr/functions/movingMedian/function_test.go index 564176ad7..5fe3344d8 100644 --- a/expr/functions/movingMedian/function_test.go +++ b/expr/functions/movingMedian/function_test.go @@ -34,7 +34,7 @@ func TestMovingMedian(t *testing.T) { {Metric: "metric1", From: 0, Until: 1}: {types.MakeMetricData("metric1", []float64{1, 1, 1, 1, 2, 2, 2, 4, 6, 4, 6, 8}, 1, now32)}, }, []*types.MetricData{types.MakeMetricData("movingMedian(metric1,4)", []float64{math.NaN(), math.NaN(), math.NaN(), 1, 1, 1.5, 2, 2, 3, 4, 5, 6}, - 1, 0).SetTag("movingMedian", "4").SetNameTag("movingMedian(metric1,4)")}, // StartTime = from + 1, 0).SetTag("movingMedian", "4").SetNameTag("metric1")}, // StartTime = from }, { "movingMedian(metric1,5)", @@ -42,7 +42,7 @@ func TestMovingMedian(t *testing.T) { {Metric: "metric1", From: 0, Until: 1}: {types.MakeMetricData("metric1", []float64{1, 1, 1, 1, 2, 2, 2, 4, 6, 4, 6, 8, 1, 2, math.NaN()}, 1, now32)}, }, []*types.MetricData{types.MakeMetricData("movingMedian(metric1,5)", []float64{math.NaN(), math.NaN(), math.NaN(), math.NaN(), 1, 1, 2, 2, 2, 4, 4, 6, 6, 4, 2}, - 1, 0).SetTag("movingMedian", "5").SetNameTag("movingMedian(metric1,5)")}, // StartTime = from + 1, 0).SetTag("movingMedian", "5").SetNameTag("metric1")}, // StartTime = from }, { "movingMedian(metric1,\"1s\")", @@ -50,7 +50,7 @@ func TestMovingMedian(t *testing.T) { {Metric: "metric1", From: -1, Until: 1}: {types.MakeMetricData("metric1", []float64{1, 1, 1, 1, 1, 2, 2, 2, 4, 6, 4, 6, 8, 1, 2, 0}, 1, now32)}, }, []*types.MetricData{types.MakeMetricData("movingMedian(metric1,'1s')", []float64{1, 1, 1, 1, 2, 2, 2, 4, 6, 4, 6, 8, 1, 2, 0}, - 1, 0).SetTag("movingMedian", "'1s'").SetNameTag("movingMedian(metric1,'1s')")}, // StartTime = from + 1, 0).SetTag("movingMedian", "'1s'").SetNameTag("metric1")}, // StartTime = from }, { "movingMedian(metric1,\"3s\")", @@ -58,7 +58,7 @@ func TestMovingMedian(t *testing.T) { {Metric: "metric1", From: -3, Until: 1}: {types.MakeMetricData("metric1", []float64{0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 4, 6, 4, 6, 8, 1, 2}, 1, now32)}, }, []*types.MetricData{types.MakeMetricData("movingMedian(metric1,'3s')", []float64{0, 1, 1, 1, 1, 2, 2, 2, 4, 4, 6, 6, 6, 2}, - 1, 0).SetTag("movingMedian", "'3s'").SetNameTag("movingMedian(metric1,'3s')")}, // StartTime = from + 1, 0).SetTag("movingMedian", "'3s'").SetNameTag("metric1")}, // StartTime = from }, { "movingMedian(metric1,\"5s\")", @@ -66,7 +66,7 @@ func TestMovingMedian(t *testing.T) { {Metric: "metric1", From: -5, Until: 1}: {types.MakeMetricData("metric1", []float64{1, 2, 3}, 10, now32)}, // step > windowSize }, []*types.MetricData{types.MakeMetricData("movingMedian(metric1,'5s')", []float64{math.NaN(), math.NaN(), math.NaN()}, - 10, now32).SetTag("movingMedian", "'5s'").SetNameTag("movingMedian(metric1,'5s')")}, // StartTime = from + 10, now32).SetTag("movingMedian", "'5s'").SetNameTag("metric1")}, // StartTime = from }, }