-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into grpc-withresolver
- Loading branch information
Showing
5 changed files
with
384 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright (c) 2021 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package querysvc | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"time" | ||
|
||
"github.com/jaegertracing/jaeger/proto-gen/api_v2/metrics" | ||
"github.com/jaegertracing/jaeger/storage/metricsstore" | ||
) | ||
|
||
// MetricsQueryService contains the underlying reader required for querying the metrics store. | ||
type MetricsQueryService struct { | ||
metricsReader metricsstore.Reader | ||
} | ||
|
||
var errNilReader = errors.New("no reader defined for MetricsQueryService") | ||
|
||
// NewMetricsQueryService returns a new MetricsQueryService. | ||
// A nil reader will result in a nil MetricsQueryService being returned. | ||
func NewMetricsQueryService(reader metricsstore.Reader) *MetricsQueryService { | ||
return &MetricsQueryService{ | ||
metricsReader: reader, | ||
} | ||
} | ||
|
||
// GetLatencies is the queryService implementation of metricsstore.Reader. | ||
func (mqs MetricsQueryService) GetLatencies(ctx context.Context, params *metricsstore.LatenciesQueryParameters) (*metrics.MetricFamily, error) { | ||
if mqs.metricsReader == nil { | ||
return nil, errNilReader | ||
} | ||
return mqs.metricsReader.GetLatencies(ctx, params) | ||
} | ||
|
||
// GetCallRates is the queryService implementation of metricsstore.Reader. | ||
func (mqs MetricsQueryService) GetCallRates(ctx context.Context, params *metricsstore.CallRateQueryParameters) (*metrics.MetricFamily, error) { | ||
if mqs.metricsReader == nil { | ||
return nil, errNilReader | ||
} | ||
return mqs.metricsReader.GetCallRates(ctx, params) | ||
} | ||
|
||
// GetErrorRates is the queryService implementation of metricsstore.Reader. | ||
func (mqs MetricsQueryService) GetErrorRates(ctx context.Context, params *metricsstore.ErrorRateQueryParameters) (*metrics.MetricFamily, error) { | ||
if mqs.metricsReader == nil { | ||
return nil, errNilReader | ||
} | ||
return mqs.metricsReader.GetErrorRates(ctx, params) | ||
} | ||
|
||
// GetMinStepDuration is the queryService implementation of metricsstore.Reader. | ||
func (mqs MetricsQueryService) GetMinStepDuration(ctx context.Context, params *metricsstore.MinStepDurationQueryParameters) (time.Duration, error) { | ||
if mqs.metricsReader == nil { | ||
return 0, errNilReader | ||
} | ||
return mqs.metricsReader.GetMinStepDuration(ctx, params) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// Copyright (c) 2021 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package querysvc | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
|
||
protometrics "github.com/jaegertracing/jaeger/proto-gen/api_v2/metrics" | ||
"github.com/jaegertracing/jaeger/storage/metricsstore" | ||
metricsmocks "github.com/jaegertracing/jaeger/storage/metricsstore/mocks" | ||
) | ||
|
||
type testMetricsQueryService struct { | ||
queryService *MetricsQueryService | ||
metricsReader *metricsmocks.Reader | ||
} | ||
|
||
func initializeTestMetricsQueryService() *testMetricsQueryService { | ||
metricsReader := &metricsmocks.Reader{} | ||
|
||
tqs := testMetricsQueryService{ | ||
metricsReader: metricsReader, | ||
} | ||
|
||
tqs.queryService = NewMetricsQueryService(metricsReader) | ||
return &tqs | ||
} | ||
|
||
// Test QueryService.GetLatencies() | ||
func TestGetLatencies(t *testing.T) { | ||
tqs := initializeTestMetricsQueryService() | ||
expectedLatencies := &protometrics.MetricFamily{ | ||
Name: "latencies", | ||
Metrics: []*protometrics.Metric{}, | ||
} | ||
qParams := &metricsstore.LatenciesQueryParameters{} | ||
tqs.metricsReader.On("GetLatencies", mock.Anything, qParams).Return(expectedLatencies, nil).Times(1) | ||
|
||
actualLatencies, err := tqs.queryService.GetLatencies(context.Background(), qParams) | ||
assert.NoError(t, err) | ||
assert.Equal(t, expectedLatencies, actualLatencies) | ||
} | ||
|
||
func TestGetLatenciesNilReader(t *testing.T) { | ||
qs := NewMetricsQueryService(nil) | ||
qParams := &metricsstore.LatenciesQueryParameters{} | ||
r, err := qs.GetLatencies(context.Background(), qParams) | ||
assert.Zero(t, r) | ||
assert.EqualError(t, err, errNilReader.Error()) | ||
} | ||
|
||
// Test QueryService.GetCallRates() | ||
func TestGetCallRates(t *testing.T) { | ||
tqs := initializeTestMetricsQueryService() | ||
expectedCallRates := &protometrics.MetricFamily{ | ||
Name: "call rates", | ||
Metrics: []*protometrics.Metric{}, | ||
} | ||
qParams := &metricsstore.CallRateQueryParameters{} | ||
tqs.metricsReader.On("GetCallRates", mock.Anything, qParams).Return(expectedCallRates, nil).Times(1) | ||
|
||
actualCallRates, err := tqs.queryService.GetCallRates(context.Background(), qParams) | ||
assert.NoError(t, err) | ||
assert.Equal(t, expectedCallRates, actualCallRates) | ||
} | ||
|
||
func TestGetCallRatesNilReader(t *testing.T) { | ||
qs := NewMetricsQueryService(nil) | ||
qParams := &metricsstore.CallRateQueryParameters{} | ||
r, err := qs.GetCallRates(context.Background(), qParams) | ||
assert.Zero(t, r) | ||
assert.EqualError(t, err, errNilReader.Error()) | ||
} | ||
|
||
// Test QueryService.GetErrorRates() | ||
func TestGetErrorRates(t *testing.T) { | ||
tqs := initializeTestMetricsQueryService() | ||
expectedErrorRates := &protometrics.MetricFamily{} | ||
qParams := &metricsstore.ErrorRateQueryParameters{} | ||
tqs.metricsReader.On("GetErrorRates", mock.Anything, qParams).Return(expectedErrorRates, nil).Times(1) | ||
|
||
actualErrorRates, err := tqs.queryService.GetErrorRates(context.Background(), qParams) | ||
assert.NoError(t, err) | ||
assert.Equal(t, expectedErrorRates, actualErrorRates) | ||
} | ||
|
||
func TestGetErrorRatesNilReader(t *testing.T) { | ||
qs := NewMetricsQueryService(nil) | ||
qParams := &metricsstore.ErrorRateQueryParameters{} | ||
r, err := qs.GetErrorRates(context.Background(), qParams) | ||
assert.Zero(t, r) | ||
assert.EqualError(t, err, errNilReader.Error()) | ||
} | ||
|
||
// Test QueryService.GetMinStepDurations() | ||
func TestGetMinStepDurations(t *testing.T) { | ||
tqs := initializeTestMetricsQueryService() | ||
expectedMinStep := time.Second | ||
qParams := &metricsstore.MinStepDurationQueryParameters{} | ||
tqs.metricsReader.On("GetMinStepDuration", mock.Anything, qParams).Return(expectedMinStep, nil).Times(1) | ||
|
||
actualMinStep, err := tqs.queryService.GetMinStepDuration(context.Background(), qParams) | ||
assert.NoError(t, err) | ||
assert.Equal(t, expectedMinStep, actualMinStep) | ||
} | ||
|
||
func TestGetMinStepDurationsNilReader(t *testing.T) { | ||
qs := NewMetricsQueryService(nil) | ||
qParams := &metricsstore.MinStepDurationQueryParameters{} | ||
r, err := qs.GetMinStepDuration(context.Background(), qParams) | ||
assert.Zero(t, r) | ||
assert.EqualError(t, err, errNilReader.Error()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.