mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-02 08:31:11 -08:00
If an explicit timestamp is provided, bypass staleness.
This commit is contained in:
parent
a5cf25743c
commit
850ea412ad
|
@ -584,7 +584,10 @@ loop:
|
||||||
sl.refCache[mets] = ref
|
sl.refCache[mets] = ref
|
||||||
str := lset.String()
|
str := lset.String()
|
||||||
sl.lsetCache[ref] = lsetCacheEntry{lset: lset, str: str}
|
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++
|
added++
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
func TestTargetScraperScrapeOK(t *testing.T) {
|
||||||
const (
|
const (
|
||||||
configTimeout = 1500 * time.Millisecond
|
configTimeout = 1500 * time.Millisecond
|
||||||
|
|
Loading…
Reference in a new issue