Skip to content

Commit

Permalink
improvement: remove usage of deprecated echo prometheus integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiebens committed Feb 12, 2024
1 parent 41b64ee commit 84d29fd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
5 changes: 0 additions & 5 deletions internal/server/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package server

import (
"fmt"
"github.com/labstack/echo-contrib/prometheus"
"github.com/labstack/echo/v4"
"go.uber.org/zap"
"net/http"
Expand Down Expand Up @@ -73,7 +72,3 @@ func EchoRecover() echo.MiddlewareFunc {
}
}
}

func EchoMetrics(p *prometheus.Prometheus) echo.MiddlewareFunc {
return p.HandlerFunc
}
12 changes: 6 additions & 6 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/jsiebens/ionscale/internal/handlers"
"github.com/jsiebens/ionscale/internal/service"
"github.com/jsiebens/ionscale/internal/templates"
echo_prometheus "github.com/labstack/echo-contrib/prometheus"
"github.com/labstack/echo-contrib/echoprometheus"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
certmagicsql "github.com/travisjeffery/certmagic-sqlstorage"
Expand Down Expand Up @@ -104,10 +104,10 @@ func Start(ctx context.Context, c *config.Config) error {
return logError(err)
}

p := echo_prometheus.NewPrometheus("http", nil)
promMiddleware := echoprometheus.NewMiddleware("http")

metricsHandler := echo.New()
p.SetMetricsPath(metricsHandler)
metricsHandler.GET("/metrics", echoprometheus.NewHandler())

createPeerHandler := func(machinePublicKey key.MachinePublic) http.Handler {
registrationHandlers := handlers.NewRegistrationHandlers(machinePublicKey, c, sessionManager, repository)
Expand All @@ -119,7 +119,7 @@ func Start(ctx context.Context, c *config.Config) error {

e := echo.New()
e.Binder = handlers.JsonBinder{}
e.Use(EchoMetrics(p), EchoLogger(httpLogger), EchoErrorHandler(), EchoRecover())
e.Use(promMiddleware, EchoLogger(httpLogger), EchoErrorHandler(), EchoRecover())
e.POST("/machine/register", registrationHandlers.Register)
e.POST("/machine/map", pollNetMapHandler.PollNetMap)
e.POST("/machine/set-dns", dnsHandlers.SetDNS)
Expand All @@ -146,14 +146,14 @@ func Start(ctx context.Context, c *config.Config) error {
rpcPath, rpcHandler := NewRpcHandler(serverKey.SystemAdminKey, repository, rpcService)

nonTlsAppHandler := echo.New()
nonTlsAppHandler.Use(EchoMetrics(p), EchoLogger(httpLogger), EchoErrorHandler(), EchoRecover())
nonTlsAppHandler.Use(promMiddleware, EchoLogger(httpLogger), EchoErrorHandler(), EchoRecover())
nonTlsAppHandler.POST("/ts2021", noiseHandlers.Upgrade)
nonTlsAppHandler.Any("/*", handlers.HttpRedirectHandler(c.Tls))

tlsAppHandler := echo.New()
tlsAppHandler.Renderer = &templates.Renderer{}
tlsAppHandler.Pre(handlers.HttpsRedirect(c.Tls))
tlsAppHandler.Use(EchoMetrics(p), EchoLogger(httpLogger), EchoErrorHandler(), EchoRecover())
tlsAppHandler.Use(promMiddleware, EchoLogger(httpLogger), EchoErrorHandler(), EchoRecover())

tlsAppHandler.Any("/*", handlers.IndexHandler(http.StatusNotFound))
tlsAppHandler.Any("/", handlers.IndexHandler(http.StatusOK))
Expand Down

0 comments on commit 84d29fd

Please sign in to comment.