Skip to content

Commit

Permalink
removing QueryRangeAggregatedTS as it no longer used
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnuchalla committed Aug 11, 2023
1 parent 9dc8764 commit 856db2e
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 119 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ require (
github.com/mailru/easyjson v0.7.7 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.7.1
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/onsi/ginkgo/v2 v2.11.0
github.com/onsi/gomega v1.27.8
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=
Expand Down
39 changes: 0 additions & 39 deletions prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ import (
"crypto/tls"
"fmt"
"net/http"
"strconv"
"time"

"github.com/montanaflynn/stats"
api "github.com/prometheus/client_golang/api"
apiv1 "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/prometheus/common/model"
Expand Down Expand Up @@ -84,43 +82,6 @@ func (p *Prometheus) QueryRange(query string, start, end time.Time, step time.Du
return v, nil
}

// QueryRangeAggregation returns the aggregation from the given query
// if the query returns multiple timeseries, their data points are aggregated into a single one
func (p *Prometheus) QueryRangeAggregatedTS(query string, start, end time.Time, step time.Duration, aggregation Aggregation) (float64, error) {
var err error
var datapoints []float64
var result float64
v, err := p.QueryRange(query, start, end, step)
if err != nil {
return result, err
}
data, ok := v.(model.Matrix)
if !ok {
return result, fmt.Errorf("result format is not a range vector: %s", data.Type().String())
}
for _, ts := range data {
for _, dp := range ts.Values {
datapoints = append(datapoints, float64(dp.Value))
}
}
switch aggregation {
case Avg:
result, err = stats.Mean(datapoints)
case Max:
result, err = stats.Max(datapoints)
case Min:
result, err = stats.Min(datapoints)
case P99, P95, P90, P50:
percentile, _ := strconv.ParseFloat(string(aggregation), 64)
result, err = stats.Percentile(datapoints, percentile)
case Stdev:
result, err = stats.StandardDeviation(datapoints)
default:
return result, fmt.Errorf("aggregation not supported: %s", aggregation)
}
return result, err
}

// Verifies prometheus connection
func (p *Prometheus) verifyConnection() error {
_, err := p.api.Runtimeinfo(context.TODO())
Expand Down
77 changes: 0 additions & 77 deletions prometheus/prometheus_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package prometheus

import (
"errors"
"fmt"
"net/http"
"time"
Expand Down Expand Up @@ -110,82 +109,6 @@ var _ = Describe("Tests for Prometheus", func() {

})

Context("Test for QueryRangeAggregatedTS", func() {
var mockAPI *MockAPI
var query string
var start, end time.Time
var step time.Duration
var p Prometheus
BeforeEach(func() {
mockAPI = new(MockAPI)
mockAPI.flag = 1
query = "your_query"
start := time.Now()
end = start.Add(time.Hour)
step = time.Minute
p = Prometheus{api: mockAPI}
count = 0
})

It("Test1 queryRange error", func() {
mockAPI.flag = 2
_, err := p.QueryRangeAggregatedTS(query, start, end, step, Avg)
//Asserting no of times mocks are called
Expect(count).To(BeEquivalentTo(1))
Expect(err).To(BeEquivalentTo(errors.New("sample error")))
})

It("Test2 for Avg", func() {
_, err := p.QueryRangeAggregatedTS(query, start, end, step, Avg)
//Asserting no of times mocks are called
Expect(count).To(BeEquivalentTo(1))
Expect(err).To(BeNil())
})

It("Test3 error when v not in matrix", func() {
mockAPI.flag = 0
_, err := p.QueryRangeAggregatedTS(query, start, end, step, Avg)
//Asserting no of times mocks are called
Expect(count).To(BeEquivalentTo(1))
Expect(err).To(BeEquivalentTo(errors.New("result format is not a range vector: matrix")))
})

It("Test4 for Min", func() {
_, err := p.QueryRangeAggregatedTS(query, start, end, step, Min)
//Asserting no of times mocks are called
Expect(count).To(BeEquivalentTo(1))
Expect(err).To(BeNil())
})

It("Test5 for Max", func() {
_, err := p.QueryRangeAggregatedTS(query, start, end, step, Max)
//Asserting no of times mocks are called
Expect(count).To(BeEquivalentTo(1))
Expect(err).To(BeNil())
})

It("Test6 for Stdev", func() {
_, err := p.QueryRangeAggregatedTS(query, start, end, step, Stdev)
//Asserting no of times mocks are called
Expect(count).To(BeEquivalentTo(1))
Expect(err).To(BeNil())
})

It("Test7 for P50 etc.", func() {
_, err := p.QueryRangeAggregatedTS(query, start, end, step, P50)
//Asserting no of times mocks are called
Expect(count).To(BeEquivalentTo(1))
Expect(err).To(BeNil())
})

It("Test6 no standard aggregator", func() {
_, err := p.QueryRangeAggregatedTS(query, start, end, step, "placeholder")
//Asserting no of times mocks are called
Expect(count).To(BeEquivalentTo(1))
Expect(err).To(BeEquivalentTo(errors.New("aggregation not supported: placeholder")))
})
})

Context("Tests for verifyConnection()", func() {
var mockAPI *MockAPI
var p Prometheus
Expand Down

0 comments on commit 856db2e

Please sign in to comment.