|
|
@ -650,6 +650,7 @@ func TestScrapeLoopStopBeforeRun(t *testing.T) {
|
|
|
|
nopMutator,
|
|
|
|
nopMutator,
|
|
|
|
nil, nil, 0,
|
|
|
|
nil, nil, 0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
1,
|
|
|
|
1,
|
|
|
@ -724,6 +725,7 @@ func TestScrapeLoopStop(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
10*time.Millisecond,
|
|
|
|
10*time.Millisecond,
|
|
|
@ -802,6 +804,7 @@ func TestScrapeLoopRun(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
time.Second,
|
|
|
|
time.Second,
|
|
|
@ -859,6 +862,7 @@ func TestScrapeLoopRun(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
time.Second,
|
|
|
|
time.Second,
|
|
|
@ -920,6 +924,7 @@ func TestScrapeLoopForcedErr(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
time.Second,
|
|
|
|
time.Second,
|
|
|
@ -980,6 +985,7 @@ func TestScrapeLoopMetadata(t *testing.T) {
|
|
|
|
cache,
|
|
|
|
cache,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
@ -1039,6 +1045,7 @@ func simpleTestScrapeLoop(t testing.TB) (context.Context, *scrapeLoop) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
@ -1101,6 +1108,7 @@ func TestScrapeLoopFailWithInvalidLabelsAfterRelabel(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
@ -1181,6 +1189,7 @@ func TestScrapeLoopRunCreatesStaleMarkersOnFailedScrape(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
10*time.Millisecond,
|
|
|
|
10*time.Millisecond,
|
|
|
@ -1246,6 +1255,7 @@ func TestScrapeLoopRunCreatesStaleMarkersOnParseFailure(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
10*time.Millisecond,
|
|
|
|
10*time.Millisecond,
|
|
|
@ -1314,6 +1324,7 @@ func TestScrapeLoopCache(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
10*time.Millisecond,
|
|
|
|
10*time.Millisecond,
|
|
|
@ -1399,6 +1410,7 @@ func TestScrapeLoopCacheMemoryExhaustionProtection(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
10*time.Millisecond,
|
|
|
|
10*time.Millisecond,
|
|
|
@ -1515,6 +1527,7 @@ func TestScrapeLoopAppend(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
@ -1613,7 +1626,7 @@ func TestScrapeLoopAppendForConflictingPrefixedLabels(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
func(ctx context.Context) storage.Appender { return app },
|
|
|
|
func(ctx context.Context) storage.Appender { return app },
|
|
|
|
nil, 0, true, 0, 0, nil, 0, 0, false, false, false, nil, false, newTestScrapeMetrics(t),
|
|
|
|
nil, 0, true, false, 0, 0, nil, 0, 0, false, false, false, nil, false, newTestScrapeMetrics(t),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
slApp := sl.appender(context.Background())
|
|
|
|
slApp := sl.appender(context.Background())
|
|
|
|
_, _, _, err := sl.append(slApp, []byte(tc.exposedLabels), "", time.Date(2000, 1, 1, 1, 0, 0, 0, time.UTC))
|
|
|
|
_, _, _, err := sl.append(slApp, []byte(tc.exposedLabels), "", time.Date(2000, 1, 1, 1, 0, 0, 0, time.UTC))
|
|
|
@ -1644,6 +1657,7 @@ func TestScrapeLoopAppendCacheEntryButErrNotFound(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
@ -1704,6 +1718,7 @@ func TestScrapeLoopAppendSampleLimit(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
app.limit, 0,
|
|
|
|
app.limit, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
@ -1783,6 +1798,7 @@ func TestScrapeLoop_HistogramBucketLimit(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
app.limit, 0,
|
|
|
|
app.limit, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
@ -1883,6 +1899,7 @@ func TestScrapeLoop_ChangingMetricString(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
@ -1933,6 +1950,7 @@ func TestScrapeLoopAppendStaleness(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
@ -1986,6 +2004,7 @@ func TestScrapeLoopAppendNoStalenessIfTimestamp(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
@ -2313,6 +2332,7 @@ metric: <
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
@ -2402,6 +2422,7 @@ func TestScrapeLoopAppendExemplarSeries(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
@ -2456,6 +2477,7 @@ func TestScrapeLoopRunReportsTargetDownOnScrapeError(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
10*time.Millisecond,
|
|
|
|
10*time.Millisecond,
|
|
|
@ -2494,6 +2516,7 @@ func TestScrapeLoopRunReportsTargetDownOnInvalidUTF8(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
10*time.Millisecond,
|
|
|
|
10*time.Millisecond,
|
|
|
@ -2545,6 +2568,7 @@ func TestScrapeLoopAppendGracefullyIfAmendOrOutOfOrderOrOutOfBounds(t *testing.T
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
@ -2592,6 +2616,7 @@ func TestScrapeLoopOutOfBoundsTimeError(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
@ -2883,6 +2908,7 @@ func TestScrapeLoop_RespectTimestamps(t *testing.T) {
|
|
|
|
func(ctx context.Context) storage.Appender { return capp },
|
|
|
|
func(ctx context.Context) storage.Appender { return capp },
|
|
|
|
nil, 0,
|
|
|
|
nil, 0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
@ -2926,6 +2952,7 @@ func TestScrapeLoop_DiscardTimestamps(t *testing.T) {
|
|
|
|
func(ctx context.Context) storage.Appender { return capp },
|
|
|
|
func(ctx context.Context) storage.Appender { return capp },
|
|
|
|
nil, 0,
|
|
|
|
nil, 0,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
@ -2968,6 +2995,7 @@ func TestScrapeLoopDiscardDuplicateLabels(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
@ -3028,6 +3056,7 @@ func TestScrapeLoopDiscardUnnamedMetrics(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
@ -3293,6 +3322,7 @@ func TestScrapeAddFast(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
@ -3381,6 +3411,7 @@ func TestScrapeReportSingleAppender(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
10*time.Millisecond,
|
|
|
|
10*time.Millisecond,
|
|
|
@ -3585,6 +3616,7 @@ func TestScrapeLoopLabelLimit(t *testing.T) {
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
|
|
|
|
false,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
&test.labelLimits,
|
|
|
|
&test.labelLimits,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
@ -3646,3 +3678,68 @@ func TestTargetScrapeIntervalAndTimeoutRelabel(t *testing.T) {
|
|
|
|
require.Equal(t, "3s", sp.ActiveTargets()[0].labels.Get(model.ScrapeIntervalLabel))
|
|
|
|
require.Equal(t, "3s", sp.ActiveTargets()[0].labels.Get(model.ScrapeIntervalLabel))
|
|
|
|
require.Equal(t, "750ms", sp.ActiveTargets()[0].labels.Get(model.ScrapeTimeoutLabel))
|
|
|
|
require.Equal(t, "750ms", sp.ActiveTargets()[0].labels.Get(model.ScrapeTimeoutLabel))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestScrapeLoopRunCreatesStaleMarkersOnFailedScrapeForTimestampedMetrics(t *testing.T) {
|
|
|
|
|
|
|
|
appender := &collectResultAppender{}
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
|
|
|
signal = make(chan struct{}, 1)
|
|
|
|
|
|
|
|
scraper = &testScraper{}
|
|
|
|
|
|
|
|
app = func(ctx context.Context) storage.Appender { return appender }
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
|
|
|
|
sl := newScrapeLoop(ctx,
|
|
|
|
|
|
|
|
scraper,
|
|
|
|
|
|
|
|
nil, nil,
|
|
|
|
|
|
|
|
nopMutator,
|
|
|
|
|
|
|
|
nopMutator,
|
|
|
|
|
|
|
|
app,
|
|
|
|
|
|
|
|
nil,
|
|
|
|
|
|
|
|
0,
|
|
|
|
|
|
|
|
true,
|
|
|
|
|
|
|
|
true,
|
|
|
|
|
|
|
|
0, 0,
|
|
|
|
|
|
|
|
nil,
|
|
|
|
|
|
|
|
10*time.Millisecond,
|
|
|
|
|
|
|
|
time.Hour,
|
|
|
|
|
|
|
|
false,
|
|
|
|
|
|
|
|
false,
|
|
|
|
|
|
|
|
false,
|
|
|
|
|
|
|
|
nil,
|
|
|
|
|
|
|
|
false,
|
|
|
|
|
|
|
|
newTestScrapeMetrics(t),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
// Succeed once, several failures, then stop.
|
|
|
|
|
|
|
|
numScrapes := 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scraper.scrapeFunc = func(ctx context.Context, w io.Writer) error {
|
|
|
|
|
|
|
|
numScrapes++
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch numScrapes {
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
w.Write([]byte(fmt.Sprintf("metric_a 42 %d\n", time.Now().UnixNano()/int64(time.Millisecond))))
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
|
|
|
|
cancel()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors.New("scrape failed")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
|
|
|
sl.run(nil)
|
|
|
|
|
|
|
|
signal <- struct{}{}
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
select {
|
|
|
|
|
|
|
|
case <-signal:
|
|
|
|
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
|
|
|
|
t.Fatalf("Scrape wasn't stopped.")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 1 successfully scraped sample, 1 stale marker after first fail, 5 report samples for
|
|
|
|
|
|
|
|
// each scrape successful or not.
|
|
|
|
|
|
|
|
require.Equal(t, 27, len(appender.resultFloats), "Appended samples not as expected:\n%s", appender)
|
|
|
|
|
|
|
|
require.Equal(t, 42.0, appender.resultFloats[0].f, "Appended first sample not as expected")
|
|
|
|
|
|
|
|
require.True(t, value.IsStaleNaN(appender.resultFloats[6].f),
|
|
|
|
|
|
|
|
"Appended second sample not as expected. Wanted: stale NaN Got: %x", math.Float64bits(appender.resultFloats[6].f))
|
|
|
|
|
|
|
|
}
|
|
|
|