web: add error counter for federation responses

pull/2259/head
Fabian Reinartz 8 years ago
parent 9d68e81b32
commit cef2e04aa3

@ -18,6 +18,7 @@ import (
"sort" "sort"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go" dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt" "github.com/prometheus/common/expfmt"
"github.com/prometheus/common/log" "github.com/prometheus/common/log"
@ -27,6 +28,13 @@ import (
"github.com/prometheus/prometheus/storage/metric" "github.com/prometheus/prometheus/storage/metric"
) )
var (
federationErrors = prometheus.NewCounter(prometheus.CounterOpts{
Name: "prometheus_web_federation_errors_total",
Help: "Total number of errors that occurred while sending federation responses.",
})
)
func (h *Handler) federation(w http.ResponseWriter, req *http.Request) { func (h *Handler) federation(w http.ResponseWriter, req *http.Request) {
h.mtx.RLock() h.mtx.RLock()
defer h.mtx.RUnlock() defer h.mtx.RUnlock()
@ -52,6 +60,7 @@ func (h *Handler) federation(w http.ResponseWriter, req *http.Request) {
q, err := h.storage.Querier() q, err := h.storage.Querier()
if err != nil { if err != nil {
federationErrors.Inc()
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
@ -59,6 +68,7 @@ func (h *Handler) federation(w http.ResponseWriter, req *http.Request) {
vector, err := q.LastSampleForLabelMatchers(h.context, minTimestamp, matcherSets...) vector, err := q.LastSampleForLabelMatchers(h.context, minTimestamp, matcherSets...)
if err != nil { if err != nil {
federationErrors.Inc()
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
@ -92,6 +102,7 @@ func (h *Handler) federation(w http.ResponseWriter, req *http.Request) {
// creating the new one. // creating the new one.
if protMetricFam != nil { if protMetricFam != nil {
if err := enc.Encode(protMetricFam); err != nil { if err := enc.Encode(protMetricFam); err != nil {
federationErrors.Inc()
log.With("err", err).Error("federation failed") log.With("err", err).Error("federation failed")
return return
} }
@ -133,6 +144,7 @@ func (h *Handler) federation(w http.ResponseWriter, req *http.Request) {
// Still have to ship off the last MetricFamily, if any. // Still have to ship off the last MetricFamily, if any.
if protMetricFam != nil { if protMetricFam != nil {
if err := enc.Encode(protMetricFam); err != nil { if err := enc.Encode(protMetricFam); err != nil {
federationErrors.Inc()
log.With("err", err).Error("federation failed") log.With("err", err).Error("federation failed")
} }
} }

Loading…
Cancel
Save