generated from xmidt-org/.go-template
/
metrics.go
81 lines (70 loc) · 2 KB
/
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// SPDX-FileCopyrightText: 2020 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package webhookClient
import (
"github.com/go-kit/kit/metrics"
"github.com/go-kit/kit/metrics/provider"
"github.com/prometheus/client_golang/prometheus"
"github.com/xmidt-org/touchstone/touchkit"
// nolint:staticcheck
"github.com/xmidt-org/webpa-common/v2/xmetrics"
"go.uber.org/fx"
)
// Names for our metrics
const (
WebhookRegistrationOutcome = "webhook_registration"
)
// labels
const (
OutcomeLabel = "outcome"
ReasonLabel = "reason"
)
const (
// outcomes
SuccessOutcome = "success"
FailureOutcome = "failure"
)
// Metrics returns the Metrics relevant to this package
func Metrics() []xmetrics.Metric {
return []xmetrics.Metric{
{
Name: WebhookRegistrationOutcome,
Type: xmetrics.CounterType,
Help: "Counter for the periodic registerer, providing the outcome of a registration attempt",
LabelNames: []string{OutcomeLabel, ReasonLabel},
},
}
}
// Measures describes the defined metrics that will be used by clients.
type Measures struct {
WebhookRegistrationOutcome metrics.Counter
}
// MeasuresIn is an uber/fx parameter with the webhook registration counter
type MeasuresIn struct {
fx.In
WebhookRegistrationOutcome metrics.Counter `name:"webhook_registration"`
}
// NewMeasures realizes desired metrics.
func NewMeasures(p provider.Provider) *Measures {
return &Measures{
WebhookRegistrationOutcome: p.NewCounter(WebhookRegistrationOutcome),
}
}
// ProvideMetrics provides the metrics relevant to this package as uber/fx options.
func ProvideMetrics() fx.Option {
return fx.Options(
touchkit.Counter(
prometheus.CounterOpts{
Name: WebhookRegistrationOutcome,
Help: "Counter for the periodic registerer, providing the outcome of a registration attempt",
}, OutcomeLabel, ReasonLabel,
),
fx.Provide(
func(in MeasuresIn) *Measures {
return &Measures{
WebhookRegistrationOutcome: in.WebhookRegistrationOutcome,
}
},
),
)
}