Merge pull request #2259 from prometheus/federationerr

web: don't return federation errors over HTTP
This commit is contained in:
Fabian Reinartz 2016-12-06 16:18:03 +01:00 committed by GitHub
commit 9ecea36ef9
1 changed files with 14 additions and 2 deletions

View File

@ -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,7 +102,8 @@ 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 {
http.Error(w, err.Error(), http.StatusInternalServerError) federationErrors.Inc()
log.With("err", err).Error("federation failed")
return return
} }
} }
@ -133,7 +144,8 @@ 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 {
http.Error(w, err.Error(), http.StatusInternalServerError) federationErrors.Inc()
log.With("err", err).Error("federation failed")
} }
} }
} }