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"
|
2020-04-08 18:58:36 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2020-03-17 17:43:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type UrmMetrics struct {
|
|
|
|
// RED metrics
|
|
|
|
rec *metric.REDClient
|
|
|
|
|
|
|
|
urmService influxdb.UserResourceMappingService
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ influxdb.UserResourceMappingService = (*UrmMetrics)(nil)
|
|
|
|
|
2020-03-17 22:24:57 +00:00
|
|
|
// NewUrmMetrics returns a metrics service middleware for the User Resource Mapping Service.
|
2020-06-15 19:04:15 +00:00
|
|
|
func NewUrmMetrics(reg prometheus.Registerer, s influxdb.UserResourceMappingService, opts ...metric.ClientOptFn) *UrmMetrics {
|
2020-05-21 18:30:19 +00:00
|
|
|
o := metric.ApplyMetricOpts(opts...)
|
2020-03-17 17:43:16 +00:00
|
|
|
return &UrmMetrics{
|
2020-05-21 18:30:19 +00:00
|
|
|
rec: metric.New(reg, o.ApplySuffix("urm")),
|
2020-03-17 17:43:16 +00:00
|
|
|
urmService: s,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *UrmMetrics) FindUserResourceMappings(ctx context.Context, filter influxdb.UserResourceMappingFilter, opt ...influxdb.FindOptions) ([]*influxdb.UserResourceMapping, int, error) {
|
|
|
|
rec := m.rec.Record("find_urms")
|
|
|
|
urms, n, err := m.urmService.FindUserResourceMappings(ctx, filter, opt...)
|
|
|
|
return urms, n, rec(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *UrmMetrics) CreateUserResourceMapping(ctx context.Context, urm *influxdb.UserResourceMapping) error {
|
|
|
|
rec := m.rec.Record("create_urm")
|
|
|
|
err := m.urmService.CreateUserResourceMapping(ctx, urm)
|
|
|
|
return rec(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *UrmMetrics) DeleteUserResourceMapping(ctx context.Context, resourceID, userID influxdb.ID) error {
|
|
|
|
rec := m.rec.Record("delete_urm")
|
|
|
|
err := m.urmService.DeleteUserResourceMapping(ctx, resourceID, userID)
|
|
|
|
return rec(err)
|
|
|
|
}
|