-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
middleware_org_metrics.go
63 lines (51 loc) · 2.07 KB
/
middleware_org_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
package tenant
import (
"context"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/metric"
"github.com/prometheus/client_golang/prometheus"
)
type OrgMetrics struct {
// RED metrics
rec *metric.REDClient
orgService influxdb.OrganizationService
}
var _ influxdb.OrganizationService = (*OrgMetrics)(nil)
// NewOrgMetrics returns a metrics service middleware for the Organization Service.
func NewOrgMetrics(reg prometheus.Registerer, s influxdb.OrganizationService, opts ...metric.MetricsOption) *OrgMetrics {
o := metric.ApplyMetricOpts(opts...)
return &OrgMetrics{
rec: metric.New(reg, o.ApplySuffix("org")),
orgService: s,
}
}
func (m *OrgMetrics) FindOrganizationByID(ctx context.Context, id influxdb.ID) (*influxdb.Organization, error) {
rec := m.rec.Record("find_org_by_id")
org, err := m.orgService.FindOrganizationByID(ctx, id)
return org, rec(err)
}
func (m *OrgMetrics) FindOrganization(ctx context.Context, filter influxdb.OrganizationFilter) (*influxdb.Organization, error) {
rec := m.rec.Record("find_org")
org, err := m.orgService.FindOrganization(ctx, filter)
return org, rec(err)
}
func (m *OrgMetrics) FindOrganizations(ctx context.Context, filter influxdb.OrganizationFilter, opt ...influxdb.FindOptions) ([]*influxdb.Organization, int, error) {
rec := m.rec.Record("find_orgs")
orgs, n, err := m.orgService.FindOrganizations(ctx, filter, opt...)
return orgs, n, rec(err)
}
func (m *OrgMetrics) CreateOrganization(ctx context.Context, b *influxdb.Organization) error {
rec := m.rec.Record("create_org")
err := m.orgService.CreateOrganization(ctx, b)
return rec(err)
}
func (m *OrgMetrics) UpdateOrganization(ctx context.Context, id influxdb.ID, upd influxdb.OrganizationUpdate) (*influxdb.Organization, error) {
rec := m.rec.Record("update_org")
updatedOrg, err := m.orgService.UpdateOrganization(ctx, id, upd)
return updatedOrg, rec(err)
}
func (m *OrgMetrics) DeleteOrganization(ctx context.Context, id influxdb.ID) error {
rec := m.rec.Record("delete_org")
err := m.orgService.DeleteOrganization(ctx, id)
return rec(err)
}