-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
42 lines (36 loc) · 1.18 KB
/
utils.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
package bprometheus
import (
"net/http"
"github.com/go-masonry/mortar/providers/groups"
"github.com/go-masonry/mortar/providers/types"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.uber.org/fx"
)
// PrometheusInternalHandlerFxOption fx.Provide option that will register Prometheus
// HTTP handler to serve "/metrics" endpoint on internal port
func PrometheusInternalHandlerFxOption() fx.Option {
return fx.Provide(fx.Annotated{
Group: groups.InternalHTTPHandlers,
Target: prometheusHTTPHandlerPatternPair,
})
}
func prometheusHTTPHandlerPatternPair() types.HTTPHandlerPatternPair {
return types.HTTPHandlerPatternPair{
Pattern: "/metrics",
Handler: HTTPHandler(),
}
}
// PrometheusHTTPHandlerPatternPair provides mortar Internal HTTP Pattern Pair
// It can later be registered to serve metrics endpoint on internal port
//
// Call this function to customize your http pattern
func PrometheusHTTPHandlerPatternPair(pattern string) types.HTTPHandlerPatternPair {
return types.HTTPHandlerPatternPair{
Pattern: pattern,
Handler: HTTPHandler(),
}
}
// HTTPHandler provides the Prometheus HTTP scrape handler.
func HTTPHandler() http.Handler {
return promhttp.Handler()
}