forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware_metrics.go
55 lines (45 loc) · 1.8 KB
/
middleware_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
package notebooks
import (
"context"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/metric"
"github.com/influxdata/influxdb/v2/kit/platform"
"github.com/prometheus/client_golang/prometheus"
)
func NewMetricCollectingService(reg prometheus.Registerer, underlying influxdb.NotebookService, opts ...metric.ClientOptFn) *metricsService {
o := metric.ApplyMetricOpts(opts...)
return &metricsService{
rec: metric.New(reg, o.ApplySuffix("notebook")),
underlying: underlying,
}
}
type metricsService struct {
// RED metrics
rec *metric.REDClient
underlying influxdb.NotebookService
}
var _ influxdb.NotebookService = (*metricsService)(nil)
func (m metricsService) GetNotebook(ctx context.Context, id platform.ID) (*influxdb.Notebook, error) {
rec := m.rec.Record("find_notebook_by_id")
nb, err := m.underlying.GetNotebook(ctx, id)
return nb, rec(err)
}
func (m metricsService) CreateNotebook(ctx context.Context, create *influxdb.NotebookReqBody) (*influxdb.Notebook, error) {
rec := m.rec.Record("create_notebook")
nb, err := m.underlying.CreateNotebook(ctx, create)
return nb, rec(err)
}
func (m metricsService) UpdateNotebook(ctx context.Context, id platform.ID, update *influxdb.NotebookReqBody) (*influxdb.Notebook, error) {
rec := m.rec.Record("update_notebook")
nb, err := m.underlying.UpdateNotebook(ctx, id, update)
return nb, rec(err)
}
func (m metricsService) DeleteNotebook(ctx context.Context, id platform.ID) (err error) {
rec := m.rec.Record("delete_notebook")
return rec(m.underlying.DeleteNotebook(ctx, id))
}
func (m metricsService) ListNotebooks(ctx context.Context, filter influxdb.NotebookListFilter) ([]*influxdb.Notebook, error) {
rec := m.rec.Record("find_notebooks")
nbs, err := m.underlying.ListNotebooks(ctx, filter)
return nbs, rec(err)
}