-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
middleware_bucket_metrics.go
76 lines (63 loc) · 2.71 KB
/
middleware_bucket_metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package tenant
import (
"context"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/metric"
"github.com/prometheus/client_golang/prometheus"
)
type BucketMetrics struct {
// RED metrics
rec *metric.REDClient
bucketService influxdb.BucketService
}
var _ influxdb.BucketService = (*BucketMetrics)(nil)
// NewBucketMetrics returns a metrics service middleware for the Bucket Service.
func NewBucketMetrics(reg prometheus.Registerer, s influxdb.BucketService, opts ...metric.MetricsOption) *BucketMetrics {
o := metric.ApplyMetricOpts(opts...)
return &BucketMetrics{
rec: metric.New(reg, o.ApplySuffix("bucket")),
bucketService: s,
}
}
// Returns a single bucket by ID.
func (m *BucketMetrics) FindBucketByID(ctx context.Context, id influxdb.ID) (*influxdb.Bucket, error) {
rec := m.rec.Record("find_bucket_by_id")
bucket, err := m.bucketService.FindBucketByID(ctx, id)
return bucket, rec(err)
}
// Returns the first bucket that matches filter.
func (m *BucketMetrics) FindBucket(ctx context.Context, filter influxdb.BucketFilter) (*influxdb.Bucket, error) {
rec := m.rec.Record("find_bucket")
bucket, err := m.bucketService.FindBucket(ctx, filter)
return bucket, rec(err)
}
// FindBuckets returns a list of buckets that match filter and the total count of matching buckets.
func (m *BucketMetrics) FindBuckets(ctx context.Context, filter influxdb.BucketFilter, opt ...influxdb.FindOptions) ([]*influxdb.Bucket, int, error) {
rec := m.rec.Record("find_buckets")
buckets, n, err := m.bucketService.FindBuckets(ctx, filter, opt...)
return buckets, n, rec(err)
}
// Creates a new bucket and sets b.ID with the new identifier.
func (m *BucketMetrics) CreateBucket(ctx context.Context, b *influxdb.Bucket) error {
rec := m.rec.Record("create_bucket")
err := m.bucketService.CreateBucket(ctx, b)
return rec(err)
}
// Updates a single bucket with changeset and returns the new bucket state after update.
func (m *BucketMetrics) UpdateBucket(ctx context.Context, id influxdb.ID, upd influxdb.BucketUpdate) (*influxdb.Bucket, error) {
rec := m.rec.Record("update_bucket")
updatedBucket, err := m.bucketService.UpdateBucket(ctx, id, upd)
return updatedBucket, rec(err)
}
// Removes a bucket by ID.
func (m *BucketMetrics) DeleteBucket(ctx context.Context, id influxdb.ID) error {
rec := m.rec.Record("delete_bucket")
err := m.bucketService.DeleteBucket(ctx, id)
return rec(err)
}
// FindBucketByName finds a Bucket given its name and Organization ID
func (m *BucketMetrics) FindBucketByName(ctx context.Context, orgID influxdb.ID, name string) (*influxdb.Bucket, error) {
rec := m.rec.Record("find_bucket_by_name")
bucket, err := m.bucketService.FindBucketByName(ctx, orgID, name)
return bucket, rec(err)
}