-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.go
44 lines (37 loc) · 1.18 KB
/
config.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 metricsmiddleware
import (
"github.com/arquivei/foundationkit/metrifier"
)
// Config is used to configure a metrics middleware.
type Config struct {
// Metrifier is the metrifier configuration
Metrifier metrifier.Config
// LabelsDecoder extracts labels from the request, response or error.
// This is optional, can be nil
LabelsDecoder LabelsDecoder
// ExternalMetrics is executed after the main metrifier is called.
// This is intended to calculate custom metrics.
// This is optional, can be nil.
ExternalMetrics ExternalMetrics
}
// WithLabelsDecoder adds a LabelsDecoder to the metrics middleware.
func (c Config) WithLabelsDecoder(d LabelsDecoder) Config {
c.LabelsDecoder = d
c.Metrifier.ExtraLabels = d.Labels()
return c
}
// WithExternalMetrics adds ExternalMetrics to the metrics middleware.
func (c Config) WithExternalMetrics(m ExternalMetrics) Config {
c.ExternalMetrics = m
return c
}
// NewDefaultConfig returns a new Config with sane defaults.
func NewDefaultConfig(endpoint string) Config {
config := Config{
Metrifier: metrifier.NewDefaultConfig("endpoint", ""),
}
config.Metrifier.ConstLabels = map[string]string{
"endpoint": endpoint,
}
return config
}