-
Notifications
You must be signed in to change notification settings - Fork 0
/
reporter.go
49 lines (39 loc) · 1.08 KB
/
reporter.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
package prometheus
import (
"github.com/pubgo/funk/assert"
"github.com/pubgo/funk/log"
tally "github.com/uber-go/tally/v4"
"github.com/uber-go/tally/v4/prometheus"
"github.com/pubgo/lava/core/debug"
"github.com/pubgo/lava/core/metrics"
)
const (
Name = "prometheus"
urlPath = "/metrics"
)
func init() {
metrics.Register(Name, New)
}
func New(conf *metrics.Config, log log.Logger) *tally.ScopeOptions {
if conf.Driver != Name {
return nil
}
opts := tally.ScopeOptions{}
opts.Separator = prometheus.DefaultSeparator
// opts.SanitizeOptions = &prometheus.DefaultSanitizerOpts
proCfg := &prometheus.Configuration{TimerType: "histogram"}
if conf.DriverCfg != nil {
assert.Must(conf.DriverCfg.Decode(proCfg))
}
logs := log.WithName(metrics.Name).WithName(Name)
reporter := assert.Must1(proCfg.NewReporter(
prometheus.ConfigurationOptions{
OnError: func(err error) {
logs.Err(err).Any("metric-config", conf).Msg("metric.prometheus init error")
},
},
))
debug.Get(urlPath, debug.Wrap(reporter.HTTPHandler()))
opts.CachedReporter = reporter
return &opts
}