Skip to content

Commit

Permalink
chore: add url skipping for telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra authored and moshloop committed May 21, 2024
1 parent f0af45d commit c2481bc
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"fmt"
"net/url"
"strings"
"slices"

"github.com/flanksource/commons/logger"
"github.com/flanksource/config-db/api"
Expand Down Expand Up @@ -47,14 +47,14 @@ var Serve = &cobra.Command{

func serve(ctx context.Context, configFiles []string) {
e := echo.New()
e.Use(otelecho.Middleware("config-db", otelecho.WithSkipper(tracingURLSkipper)))
e.Use(otelecho.Middleware("config-db", otelecho.WithSkipper(telemetryURLSkipper)))

// PostgREST needs to know how it is exposed to create the correct links
db.HTTPEndpoint = publicEndpoint + "/db"

if logger.IsTraceEnabled() {
echoLogConfig := middleware.DefaultLoggerConfig
echoLogConfig.Skipper = tracingURLSkipper
echoLogConfig.Skipper = telemetryURLSkipper
e.Use(middleware.LoggerWithConfig(echoLogConfig))
}

Expand All @@ -77,6 +77,7 @@ func serve(ctx context.Context, configFiles []string) {

e.Use(echoprometheus.NewMiddlewareWithConfig(echoprometheus.MiddlewareConfig{
Registerer: prom.DefaultRegisterer,
Skipper: telemetryURLSkipper,
}))

e.GET("/metrics", echoprometheus.NewHandlerWithConfig(echoprometheus.HandlerConfig{
Expand Down Expand Up @@ -142,13 +143,8 @@ func init() {
ServerFlags(Serve.Flags())
}

// tracingURLSkipper ignores metrics route on some middleware
func tracingURLSkipper(c echo.Context) bool {
pathsToSkip := []string{"/health", "/metrics"}
for _, p := range pathsToSkip {
if strings.HasPrefix(c.Path(), p) {
return true
}
}
return false
// telemetryURLSkipper ignores metrics route on some middleware
func telemetryURLSkipper(c echo.Context) bool {
pathsToSkip := []string{"/live", "/ready", "/metrics"}
return slices.Contains(pathsToSkip, c.Path())
}

0 comments on commit c2481bc

Please sign in to comment.