2020-03-17 17:43:16 +00:00
|
|
|
package tenant
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-04-03 17:39:20 +00:00
|
|
|
"github.com/influxdata/influxdb/v2"
|
|
|
|
"github.com/influxdata/influxdb/v2/kit/metric"
|
2021-09-13 19:12:35 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/kit/platform"
|
2020-04-08 18:58:36 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2020-03-17 17:43:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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.
|
2020-06-15 19:04:15 +00:00
|
|
|
func NewOrgMetrics(reg prometheus.Registerer, s influxdb.OrganizationService, opts ...metric.ClientOptFn) *OrgMetrics {
|
2020-05-21 18:30:19 +00:00
|
|
|
o := metric.ApplyMetricOpts(opts...)
|
2020-03-17 17:43:16 +00:00
|
|
|
return &OrgMetrics{
|
2020-05-21 18:30:19 +00:00
|
|
|
rec: metric.New(reg, o.ApplySuffix("org")),
|
2020-03-17 17:43:16 +00:00
|
|
|
orgService: s,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-30 18:10:02 +00:00
|
|
|
func (m *OrgMetrics) FindOrganizationByID(ctx context.Context, id platform.ID) (*influxdb.Organization, error) {
|
2020-03-17 17:43:16 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2021-03-30 18:10:02 +00:00
|
|
|
func (m *OrgMetrics) UpdateOrganization(ctx context.Context, id platform.ID, upd influxdb.OrganizationUpdate) (*influxdb.Organization, error) {
|
2020-03-17 17:43:16 +00:00
|
|
|
rec := m.rec.Record("update_org")
|
|
|
|
updatedOrg, err := m.orgService.UpdateOrganization(ctx, id, upd)
|
|
|
|
return updatedOrg, rec(err)
|
|
|
|
}
|
|
|
|
|
2021-03-30 18:10:02 +00:00
|
|
|
func (m *OrgMetrics) DeleteOrganization(ctx context.Context, id platform.ID) error {
|
2020-03-17 17:43:16 +00:00
|
|
|
rec := m.rec.Record("delete_org")
|
|
|
|
err := m.orgService.DeleteOrganization(ctx, id)
|
|
|
|
return rec(err)
|
|
|
|
}
|