Skip to content

Commit

Permalink
filter metrics endpoint for get only
Browse files Browse the repository at this point in the history
  • Loading branch information
Katherine Lin committed Apr 19, 2024
1 parent ef7b7bb commit f52f1f7
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func NewFrontend(logger *slog.Logger, listener net.Listener, emitter metrics.Emi
mux.HandleFunc(MuxPattern(http.MethodGet, "healthz", "ready"), f.HealthzReady)

// Expose Prometheus metrics endpoint
mux.Handle("/metrics", allowGETOnly(promhttp.Handler()))
mux.Handle(MuxPattern(http.MethodGet, "metrics"), promhttp.Handler())

// Authenticated routes
postMuxMiddleware := NewMiddleware(
Expand Down Expand Up @@ -328,14 +328,3 @@ func (f *Frontend) ArmSubscriptionAction(writer http.ResponseWriter, request *ht
f.logger.Error(err.Error())
}
}

// Wrap the Prometheus handler to only allow GET requests
func allowGETOnly(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
return
}
h.ServeHTTP(w, r)
})
}

0 comments on commit f52f1f7

Please sign in to comment.