Added Prometheus metrics, don't forget to restrict access on /metrics endpoint.

This commit is contained in:
2019-05-17 17:12:27 +02:00
parent e794311eb8
commit d5573e7f39
4 changed files with 222 additions and 4 deletions
+8
View File
@@ -10,12 +10,14 @@ import (
"git.aiterp.net/rpdata/api/graph2"
"git.aiterp.net/rpdata/api/internal/auth"
"git.aiterp.net/rpdata/api/internal/instrumentation"
"git.aiterp.net/rpdata/api/internal/loader"
"git.aiterp.net/rpdata/api/internal/store"
"git.aiterp.net/rpdata/api/models"
"git.aiterp.net/rpdata/api/models/changes"
"git.aiterp.net/rpdata/api/models/logs"
"github.com/99designs/gqlgen/handler"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func main() {
@@ -24,9 +26,13 @@ func main() {
log.Fatalln("Failed to init store:", err)
}
instrumentation.Register()
http.Handle("/", handler.Playground("RPData API", "/graphql"))
http.Handle("/graphql", queryHandler())
http.Handle("/metrics", promhttp.Handler())
go func() {
err := logs.RunFullUpdate()
if err != nil {
@@ -81,6 +87,8 @@ func queryHandler() http.HandlerFunc {
return fmt.Errorf("The server failed to serve your request due to an internal error, it has been logged")
}),
handler.ComplexityLimit(300),
handler.RequestMiddleware(instrumentation.RequestMiddleware()),
handler.ResolverMiddleware(instrumentation.ResolverMiddleware()),
)
return func(w http.ResponseWriter, r *http.Request) {