/
metrics.go
59 lines (53 loc) · 1.85 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
package basculemetrics
import (
"github.com/go-kit/kit/metrics"
gokitprometheus "github.com/go-kit/kit/metrics/prometheus"
"github.com/jithin-kg/webpa-common/xmetrics"
)
//Names for our metrics
const (
AuthValidationOutcome = "auth_validation"
NBFHistogram = "auth_from_nbf_seconds"
EXPHistogram = "auth_from_exp_seconds"
)
// labels
const (
OutcomeLabel = "outcome"
)
//Metrics returns the Metrics relevant to this package
func Metrics() []xmetrics.Metric {
return []xmetrics.Metric{
xmetrics.Metric{
Name: AuthValidationOutcome,
Type: xmetrics.CounterType,
Help: "Counter for success and failure reason results through bascule",
LabelNames: []string{OutcomeLabel},
},
xmetrics.Metric{
Name: NBFHistogram,
Type: xmetrics.HistogramType,
Help: "Difference (in seconds) between time of JWT validation and nbf (including leeway)",
Buckets: []float64{-61, -11, -2, -1, 0, 9, 60}, // defines the upper inclusive (<=) bounds
},
xmetrics.Metric{
Name: EXPHistogram,
Type: xmetrics.HistogramType,
Help: "Difference (in seconds) between time of JWT validation and exp (including leeway)",
Buckets: []float64{-61, -11, -2, -1, 0, 9, 60},
},
}
}
//AuthValidationMeasures describes the defined metrics that will be used by clients
type AuthValidationMeasures struct {
NBFHistogram *gokitprometheus.Histogram
ExpHistogram *gokitprometheus.Histogram
ValidationOutcome metrics.Counter
}
//NewAuthValidationMeasures realizes desired metrics
func NewAuthValidationMeasures(r xmetrics.Registry) *AuthValidationMeasures {
return &AuthValidationMeasures{
NBFHistogram: gokitprometheus.NewHistogram(r.NewHistogramVec(NBFHistogram)),
ExpHistogram: gokitprometheus.NewHistogram(r.NewHistogramVec(EXPHistogram)),
ValidationOutcome: r.NewCounter(AuthValidationOutcome),
}
}