-
Notifications
You must be signed in to change notification settings - Fork 70
/
metrics.go
43 lines (35 loc) · 1.06 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
package global
import (
"encoding/json"
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
"github.com/caddyserver/ingress/pkg/converter"
"github.com/caddyserver/ingress/pkg/store"
)
type MetricsPlugin struct{}
func (p MetricsPlugin) IngressPlugin() converter.PluginInfo {
return converter.PluginInfo{
Name: "metrics",
New: func() converter.Plugin { return new(MetricsPlugin) },
}
}
func init() {
converter.RegisterPlugin(MetricsPlugin{})
}
func (p MetricsPlugin) GlobalHandler(config *converter.Config, store *store.Store) error {
if store.ConfigMap.Metrics {
metricsRoute := caddyhttp.Route{
HandlersRaw: []json.RawMessage{json.RawMessage(`{ "handler": "metrics" }`)},
MatcherSetsRaw: []caddy.ModuleMap{{
"path": caddyconfig.JSON(caddyhttp.MatchPath{"/metrics"}, nil),
}},
}
config.GetMetricsServer().Routes = append(config.GetMetricsServer().Routes, metricsRoute)
}
return nil
}
// Interface guards
var (
_ = converter.GlobalMiddleware(MetricsPlugin{})
)