From b2ac3d2d86d7190675fc716d434f2ad6f8bf6125 Mon Sep 17 00:00:00 2001 From: Brian Brazil Date: Thu, 5 Oct 2017 13:05:11 +0100 Subject: [PATCH] Remove count_scalar and drop_common_labels. For #3060 --- promql/functions.go | 62 ------------------------------------- promql/testdata/legacy.test | 34 ++------------------ 2 files changed, 2 insertions(+), 94 deletions(-) diff --git a/promql/functions.go b/promql/functions.go index 71dffd3b4..60548f312 100644 --- a/promql/functions.go +++ b/promql/functions.go @@ -327,48 +327,6 @@ func funcClampMin(ev *evaluator, args Expressions) Value { return vec } -// === drop_common_labels(node ValueTypeVector) Vector === -func funcDropCommonLabels(ev *evaluator, args Expressions) Value { - vec := ev.evalVector(args[0]) - if len(vec) < 1 { - return Vector{} - } - common := map[string]string{} - - for _, l := range vec[0].Metric { - // TODO(julius): Should we also drop common metric names? - if l.Name == labels.MetricName { - continue - } - common[l.Name] = l.Value - } - - for _, el := range vec[1:] { - for k, v := range common { - for _, l := range el.Metric { - if l.Name == k && l.Value != v { - // Deletion of map entries while iterating over them is safe. - // From http://golang.org/ref/spec#For_statements: - // "If map entries that have not yet been reached are deleted during - // iteration, the corresponding iteration values will not be produced." - delete(common, k) - } - } - } - } - - cnames := []string{} - for n := range common { - cnames = append(cnames, n) - } - - for i := range vec { - el := &vec[i] - el.Metric = labels.NewBuilder(el.Metric).Del(cnames...).Labels() - } - return vec -} - // === round(Vector ValueTypeVector, toNearest=1 Scalar) Vector === func funcRound(ev *evaluator, args Expressions) Value { // round returns a number rounded to toNearest. @@ -405,14 +363,6 @@ func funcScalar(ev *evaluator, args Expressions) Value { } } -// === count_scalar(Vector ValueTypeVector) float64 === -func funcCountScalar(ev *evaluator, args Expressions) Value { - return Scalar{ - V: float64(len(ev.evalVector(args[0]))), - T: ev.Timestamp, - } -} - func aggrOverTime(ev *evaluator, args Expressions, aggrFn func([]Point) float64) Value { mat := ev.evalMatrix(args[0]) resultVector := Vector{} @@ -1052,12 +1002,6 @@ var functions = map[string]*Function{ ReturnType: ValueTypeVector, Call: funcCountOverTime, }, - "count_scalar": { - Name: "count_scalar", - ArgTypes: []ValueType{ValueTypeVector}, - ReturnType: ValueTypeScalar, - Call: funcCountScalar, - }, "days_in_month": { Name: "days_in_month", ArgTypes: []ValueType{ValueTypeVector}, @@ -1091,12 +1035,6 @@ var functions = map[string]*Function{ ReturnType: ValueTypeVector, Call: funcDeriv, }, - "drop_common_labels": { - Name: "drop_common_labels", - ArgTypes: []ValueType{ValueTypeVector}, - ReturnType: ValueTypeVector, - Call: funcDropCommonLabels, - }, "exp": { Name: "exp", ArgTypes: []ValueType{ValueTypeVector}, diff --git a/promql/testdata/legacy.test b/promql/testdata/legacy.test index 1556485f8..607c2819c 100644 --- a/promql/testdata/legacy.test +++ b/promql/testdata/legacy.test @@ -125,14 +125,6 @@ eval instant at 50m rate(testcounter_zero_cutoff[20m]) {start="5m"} 0.6 -# count_scalar for a non-empty vector should return scalar element count. -eval instant at 50m count_scalar(http_requests) - 8 - -# count_scalar for an empty vector should return scalar 0. -eval instant at 50m count_scalar(nonexistent) - 0 - eval instant at 50m http_requests{group!="canary"} http_requests{group="production", instance="1", job="app-server"} 600 http_requests{group="production", instance="0", job="app-server"} 500 @@ -149,9 +141,6 @@ eval instant at 50m http_requests{job!~"api-.+",group!="canary"} http_requests{group="production", instance="1", job="app-server"} 600 http_requests{group="production", instance="0", job="app-server"} 500 -eval instant at 50m count_scalar(http_requests{job=~"server"}) - 0 - eval instant at 50m http_requests{group="production",job=~"api-.+"} http_requests{group="production", instance="0", job="api-server"} 100 http_requests{group="production", instance="1", job="api-server"} 200 @@ -244,10 +233,6 @@ eval instant at 50m sum_over_time(http_requests{group="production",job="api-serv eval instant at 50m time() 3000 -eval instant at 50m drop_common_labels(http_requests{group="production",job="api-server"}) - http_requests{instance="0"} 100 - http_requests{instance="1"} 200 - eval instant at 50m {__name__=~".+"} http_requests{group="canary", instance="0", job="api-server"} 300 http_requests{group="canary", instance="0", job="app-server"} 700 @@ -283,11 +268,9 @@ eval instant at 50m absent(nonexistent) eval instant at 50m absent(nonexistent{job="testjob", instance="testinstance", method=~".x"}) {instance="testinstance", job="testjob"} 1 -eval instant at 50m count_scalar(absent(http_requests)) - 0 +eval instant at 50m absent(http_requests) -eval instant at 50m count_scalar(absent(sum(http_requests))) - 0 +eval instant at 50m absent(sum(http_requests)) eval instant at 50m absent(sum(nonexistent{job="testjob", instance="testinstance"})) {} 1 @@ -370,19 +353,6 @@ eval instant at 50m log10(vector_matching_a - 20) # Matrix tests. - -clear -load 1h - testmetric{testlabel="1"} 1 1 - testmetric{testlabel="2"} _ 2 - -eval instant at 0h drop_common_labels(testmetric) - testmetric 1 - -eval instant at 1h drop_common_labels(testmetric) - testmetric{testlabel="1"} 1 - testmetric{testlabel="2"} 2 - clear load 1h testmetric{testlabel="1"} 1 1