-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
middleware_onboarding_metrics.go
44 lines (36 loc) · 1.42 KB
/
middleware_onboarding_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
package tenant
import (
"context"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/metric"
"github.com/prometheus/client_golang/prometheus"
)
var _ influxdb.OnboardingService = (*OnboardingMetrics)(nil)
type OnboardingMetrics struct {
// RED metrics
rec *metric.REDClient
onboardingService influxdb.OnboardingService
}
// NewOnboardingMetrics returns a metrics service middleware for the User Service.
func NewOnboardingMetrics(reg prometheus.Registerer, s influxdb.OnboardingService, opts ...metric.MetricsOption) *OnboardingMetrics {
o := metric.ApplyMetricOpts(opts...)
return &OnboardingMetrics{
rec: metric.New(reg, o.ApplySuffix("onboard")),
onboardingService: s,
}
}
func (m *OnboardingMetrics) IsOnboarding(ctx context.Context) (bool, error) {
rec := m.rec.Record("is_onboarding")
available, err := m.onboardingService.IsOnboarding(ctx)
return available, rec(err)
}
func (m *OnboardingMetrics) OnboardInitialUser(ctx context.Context, req *influxdb.OnboardingRequest) (*influxdb.OnboardingResults, error) {
rec := m.rec.Record("onboard_initial_user")
res, err := m.onboardingService.OnboardInitialUser(ctx, req)
return res, rec(err)
}
func (m *OnboardingMetrics) OnboardUser(ctx context.Context, req *influxdb.OnboardingRequest) (*influxdb.OnboardingResults, error) {
rec := m.rec.Record("onboard_user")
res, err := m.onboardingService.OnboardUser(ctx, req)
return res, rec(err)
}