Skip to content

Commit 9954453

Browse files
committed
Rename MetricsCollectorOpts to PrometheusMetricsOpts for consistency
1 parent 6427575 commit 9954453

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

dbrutil/query_metrics_event_receiver.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ package dbrutil
99
import (
1010
"time"
1111

12-
"github.com/acronis/go-dbkit"
1312
"github.com/gocraft/dbr/v2"
1413
)
1514

15+
// MetricsCollector is an interface for collecting metrics about SQL queries.
16+
type MetricsCollector interface {
17+
ObserveQueryDuration(query string, duration time.Duration)
18+
}
19+
1620
// QueryMetricsEventReceiverOpts consists options for QueryMetricsEventReceiver.
1721
type QueryMetricsEventReceiverOpts struct {
1822
AnnotationPrefix string
@@ -23,14 +27,14 @@ type QueryMetricsEventReceiverOpts struct {
2327
// To be collected, SQL query should be annotated (comment starting with specified prefix).
2428
type QueryMetricsEventReceiver struct {
2529
*dbr.NullEventReceiver
26-
metricsCollector dbkit.MetricsCollector
30+
metricsCollector MetricsCollector
2731
annotationPrefix string
2832
annotationModifier func(string) string
2933
}
3034

3135
// NewQueryMetricsEventReceiverWithOpts creates a new QueryMetricsEventReceiver with additinal options.
3236
func NewQueryMetricsEventReceiverWithOpts(
33-
mc dbkit.MetricsCollector, options QueryMetricsEventReceiverOpts,
37+
mc MetricsCollector, options QueryMetricsEventReceiverOpts,
3438
) *QueryMetricsEventReceiver {
3539
return &QueryMetricsEventReceiver{
3640
metricsCollector: mc,
@@ -40,7 +44,7 @@ func NewQueryMetricsEventReceiverWithOpts(
4044
}
4145

4246
// NewQueryMetricsEventReceiver creates a new QueryMetricsEventReceiver.
43-
func NewQueryMetricsEventReceiver(mc dbkit.MetricsCollector, annotationPrefix string) *QueryMetricsEventReceiver {
47+
func NewQueryMetricsEventReceiver(mc MetricsCollector, annotationPrefix string) *QueryMetricsEventReceiver {
4448
options := QueryMetricsEventReceiverOpts{
4549
AnnotationPrefix: annotationPrefix,
4650
}

metrics.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,14 @@ import (
1212
"github.com/prometheus/client_golang/prometheus"
1313
)
1414

15-
type MetricsCollector interface {
16-
ObserveQueryDuration(query string, duration time.Duration)
17-
}
18-
1915
// PrometheusMetricsLabelQuery is a label name for SQL query in Prometheus metrics.
2016
const PrometheusMetricsLabelQuery = "query"
2117

2218
// DefaultQueryDurationBuckets is default buckets into which observations of executing SQL queries are counted.
2319
var DefaultQueryDurationBuckets = []float64{0.001, 0.01, 0.1, 0.25, 0.5, 1, 2.5, 5, 10}
2420

25-
// MetricsCollectorOpts represents an options for PrometheusMetrics.
26-
type MetricsCollectorOpts struct {
21+
// PrometheusMetricsOpts represents an options for PrometheusMetrics.
22+
type PrometheusMetricsOpts struct {
2723
// Namespace is a namespace for metrics. It will be prepended to all metric names.
2824
Namespace string
2925

@@ -48,11 +44,11 @@ type PrometheusMetrics struct {
4844

4945
// NewPrometheusMetrics creates a new metrics collector.
5046
func NewPrometheusMetrics() *PrometheusMetrics {
51-
return NewPrometheusMetricsWithOpts(MetricsCollectorOpts{})
47+
return NewPrometheusMetricsWithOpts(PrometheusMetricsOpts{})
5248
}
5349

5450
// NewPrometheusMetricsWithOpts is a more configurable version of creating PrometheusMetrics.
55-
func NewPrometheusMetricsWithOpts(opts MetricsCollectorOpts) *PrometheusMetrics {
51+
func NewPrometheusMetricsWithOpts(opts PrometheusMetricsOpts) *PrometheusMetrics {
5652
queryDurationBuckets := opts.QueryDurationBuckets
5753
if queryDurationBuckets == nil {
5854
queryDurationBuckets = DefaultQueryDurationBuckets

0 commit comments

Comments
 (0)