Skip to content

Commit

Permalink
Remove responses metric
Browse files Browse the repository at this point in the history
Signed-off-by: Albert Teoh <see.kwang.teoh@gmail.com>
  • Loading branch information
albertteoh committed May 9, 2022
1 parent 9009b3d commit 857f64a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
12 changes: 5 additions & 7 deletions storage/metricsstore/metrics/decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,17 @@ type ReadMetricsDecorator struct {
type queryMetrics struct {
Errors metrics.Counter `metric:"requests" tags:"result=err"`
Successes metrics.Counter `metric:"requests" tags:"result=ok"`
Responses metrics.Timer `metric:"responses"`
ErrLatency metrics.Timer `metric:"latency" tags:"result=err"`
OKLatency metrics.Timer `metric:"latency" tags:"result=ok"`
}

func (q *queryMetrics) emit(err error, latency time.Duration, responses int) {
func (q *queryMetrics) emit(err error, latency time.Duration) {
if err != nil {
q.Errors.Inc(1)
q.ErrLatency.Record(latency)
} else {
q.Successes.Inc(1)
q.OKLatency.Record(latency)
q.Responses.Record(time.Duration(responses))
}
}

Expand All @@ -74,30 +72,30 @@ func buildQueryMetrics(operation string, metricsFactory metrics.Factory) *queryM
func (m *ReadMetricsDecorator) GetLatencies(ctx context.Context, params *metricsstore.LatenciesQueryParameters) (*protometrics.MetricFamily, error) {
start := time.Now()
retMe, err := m.reader.GetLatencies(ctx, params)
m.getLatenciesMetrics.emit(err, time.Since(start), 1)
m.getLatenciesMetrics.emit(err, time.Since(start))
return retMe, err
}

// GetCallRates implements metricsstore.Reader#GetCallRates
func (m *ReadMetricsDecorator) GetCallRates(ctx context.Context, params *metricsstore.CallRateQueryParameters) (*protometrics.MetricFamily, error) {
start := time.Now()
retMe, err := m.reader.GetCallRates(ctx, params)
m.getCallRatesMetrics.emit(err, time.Since(start), 1)
m.getCallRatesMetrics.emit(err, time.Since(start))
return retMe, err
}

// GetErrorRates implements metricsstore.Reader#GetErrorRates
func (m *ReadMetricsDecorator) GetErrorRates(ctx context.Context, params *metricsstore.ErrorRateQueryParameters) (*protometrics.MetricFamily, error) {
start := time.Now()
retMe, err := m.reader.GetErrorRates(ctx, params)
m.getErrorRatesMetrics.emit(err, time.Since(start), 1)
m.getErrorRatesMetrics.emit(err, time.Since(start))
return retMe, err
}

// GetMinStepDuration implements metricsstore.Reader#GetMinStepDuration
func (m *ReadMetricsDecorator) GetMinStepDuration(ctx context.Context, params *metricsstore.MinStepDurationQueryParameters) (time.Duration, error) {
start := time.Now()
retMe, err := m.reader.GetMinStepDuration(ctx, params)
m.getMinStepDurationMetrics.emit(err, time.Since(start), 1)
m.getMinStepDurationMetrics.emit(err, time.Since(start))
return retMe, err
}
2 changes: 0 additions & 2 deletions storage/metricsstore/metrics/decorator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func TestSuccessfulUnderlyingCalls(t *testing.T) {
// This is not exhaustive.
wantExistingKeys := []string{
"latency|operation=get_latencies|result=ok.P50",
"responses|operation=get_call_rates.P50",
"latency|operation=get_error_rates|result=ok.P50",
}

Expand Down Expand Up @@ -147,7 +146,6 @@ func TestFailingUnderlyingCalls(t *testing.T) {
// This is not exhaustive.
wantNonExistentKeys := []string{
"latency|operation=get_latencies|result=ok.P50",
"responses|operation=get_call_rates|result=ok.P50",
"latency|operation=get_error_rates|result=ok.P50",
}

Expand Down

0 comments on commit 857f64a

Please sign in to comment.