If an explicit timestamp is provided, bypass staleness.

This commit is contained in:
Brian Brazil 2017-04-28 16:36:36 +01:00
parent a5cf25743c
commit 850ea412ad
2 changed files with 36 additions and 1 deletions

View file

@ -584,7 +584,10 @@ loop:
sl.refCache[mets] = ref
str := lset.String()
sl.lsetCache[ref] = lsetCacheEntry{lset: lset, str: str}
samplesScraped[str] = lset
if tp == nil {
// Bypass staleness logic if there is an explicit timestamp.
samplesScraped[str] = lset
}
}
added++
}

View file

@ -520,6 +520,38 @@ func TestScrapeLoopAppendStaleness(t *testing.T) {
}
func TestScrapeLoopAppendNoStalenessIfTimestamp(t *testing.T) {
app := &collectResultAppender{}
sl := &scrapeLoop{
appender: func() storage.Appender { return app },
reportAppender: func() storage.Appender { return nopAppender{} },
refCache: map[string]uint64{},
lsetCache: map[uint64]lsetCacheEntry{},
}
now := time.Now()
_, _, err := sl.append([]byte("metric_a 1 1000\n"), now)
if err != nil {
t.Fatalf("Unexpected append error: %s", err)
}
_, _, err = sl.append([]byte(""), now.Add(time.Second))
if err != nil {
t.Fatalf("Unexpected append error: %s", err)
}
want := []sample{
{
metric: labels.FromStrings(model.MetricNameLabel, "metric_a"),
t: 1000,
v: 1,
},
}
if !reflect.DeepEqual(want, app.result) {
t.Fatalf("Appended samples not as expected. Wanted: %+v Got: %+v", want, app.result)
}
}
func TestTargetScraperScrapeOK(t *testing.T) {
const (
configTimeout = 1500 * time.Millisecond