 a2714ab1f1
			
		
	
	a2714ab1f1
	
	
	
		
			
			web/outpost: make metrics compliant with Prometheus best-practices Today, all NewHistogramVec store values in nanoseconds without changing the default histogram bucket, which are made for seconds, making them a bit useless. In addition, some metrics names are not self-explanatoryand and do not comply with Prometheus best practices. This commit tries to fix all of this "issues". NOTE: I kept old metrics in order to avoid breaking changes with existing dashboards and metrics. Signed-off-by: Alexandre NICOLAIE <xunleii@users.noreply.github.com>
		
			
				
	
	
		
			52 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package metrics
 | |
| 
 | |
| import (
 | |
| 	"net/http"
 | |
| 
 | |
| 	log "github.com/sirupsen/logrus"
 | |
| 	"goauthentik.io/internal/config"
 | |
| 	"goauthentik.io/internal/utils/sentry"
 | |
| 
 | |
| 	"github.com/gorilla/mux"
 | |
| 	"github.com/prometheus/client_golang/prometheus"
 | |
| 	"github.com/prometheus/client_golang/prometheus/promauto"
 | |
| 	"github.com/prometheus/client_golang/prometheus/promhttp"
 | |
| )
 | |
| 
 | |
| var (
 | |
| 	Requests = promauto.NewHistogramVec(prometheus.HistogramOpts{
 | |
| 		Name: "authentik_outpost_proxy_request_duration_seconds",
 | |
| 		Help: "Proxy request latencies in seconds",
 | |
| 	}, []string{"outpost_name", "method", "host", "type"})
 | |
| 	UpstreamTiming = promauto.NewHistogramVec(prometheus.HistogramOpts{
 | |
| 		Name: "authentik_outpost_proxy_upstream_response_duration_seconds",
 | |
| 		Help: "Proxy upstream response latencies in seconds",
 | |
| 	}, []string{"outpost_name", "method", "scheme", "host", "upstream_host"})
 | |
| 
 | |
| 	// NOTE: the following metric is kept for compatibility purpose
 | |
| 	RequestsLegacy = promauto.NewHistogramVec(prometheus.HistogramOpts{
 | |
| 		Name: "authentik_outpost_proxy_requests",
 | |
| 		Help: "The total number of configured providers",
 | |
| 	}, []string{"outpost_name", "method", "host", "type"})
 | |
| 	UpstreamTimingLegacy = promauto.NewHistogramVec(prometheus.HistogramOpts{
 | |
| 		Name: "authentik_outpost_proxy_upstream_time",
 | |
| 		Help: "A summary of the duration we wait for the upstream reply",
 | |
| 	}, []string{"outpost_name", "method", "scheme", "host", "upstream_host"})
 | |
| )
 | |
| 
 | |
| func RunServer() {
 | |
| 	m := mux.NewRouter()
 | |
| 	l := log.WithField("logger", "authentik.outpost.metrics")
 | |
| 	m.Use(sentry.SentryNoSampleMiddleware)
 | |
| 	m.HandleFunc("/outpost.goauthentik.io/ping", func(rw http.ResponseWriter, r *http.Request) {
 | |
| 		rw.WriteHeader(204)
 | |
| 	})
 | |
| 	m.Path("/metrics").Handler(promhttp.Handler())
 | |
| 	listen := config.Get().Listen.Metrics
 | |
| 	l.WithField("listen", listen).Info("Starting Metrics server")
 | |
| 	err := http.ListenAndServe(listen, m)
 | |
| 	if err != nil {
 | |
| 		l.WithError(err).Warning("Failed to start metrics listener")
 | |
| 	}
 | |
| }
 |