diff --git a/go.mod b/go.mod index 37386c962..ba04787dd 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/dustin/go-humanize v1.0.1 github.com/go-chi/chi v4.1.2+incompatible github.com/go-chi/render v1.0.1 - github.com/go-graphite/carbonapi v0.16.0 + github.com/go-graphite/carbonapi v0.16.2-0.20231101113133-39b476ab3e6d github.com/go-graphite/protocol v1.0.0 github.com/go-redis/redis/v8 v8.11.5 github.com/go-redsync/redsync/v4 v4.4.4 @@ -55,7 +55,6 @@ require ( ) require ( - bitbucket.org/tebeka/strftime v0.0.0-20140926081919-2194253a23c0 // indirect github.com/JaderDias/movingmedian v0.0.0-20220813210630-d8c6b6de8835 // indirect github.com/Masterminds/sprig/v3 v3.2.3 github.com/RoaringBitmap/roaring v1.3.0 // indirect @@ -192,6 +191,7 @@ require ( github.com/shopspring/decimal v1.2.0 // indirect github.com/swaggo/files v1.0.1 // indirect github.com/swaggo/swag v1.8.12 // indirect + github.com/tebeka/strftime v0.1.5 // indirect golang.org/x/tools v0.12.0 // indirect ) diff --git a/go.sum b/go.sum index f73e0f1bf..905d91bc8 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -bitbucket.org/tebeka/strftime v0.0.0-20140926081919-2194253a23c0 h1:800dI8vRxVMgss6UcZY8gxk8PvYw7Qo1ZI3TrUkTKjc= -bitbucket.org/tebeka/strftime v0.0.0-20140926081919-2194253a23c0/go.mod h1:9BKpS/J2txC7Ql3QUhesesiV3HsIsA7zl7VK6cQVg5M= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.31.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= @@ -589,8 +587,8 @@ github.com/go-errors/errors v1.1.1/go.mod h1:psDX2osz5VnTOnFWbDeWwS7yejl+uV3FEWE github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-graphite/carbonapi v0.16.0 h1:HvPjAKYChiwdHtNpFu33hLRpPCYA7gyyeFWpPR2XvXs= -github.com/go-graphite/carbonapi v0.16.0/go.mod h1:RQpis4h2a1kxn1s/R5LQXbumFj+kR2bRz+BebPN1Z1Q= +github.com/go-graphite/carbonapi v0.16.2-0.20231101113133-39b476ab3e6d h1:XzKqULyL0Qlsz5VVl7Q82YWFbdnJTZYCc1lO4kKKUEs= +github.com/go-graphite/carbonapi v0.16.2-0.20231101113133-39b476ab3e6d/go.mod h1:vefIVMyWf471SFMpHS4CSbySjGaMPtNxmMTnTlU2tSc= github.com/go-graphite/protocol v1.0.0 h1:Fqb0mkVVtfMrn6vw6Ntm3raf3gVVZCOVdZu4JosW5qE= github.com/go-graphite/protocol v1.0.0/go.mod h1:eonkg/0UGhJUYu+PshOg1NzWSUcXskr/yHeQXJHJr8Y= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= @@ -1084,6 +1082,8 @@ github.com/swaggo/http-swagger v1.3.4/go.mod h1:9dAh0unqMBAlbp1uE2Uc2mQTxNMU/ha4 github.com/swaggo/swag v1.8.12 h1:pctzkNPu0AlQP2royqX3apjKCQonAnf7KGoxeO4y64w= github.com/swaggo/swag v1.8.12/go.mod h1:lNfm6Gg+oAq3zRJQNEMBE66LIJKM44mxFqhEEgy2its= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= +github.com/tebeka/strftime v0.1.5 h1:1NQKN1NiQgkqd/2moD6ySP/5CoZQsKa1d3ZhJ44Jpmg= +github.com/tebeka/strftime v0.1.5/go.mod h1:29/OidkoWHdEKZqzyDLUyC+LmgDgdHo4WAFCDT7D/Ig= github.com/tinylib/msgp v1.1.8 h1:FCXC1xanKO4I8plpHGH2P7koL/RzZs12l/+r7vakfm0= github.com/tinylib/msgp v1.1.8/go.mod h1:qkpG+2ldGg4xRFmx+jfTvZPxfGFhi64BcnL9vkCm/Tw= github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU= diff --git a/metric_source/local/eval.go b/metric_source/local/eval.go index a2d51a6ae..a985ab115 100644 --- a/metric_source/local/eval.go +++ b/metric_source/local/eval.go @@ -94,7 +94,7 @@ func (ctx *evalCtx) parse(target string) (parser.Expr, error) { } func (ctx *evalCtx) getMetricsData(database moira.Database, parsedExpr parser.Expr) (*fetchedMetrics, error) { - metricRequests := parsedExpr.Metrics() + metricRequests := parsedExpr.Metrics(0, 0) metrics := make([]string, 0) metricsMap := make(map[parser.MetricRequest][]*types.MetricData) @@ -190,7 +190,7 @@ func (ctx *evalCtx) writeResult(exp parser.Expr, metrics *fetchedMetrics, metric } result.Metrics = append(result.Metrics, metrics.metrics...) - for _, mr := range exp.Metrics() { + for _, mr := range exp.Metrics(0, 0) { result.Patterns = append(result.Patterns, mr.Metric) } } diff --git a/metric_source/local/local_test.go b/metric_source/local/local_test.go index 88403d72b..0e8af0e8e 100644 --- a/metric_source/local/local_test.go +++ b/metric_source/local/local_test.go @@ -362,6 +362,66 @@ func TestLocalSourceFetch(t *testing.T) { Patterns: []string{pattern1}, }) }) + + Convey("Test success evaluate target with aliasByTags('name')", t, func() { + database.EXPECT().GetPatternMetrics(pattern1).Return([]string{metric}, nil) + database.EXPECT().GetMetricRetention(metric).Return(retention, nil) + database.EXPECT().GetMetricsValues([]string{metric}, retentionFrom, retentionUntil-1).Return(dataList, nil) + database.EXPECT().GetMetricsTTLSeconds().Return(metricsTTL) + + result, err := localSource.Fetch("super.puper.pattern | aliasByTags('name')", from, until, true) + + So(err, ShouldBeNil) + So(result, ShouldResemble, &FetchResult{ + MetricsData: []metricSource.MetricData{{ + Name: "super.puper.metric", + StartTime: retentionFrom, + StopTime: retentionUntil, + StepTime: retention, + Values: []float64{0, 1, 2, 3, 4}, + }}, + Metrics: []string{metric}, + Patterns: []string{pattern1}, + }) + }) + + Convey("Test success evaluate target with currentAbove(3.99)", t, func() { + database.EXPECT().GetPatternMetrics(pattern1).Return([]string{metric}, nil) + database.EXPECT().GetMetricRetention(metric).Return(retention, nil) + database.EXPECT().GetMetricsValues([]string{metric}, retentionFrom, retentionUntil-1).Return(dataList, nil) + database.EXPECT().GetMetricsTTLSeconds().Return(metricsTTL) + + result, err := localSource.Fetch("super.puper.pattern | currentAbove(3.99)", from, until, true) + + So(err, ShouldBeNil) + So(result, ShouldResemble, &FetchResult{ + MetricsData: []metricSource.MetricData{{ + Name: "super.puper.metric", + StartTime: retentionFrom, + StopTime: retentionUntil, + StepTime: retention, + Values: []float64{0, 1, 2, 3, 4}, + }}, + Metrics: []string{metric}, + Patterns: []string{pattern1}, + }) + }) + + Convey("Test success evaluate target with currentAbove(4)", t, func() { + database.EXPECT().GetPatternMetrics(pattern1).Return([]string{metric}, nil) + database.EXPECT().GetMetricRetention(metric).Return(retention, nil) + database.EXPECT().GetMetricsValues([]string{metric}, retentionFrom, retentionUntil-1).Return(dataList, nil) + database.EXPECT().GetMetricsTTLSeconds().Return(metricsTTL) + + result, err := localSource.Fetch("super.puper.pattern | currentAbove(4)", from, until, true) + + So(err, ShouldBeNil) + So(result, ShouldResemble, &FetchResult{ + MetricsData: []metricSource.MetricData{}, + Metrics: []string{metric}, + Patterns: []string{pattern1}, + }) + }) } func TestLocalSourceFetchNoRealTimeAlerting(t *testing.T) {