Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aggregator/pkg/common/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type AggregatorMetricLabeler interface {
// RecordAPIRequestDuration records the duration of an API request in milliseconds.
RecordAPIRequestDuration(ctx context.Context, duration time.Duration)
// IncrementAPIRequestErrors increments the API request errors counter.
IncrementAPIRequestErrors(ctx context.Context)
IncrementAPIRequestErrors(ctx context.Context, method string)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of adding a method here? This is grpc and AFAIK method name is automatically included in the context

ctx = scope.WithAPIName(ctx, info.FullMethod)
return handler(ctx, req)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its more explicit IMO - opinionated? im fine with any option

// RecordMessageSinceNumberOfRecordsReturned records the number of records returned for a GetMessageSince request.
RecordMessageSinceNumberOfRecordsReturned(ctx context.Context, count int)
// IncrementPendingAggregationsChannelBuffer increments the pending aggregations channel buffer counter.
Expand Down
2 changes: 1 addition & 1 deletion aggregator/pkg/middlewares/metric_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (m *MetricMiddleware) Intercept(ctx context.Context, req any, info *grpc.Un

resp, err = handler(ctx, req)
if err != nil {
metrics.IncrementAPIRequestErrors(ctx)
metrics.IncrementAPIRequestErrors(ctx, info.FullMethod)
}
return resp, err
}
Expand Down
2 changes: 1 addition & 1 deletion aggregator/pkg/middlewares/metric_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestMetricMiddleware_Intercept(t *testing.T) {
metrics.EXPECT().IncrementActiveRequestsCounter(mock.Anything).Once()
metrics.EXPECT().DecrementActiveRequestsCounter(mock.Anything).Once()
metrics.EXPECT().RecordAPIRequestDuration(mock.Anything, mock.Anything).Once()
metrics.EXPECT().IncrementAPIRequestErrors(mock.Anything).Once()
metrics.EXPECT().IncrementAPIRequestErrors(mock.Anything, mock.Anything).Once()

middleware := NewMetricMiddleware(monitoring)

Expand Down
15 changes: 9 additions & 6 deletions aggregator/pkg/monitoring/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"time"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"

"github.com/smartcontractkit/chainlink-ccv/aggregator/pkg/common"
Expand Down Expand Up @@ -55,25 +56,25 @@ func MetricViews() []sdkmetric.View {
sdkmetric.NewView(
sdkmetric.Instrument{Name: "aggregator_time_to_aggregation_seconds"},
sdkmetric.Stream{Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
Boundaries: []float64{0, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10},
Boundaries: []float64{0, 0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10},
}},
),
sdkmetric.NewView(
sdkmetric.Instrument{Name: "aggregator_api_request_duration_seconds"},
sdkmetric.Stream{Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
Boundaries: []float64{0, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10},
Boundaries: []float64{0, 0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10},
}},
),
sdkmetric.NewView(
sdkmetric.Instrument{Name: "aggregator_get_message_since_number_of_records_returns"},
sdkmetric.Stream{Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
Boundaries: []float64{1, 5, 10, 25, 50, 100, 250, 500, 1000},
Boundaries: []float64{0, 1, 5, 10, 25, 50, 100, 250, 500, 1000},
}},
),
sdkmetric.NewView(
sdkmetric.Instrument{Name: "aggregator_storage_duration_seconds"},
sdkmetric.Stream{Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
Boundaries: []float64{0, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10},
Boundaries: []float64{0, 0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10},
}},
),
sdkmetric.NewView(
Expand Down Expand Up @@ -287,9 +288,11 @@ func (c *AggregatorMetricLabeler) RecordAPIRequestDuration(ctx context.Context,
c.am.apiRequestDuration.Record(ctx, duration.Seconds(), metric.WithAttributes(otelLabels...))
}

func (c *AggregatorMetricLabeler) IncrementAPIRequestErrors(ctx context.Context) {
func (c *AggregatorMetricLabeler) IncrementAPIRequestErrors(ctx context.Context, method string) {
otelLabels := beholder.OtelAttributes(c.Labels).AsStringAttributes()
c.am.apiRequestError.Add(ctx, 1, metric.WithAttributes(otelLabels...))
c.am.apiRequestError.Add(ctx, 1, metric.WithAttributes([]attribute.KeyValue{
attribute.String("method", method),
}...), metric.WithAttributes(otelLabels...))
}

func (c *AggregatorMetricLabeler) RecordMessageSinceNumberOfRecordsReturned(ctx context.Context, count int) {
Expand Down
2 changes: 1 addition & 1 deletion aggregator/pkg/monitoring/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (c *NoopAggregatorMetricLabeler) RecordAPIRequestDuration(ctx context.Conte
// No-op
}

func (c *NoopAggregatorMetricLabeler) IncrementAPIRequestErrors(ctx context.Context) {
func (c *NoopAggregatorMetricLabeler) IncrementAPIRequestErrors(ctx context.Context, method string) {
// No-op
}

Expand Down
17 changes: 9 additions & 8 deletions internal/mocks/mock_AggregatorMetricLabeler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading