Commit 37b44ff7 authored by Matthew Slipper's avatar Matthew Slipper

Add proxy method metrics

parent 708c9410
This diff is collapsed.
......@@ -8,8 +8,8 @@ import (
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/rs/cors"
"io"
"github.com/rs/cors"
"io"
"io/ioutil"
"net/http"
"time"
......@@ -22,17 +22,11 @@ var (
Help: "Count of total HTTP requests.",
})
httpRequestDurationHisto = promauto.NewHistogram(prometheus.HistogramOpts{
Namespace: "proxyd",
Name: "http_request_duration_histogram_seconds",
Help: "Histogram of HTTP request durations.",
Buckets: []float64{
0,
0.1,
0.25,
0.75,
1,
},
httpRequestDurationSummary = promauto.NewSummary(prometheus.SummaryOpts{
Namespace: "proxyd",
Name: "http_request_duration_seconds",
Help: "Summary of HTTP request durations, in seconds.",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.95: 0.005, 0.99: 0.001},
})
rpcRequestsCtr = promauto.NewCounterVec(prometheus.CounterOpts{
......@@ -96,8 +90,8 @@ func (s *Server) ListenAndServe(host string, port int) error {
hdlr.HandleFunc("/healthz", s.HandleHealthz).Methods("GET")
hdlr.HandleFunc("/", s.HandleRPC).Methods("POST")
c := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
})
AllowedOrigins: []string{"*"},
})
addr := fmt.Sprintf("%s:%d", host, port)
server := &http.Server{
Handler: instrumentedHdlr(c.Handler(hdlr)),
......@@ -142,7 +136,7 @@ func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request) {
return
}
backendRes, err := group.Forward(body)
backendRes, err := group.Forward(req)
if err != nil {
log.Error("error forwarding RPC request", "group", group.Name, "method", req.Method, "err", err)
rpcErrorsCtr.WithLabelValues("-32603").Inc()
......@@ -184,6 +178,6 @@ func instrumentedHdlr(h http.Handler) http.HandlerFunc {
start := time.Now()
h.ServeHTTP(w, r)
dur := time.Since(start)
httpRequestDurationHisto.Observe(float64(dur) / float64(time.Second))
httpRequestDurationSummary.Observe(float64(dur) / float64(time.Second))
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment