From b35e25a08229e52bb75152b327147eb81c5a0737 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Wed, 16 Dec 2015 13:45:44 +0100 Subject: [PATCH] Don't federate stale samples --- web/federate.go | 11 +++++++---- web/ui/bindata.go | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/web/federate.go b/web/federate.go index d935421a7..81f39302e 100644 --- a/web/federate.go +++ b/web/federate.go @@ -46,11 +46,13 @@ func (h *Handler) federation(w http.ResponseWriter, req *http.Request) { } } - format := expfmt.Negotiate(req.Header) + var ( + minTimestamp = model.Now().Add(-promql.StalenessDelta) + format = expfmt.Negotiate(req.Header) + enc = expfmt.NewEncoder(w, format) + ) w.Header().Set("Content-Type", string(format)) - enc := expfmt.NewEncoder(w, format) - protMetric := &dto.Metric{ Label: []*dto.LabelPair{}, Untyped: &dto.Untyped{}, @@ -64,7 +66,8 @@ func (h *Handler) federation(w http.ResponseWriter, req *http.Request) { globalUsed := map[model.LabelName]struct{}{} sp := h.storage.LastSamplePairForFingerprint(fp) - if sp == nil { + // Discard if sample does not exist or lays before the staleness interval. + if sp == nil || sp.Timestamp.Before(minTimestamp) { continue } diff --git a/web/ui/bindata.go b/web/ui/bindata.go index 956ded2b3..6ab2b970f 100644 --- a/web/ui/bindata.go +++ b/web/ui/bindata.go @@ -134,7 +134,7 @@ func webUiTemplatesAlertsHtml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "web/ui/templates/alerts.html", size: 1707, mode: os.FileMode(420), modTime: time.Unix(1448976906, 0)} + info := bindataFileInfo{name: "web/ui/templates/alerts.html", size: 1707, mode: os.FileMode(420), modTime: time.Unix(1450269200, 0)} a := &asset{bytes: bytes, info: info} return a, nil }