|
|
|
@ -300,6 +300,7 @@ func TestScrapePoolReload(t *testing.T) {
|
|
|
|
|
func TestScrapePoolAppender(t *testing.T) { |
|
|
|
|
cfg := &config.ScrapeConfig{} |
|
|
|
|
app := &nopAppendable{} |
|
|
|
|
ctx := context.Background() |
|
|
|
|
sp, _ := newScrapePool(cfg, app, 0, nil) |
|
|
|
|
|
|
|
|
|
loop := sp.newLoop(scrapeLoopOptions{ |
|
|
|
@ -308,7 +309,7 @@ func TestScrapePoolAppender(t *testing.T) {
|
|
|
|
|
appl, ok := loop.(*scrapeLoop) |
|
|
|
|
testutil.Assert(t, ok, "Expected scrapeLoop but got %T", loop) |
|
|
|
|
|
|
|
|
|
wrapped := appl.appender() |
|
|
|
|
wrapped := appl.appender(ctx) |
|
|
|
|
|
|
|
|
|
tl, ok := wrapped.(*timeLimitAppender) |
|
|
|
|
testutil.Assert(t, ok, "Expected timeLimitAppender but got %T", wrapped) |
|
|
|
@ -323,7 +324,7 @@ func TestScrapePoolAppender(t *testing.T) {
|
|
|
|
|
appl, ok = loop.(*scrapeLoop) |
|
|
|
|
testutil.Assert(t, ok, "Expected scrapeLoop but got %T", loop) |
|
|
|
|
|
|
|
|
|
wrapped = appl.appender() |
|
|
|
|
wrapped = appl.appender(ctx) |
|
|
|
|
|
|
|
|
|
sl, ok := wrapped.(*limitAppender) |
|
|
|
|
testutil.Assert(t, ok, "Expected limitAppender but got %T", wrapped) |
|
|
|
@ -374,8 +375,9 @@ func TestScrapePoolRaces(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
func TestScrapeLoopStopBeforeRun(t *testing.T) { |
|
|
|
|
scraper := &testScraper{} |
|
|
|
|
ctx := context.Background() |
|
|
|
|
|
|
|
|
|
sl := newScrapeLoop(context.Background(), |
|
|
|
|
sl := newScrapeLoop(ctx, |
|
|
|
|
scraper, |
|
|
|
|
nil, nil, |
|
|
|
|
nopMutator, |
|
|
|
@ -434,10 +436,11 @@ func TestScrapeLoopStop(t *testing.T) {
|
|
|
|
|
signal = make(chan struct{}, 1) |
|
|
|
|
appender = &collectResultAppender{} |
|
|
|
|
scraper = &testScraper{} |
|
|
|
|
app = func() storage.Appender { return appender } |
|
|
|
|
app = func(ctx context.Context) storage.Appender { return appender } |
|
|
|
|
) |
|
|
|
|
ctx := context.Background() |
|
|
|
|
|
|
|
|
|
sl := newScrapeLoop(context.Background(), |
|
|
|
|
sl := newScrapeLoop(ctx, |
|
|
|
|
scraper, |
|
|
|
|
nil, nil, |
|
|
|
|
nopMutator, |
|
|
|
@ -499,7 +502,7 @@ func TestScrapeLoopRun(t *testing.T) {
|
|
|
|
|
errc = make(chan error) |
|
|
|
|
|
|
|
|
|
scraper = &testScraper{} |
|
|
|
|
app = func() storage.Appender { return &nopAppender{} } |
|
|
|
|
app = func(ctx context.Context) storage.Appender { return &nopAppender{} } |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
@ -605,14 +608,14 @@ func TestScrapeLoopMetadata(t *testing.T) {
|
|
|
|
|
nil, nil, |
|
|
|
|
nopMutator, |
|
|
|
|
nopMutator, |
|
|
|
|
func() storage.Appender { return nopAppender{} }, |
|
|
|
|
func(ctx context.Context) storage.Appender { return nopAppender{} }, |
|
|
|
|
cache, |
|
|
|
|
0, |
|
|
|
|
true, |
|
|
|
|
) |
|
|
|
|
defer cancel() |
|
|
|
|
|
|
|
|
|
slApp := sl.appender() |
|
|
|
|
slApp := sl.appender(ctx) |
|
|
|
|
total, _, _, err := sl.append(slApp, []byte(`# TYPE test_metric counter |
|
|
|
|
# HELP test_metric some help text |
|
|
|
|
# UNIT test_metric metric |
|
|
|
@ -661,7 +664,7 @@ func TestScrapeLoopSeriesAdded(t *testing.T) {
|
|
|
|
|
) |
|
|
|
|
defer cancel() |
|
|
|
|
|
|
|
|
|
slApp := sl.appender() |
|
|
|
|
slApp := sl.appender(ctx) |
|
|
|
|
total, added, seriesAdded, err := sl.append(slApp, []byte("test_metric 1\n"), "", time.Time{}) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, slApp.Commit()) |
|
|
|
@ -669,7 +672,7 @@ func TestScrapeLoopSeriesAdded(t *testing.T) {
|
|
|
|
|
testutil.Equals(t, 1, added) |
|
|
|
|
testutil.Equals(t, 1, seriesAdded) |
|
|
|
|
|
|
|
|
|
slApp = sl.appender() |
|
|
|
|
slApp = sl.appender(ctx) |
|
|
|
|
total, added, seriesAdded, err = sl.append(slApp, []byte("test_metric 1\n"), "", time.Time{}) |
|
|
|
|
testutil.Ok(t, slApp.Commit()) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
@ -683,7 +686,7 @@ func TestScrapeLoopRunCreatesStaleMarkersOnFailedScrape(t *testing.T) {
|
|
|
|
|
var ( |
|
|
|
|
signal = make(chan struct{}, 1) |
|
|
|
|
scraper = &testScraper{} |
|
|
|
|
app = func() storage.Appender { return appender } |
|
|
|
|
app = func(ctx context.Context) storage.Appender { return appender } |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
@ -736,7 +739,7 @@ func TestScrapeLoopRunCreatesStaleMarkersOnParseFailure(t *testing.T) {
|
|
|
|
|
var ( |
|
|
|
|
signal = make(chan struct{}, 1) |
|
|
|
|
scraper = &testScraper{} |
|
|
|
|
app = func() storage.Appender { return appender } |
|
|
|
|
app = func(ctx context.Context) storage.Appender { return appender } |
|
|
|
|
numScrapes = 0 |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -795,7 +798,7 @@ func TestScrapeLoopCache(t *testing.T) {
|
|
|
|
|
var ( |
|
|
|
|
signal = make(chan struct{}, 1) |
|
|
|
|
scraper = &testScraper{} |
|
|
|
|
app = func() storage.Appender { appender.next = s.Appender(); return appender } |
|
|
|
|
app = func(ctx context.Context) storage.Appender { appender.next = s.Appender(ctx); return appender } |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
@ -863,13 +866,13 @@ func TestScrapeLoopCacheMemoryExhaustionProtection(t *testing.T) {
|
|
|
|
|
s := teststorage.New(t) |
|
|
|
|
defer s.Close() |
|
|
|
|
|
|
|
|
|
sapp := s.Appender() |
|
|
|
|
sapp := s.Appender(context.Background()) |
|
|
|
|
|
|
|
|
|
appender := &collectResultAppender{next: sapp} |
|
|
|
|
var ( |
|
|
|
|
signal = make(chan struct{}, 1) |
|
|
|
|
scraper = &testScraper{} |
|
|
|
|
app = func() storage.Appender { return appender } |
|
|
|
|
app = func(ctx context.Context) storage.Appender { return appender } |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
@ -975,8 +978,9 @@ func TestScrapeLoopAppend(t *testing.T) {
|
|
|
|
|
discoveryLabels := &Target{ |
|
|
|
|
labels: labels.FromStrings(test.discoveryLabels...), |
|
|
|
|
} |
|
|
|
|
ctx := context.Background() |
|
|
|
|
|
|
|
|
|
sl := newScrapeLoop(context.Background(), |
|
|
|
|
sl := newScrapeLoop(ctx, |
|
|
|
|
nil, nil, nil, |
|
|
|
|
func(l labels.Labels) labels.Labels { |
|
|
|
|
return mutateSampleLabels(l, discoveryLabels, test.honorLabels, nil) |
|
|
|
@ -984,7 +988,7 @@ func TestScrapeLoopAppend(t *testing.T) {
|
|
|
|
|
func(l labels.Labels) labels.Labels { |
|
|
|
|
return mutateReportSampleLabels(l, discoveryLabels) |
|
|
|
|
}, |
|
|
|
|
func() storage.Appender { return app }, |
|
|
|
|
func(ctx context.Context) storage.Appender { return app }, |
|
|
|
|
nil, |
|
|
|
|
0, |
|
|
|
|
true, |
|
|
|
@ -992,7 +996,7 @@ func TestScrapeLoopAppend(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
now := time.Now() |
|
|
|
|
|
|
|
|
|
slApp := sl.appender() |
|
|
|
|
slApp := sl.appender(ctx) |
|
|
|
|
_, _, _, err := sl.append(slApp, []byte(test.scrapeLabels), "", now) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, slApp.Commit()) |
|
|
|
@ -1020,12 +1024,13 @@ func TestScrapeLoopAppend(t *testing.T) {
|
|
|
|
|
func TestScrapeLoopAppendCacheEntryButErrNotFound(t *testing.T) { |
|
|
|
|
// collectResultAppender's AddFast always returns ErrNotFound if we don't give it a next.
|
|
|
|
|
app := &collectResultAppender{} |
|
|
|
|
ctx := context.Background() |
|
|
|
|
|
|
|
|
|
sl := newScrapeLoop(context.Background(), |
|
|
|
|
sl := newScrapeLoop(ctx, |
|
|
|
|
nil, nil, nil, |
|
|
|
|
nopMutator, |
|
|
|
|
nopMutator, |
|
|
|
|
func() storage.Appender { return app }, |
|
|
|
|
func(ctx context.Context) storage.Appender { return app }, |
|
|
|
|
nil, |
|
|
|
|
0, |
|
|
|
|
true, |
|
|
|
@ -1045,7 +1050,7 @@ func TestScrapeLoopAppendCacheEntryButErrNotFound(t *testing.T) {
|
|
|
|
|
sl.cache.addRef(mets, fakeRef, lset, hash) |
|
|
|
|
now := time.Now() |
|
|
|
|
|
|
|
|
|
slApp := sl.appender() |
|
|
|
|
slApp := sl.appender(ctx) |
|
|
|
|
_, _, _, err := sl.append(slApp, []byte(metric), "", now) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, slApp.Commit()) |
|
|
|
@ -1064,8 +1069,9 @@ func TestScrapeLoopAppendCacheEntryButErrNotFound(t *testing.T) {
|
|
|
|
|
func TestScrapeLoopAppendSampleLimit(t *testing.T) { |
|
|
|
|
resApp := &collectResultAppender{} |
|
|
|
|
app := &limitAppender{Appender: resApp, limit: 1} |
|
|
|
|
ctx := context.Background() |
|
|
|
|
|
|
|
|
|
sl := newScrapeLoop(context.Background(), |
|
|
|
|
sl := newScrapeLoop(ctx, |
|
|
|
|
nil, nil, nil, |
|
|
|
|
func(l labels.Labels) labels.Labels { |
|
|
|
|
if l.Has("deleteme") { |
|
|
|
@ -1074,7 +1080,7 @@ func TestScrapeLoopAppendSampleLimit(t *testing.T) {
|
|
|
|
|
return l |
|
|
|
|
}, |
|
|
|
|
nopMutator, |
|
|
|
|
func() storage.Appender { return app }, |
|
|
|
|
func(ctx context.Context) storage.Appender { return app }, |
|
|
|
|
nil, |
|
|
|
|
0, |
|
|
|
|
true, |
|
|
|
@ -1088,7 +1094,7 @@ func TestScrapeLoopAppendSampleLimit(t *testing.T) {
|
|
|
|
|
beforeMetricValue := beforeMetric.GetCounter().GetValue() |
|
|
|
|
|
|
|
|
|
now := time.Now() |
|
|
|
|
slApp := sl.appender() |
|
|
|
|
slApp := sl.appender(ctx) |
|
|
|
|
total, added, seriesAdded, err := sl.append(app, []byte("metric_a 1\nmetric_b 1\nmetric_c 1\n"), "", now) |
|
|
|
|
if err != errSampleLimit { |
|
|
|
|
t.Fatalf("Did not see expected sample limit error: %s", err) |
|
|
|
@ -1119,7 +1125,7 @@ func TestScrapeLoopAppendSampleLimit(t *testing.T) {
|
|
|
|
|
testutil.Equals(t, want, resApp.rolledbackResult, "Appended samples not as expected") |
|
|
|
|
|
|
|
|
|
now = time.Now() |
|
|
|
|
slApp = sl.appender() |
|
|
|
|
slApp = sl.appender(ctx) |
|
|
|
|
total, added, seriesAdded, err = sl.append(slApp, []byte("metric_a 1\nmetric_b 1\nmetric_c{deleteme=\"yes\"} 1\nmetric_d 1\nmetric_e 1\nmetric_f 1\nmetric_g 1\nmetric_h{deleteme=\"yes\"} 1\nmetric_i{deleteme=\"yes\"} 1\n"), "", now) |
|
|
|
|
if err != errSampleLimit { |
|
|
|
|
t.Fatalf("Did not see expected sample limit error: %s", err) |
|
|
|
@ -1138,24 +1144,25 @@ func TestScrapeLoop_ChangingMetricString(t *testing.T) {
|
|
|
|
|
defer s.Close() |
|
|
|
|
|
|
|
|
|
capp := &collectResultAppender{} |
|
|
|
|
ctx := context.Background() |
|
|
|
|
|
|
|
|
|
sl := newScrapeLoop(context.Background(), |
|
|
|
|
sl := newScrapeLoop(ctx, |
|
|
|
|
nil, nil, nil, |
|
|
|
|
nopMutator, |
|
|
|
|
nopMutator, |
|
|
|
|
func() storage.Appender { capp.next = s.Appender(); return capp }, |
|
|
|
|
func(ctx context.Context) storage.Appender { capp.next = s.Appender(ctx); return capp }, |
|
|
|
|
nil, |
|
|
|
|
0, |
|
|
|
|
true, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
now := time.Now() |
|
|
|
|
slApp := sl.appender() |
|
|
|
|
slApp := sl.appender(ctx) |
|
|
|
|
_, _, _, err := sl.append(slApp, []byte(`metric_a{a="1",b="1"} 1`), "", now) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, slApp.Commit()) |
|
|
|
|
|
|
|
|
|
slApp = sl.appender() |
|
|
|
|
slApp = sl.appender(ctx) |
|
|
|
|
_, _, _, err = sl.append(slApp, []byte(`metric_a{b="1",a="1"} 2`), "", now.Add(time.Minute)) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, slApp.Commit()) |
|
|
|
@ -1178,24 +1185,25 @@ func TestScrapeLoop_ChangingMetricString(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
func TestScrapeLoopAppendStaleness(t *testing.T) { |
|
|
|
|
app := &collectResultAppender{} |
|
|
|
|
ctx := context.Background() |
|
|
|
|
|
|
|
|
|
sl := newScrapeLoop(context.Background(), |
|
|
|
|
sl := newScrapeLoop(ctx, |
|
|
|
|
nil, nil, nil, |
|
|
|
|
nopMutator, |
|
|
|
|
nopMutator, |
|
|
|
|
func() storage.Appender { return app }, |
|
|
|
|
func(ctx context.Context) storage.Appender { return app }, |
|
|
|
|
nil, |
|
|
|
|
0, |
|
|
|
|
true, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
now := time.Now() |
|
|
|
|
slApp := sl.appender() |
|
|
|
|
slApp := sl.appender(ctx) |
|
|
|
|
_, _, _, err := sl.append(slApp, []byte("metric_a 1\n"), "", now) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, slApp.Commit()) |
|
|
|
|
|
|
|
|
|
slApp = sl.appender() |
|
|
|
|
slApp = sl.appender(ctx) |
|
|
|
|
_, _, _, err = sl.append(slApp, []byte(""), "", now.Add(time.Second)) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, slApp.Commit()) |
|
|
|
@ -1222,23 +1230,24 @@ func TestScrapeLoopAppendStaleness(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
func TestScrapeLoopAppendNoStalenessIfTimestamp(t *testing.T) { |
|
|
|
|
app := &collectResultAppender{} |
|
|
|
|
sl := newScrapeLoop(context.Background(), |
|
|
|
|
ctx := context.Background() |
|
|
|
|
sl := newScrapeLoop(ctx, |
|
|
|
|
nil, nil, nil, |
|
|
|
|
nopMutator, |
|
|
|
|
nopMutator, |
|
|
|
|
func() storage.Appender { return app }, |
|
|
|
|
func(ctx context.Context) storage.Appender { return app }, |
|
|
|
|
nil, |
|
|
|
|
0, |
|
|
|
|
true, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
now := time.Now() |
|
|
|
|
slApp := sl.appender() |
|
|
|
|
slApp := sl.appender(ctx) |
|
|
|
|
_, _, _, err := sl.append(slApp, []byte("metric_a 1 1000\n"), "", now) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, slApp.Commit()) |
|
|
|
|
|
|
|
|
|
slApp = sl.appender() |
|
|
|
|
slApp = sl.appender(ctx) |
|
|
|
|
_, _, _, err = sl.append(slApp, []byte(""), "", now.Add(time.Second)) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, slApp.Commit()) |
|
|
|
@ -1257,7 +1266,7 @@ func TestScrapeLoopRunReportsTargetDownOnScrapeError(t *testing.T) {
|
|
|
|
|
var ( |
|
|
|
|
scraper = &testScraper{} |
|
|
|
|
appender = &collectResultAppender{} |
|
|
|
|
app = func() storage.Appender { return appender } |
|
|
|
|
app = func(ctx context.Context) storage.Appender { return appender } |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
@ -1285,7 +1294,7 @@ func TestScrapeLoopRunReportsTargetDownOnInvalidUTF8(t *testing.T) {
|
|
|
|
|
var ( |
|
|
|
|
scraper = &testScraper{} |
|
|
|
|
appender = &collectResultAppender{} |
|
|
|
|
app = func() storage.Appender { return appender } |
|
|
|
|
app = func(ctx context.Context) storage.Appender { return appender } |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
@ -1333,20 +1342,21 @@ func (app *errorAppender) AddFast(ref uint64, t int64, v float64) error {
|
|
|
|
|
|
|
|
|
|
func TestScrapeLoopAppendGracefullyIfAmendOrOutOfOrderOrOutOfBounds(t *testing.T) { |
|
|
|
|
app := &errorAppender{} |
|
|
|
|
ctx := context.Background() |
|
|
|
|
|
|
|
|
|
sl := newScrapeLoop(context.Background(), |
|
|
|
|
sl := newScrapeLoop(ctx, |
|
|
|
|
nil, |
|
|
|
|
nil, nil, |
|
|
|
|
nopMutator, |
|
|
|
|
nopMutator, |
|
|
|
|
func() storage.Appender { return app }, |
|
|
|
|
func(ctx context.Context) storage.Appender { return app }, |
|
|
|
|
nil, |
|
|
|
|
0, |
|
|
|
|
true, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
now := time.Unix(1, 0) |
|
|
|
|
slApp := sl.appender() |
|
|
|
|
slApp := sl.appender(ctx) |
|
|
|
|
total, added, seriesAdded, err := sl.append(slApp, []byte("out_of_order 1\namend 1\nnormal 1\nout_of_bounds 1\n"), "", now) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, slApp.Commit()) |
|
|
|
@ -1366,12 +1376,13 @@ func TestScrapeLoopAppendGracefullyIfAmendOrOutOfOrderOrOutOfBounds(t *testing.T
|
|
|
|
|
|
|
|
|
|
func TestScrapeLoopOutOfBoundsTimeError(t *testing.T) { |
|
|
|
|
app := &collectResultAppender{} |
|
|
|
|
sl := newScrapeLoop(context.Background(), |
|
|
|
|
ctx := context.Background() |
|
|
|
|
sl := newScrapeLoop(ctx, |
|
|
|
|
nil, |
|
|
|
|
nil, nil, |
|
|
|
|
nopMutator, |
|
|
|
|
nopMutator, |
|
|
|
|
func() storage.Appender { |
|
|
|
|
func(ctx context.Context) storage.Appender { |
|
|
|
|
return &timeLimitAppender{ |
|
|
|
|
Appender: app, |
|
|
|
|
maxTime: timestamp.FromTime(time.Now().Add(10 * time.Minute)), |
|
|
|
@ -1383,7 +1394,7 @@ func TestScrapeLoopOutOfBoundsTimeError(t *testing.T) {
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
now := time.Now().Add(20 * time.Minute) |
|
|
|
|
slApp := sl.appender() |
|
|
|
|
slApp := sl.appender(ctx) |
|
|
|
|
total, added, seriesAdded, err := sl.append(slApp, []byte("normal 1\n"), "", now) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, slApp.Commit()) |
|
|
|
@ -1556,21 +1567,22 @@ func TestScrapeLoop_RespectTimestamps(t *testing.T) {
|
|
|
|
|
s := teststorage.New(t) |
|
|
|
|
defer s.Close() |
|
|
|
|
|
|
|
|
|
app := s.Appender() |
|
|
|
|
ctx := context.Background() |
|
|
|
|
app := s.Appender(ctx) |
|
|
|
|
|
|
|
|
|
capp := &collectResultAppender{next: app} |
|
|
|
|
|
|
|
|
|
sl := newScrapeLoop(context.Background(), |
|
|
|
|
sl := newScrapeLoop(ctx, |
|
|
|
|
nil, nil, nil, |
|
|
|
|
nopMutator, |
|
|
|
|
nopMutator, |
|
|
|
|
func() storage.Appender { return capp }, |
|
|
|
|
func(ctx context.Context) storage.Appender { return capp }, |
|
|
|
|
nil, 0, |
|
|
|
|
true, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
now := time.Now() |
|
|
|
|
slApp := sl.appender() |
|
|
|
|
slApp := sl.appender(ctx) |
|
|
|
|
_, _, _, err := sl.append(slApp, []byte(`metric_a{a="1",b="1"} 1 0`), "", now) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, slApp.Commit()) |
|
|
|
@ -1589,21 +1601,22 @@ func TestScrapeLoop_DiscardTimestamps(t *testing.T) {
|
|
|
|
|
s := teststorage.New(t) |
|
|
|
|
defer s.Close() |
|
|
|
|
|
|
|
|
|
app := s.Appender() |
|
|
|
|
ctx := context.Background() |
|
|
|
|
app := s.Appender(ctx) |
|
|
|
|
|
|
|
|
|
capp := &collectResultAppender{next: app} |
|
|
|
|
|
|
|
|
|
sl := newScrapeLoop(context.Background(), |
|
|
|
|
sl := newScrapeLoop(ctx, |
|
|
|
|
nil, nil, nil, |
|
|
|
|
nopMutator, |
|
|
|
|
nopMutator, |
|
|
|
|
func() storage.Appender { return capp }, |
|
|
|
|
func(ctx context.Context) storage.Appender { return capp }, |
|
|
|
|
nil, 0, |
|
|
|
|
false, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
now := time.Now() |
|
|
|
|
slApp := sl.appender() |
|
|
|
|
slApp := sl.appender(ctx) |
|
|
|
|
_, _, _, err := sl.append(slApp, []byte(`metric_a{a="1",b="1"} 1 0`), "", now) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, slApp.Commit()) |
|
|
|
@ -1636,7 +1649,7 @@ func TestScrapeLoopDiscardDuplicateLabels(t *testing.T) {
|
|
|
|
|
defer cancel() |
|
|
|
|
|
|
|
|
|
// We add a good and a bad metric to check that both are discarded.
|
|
|
|
|
slApp := sl.appender() |
|
|
|
|
slApp := sl.appender(ctx) |
|
|
|
|
_, _, _, err := sl.append(slApp, []byte("test_metric{le=\"500\"} 1\ntest_metric{le=\"600\",le=\"700\"} 1\n"), "", time.Time{}) |
|
|
|
|
testutil.NotOk(t, err) |
|
|
|
|
testutil.Ok(t, slApp.Rollback()) |
|
|
|
@ -1648,7 +1661,7 @@ func TestScrapeLoopDiscardDuplicateLabels(t *testing.T) {
|
|
|
|
|
testutil.Ok(t, series.Err()) |
|
|
|
|
|
|
|
|
|
// We add a good metric to check that it is recorded.
|
|
|
|
|
slApp = sl.appender() |
|
|
|
|
slApp = sl.appender(ctx) |
|
|
|
|
_, _, _, err = sl.append(slApp, []byte("test_metric{le=\"500\"} 1\n"), "", time.Time{}) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, slApp.Commit()) |
|
|
|
@ -1665,7 +1678,8 @@ func TestScrapeLoopDiscardUnnamedMetrics(t *testing.T) {
|
|
|
|
|
s := teststorage.New(t) |
|
|
|
|
defer s.Close() |
|
|
|
|
|
|
|
|
|
app := s.Appender() |
|
|
|
|
ctx := context.Background() |
|
|
|
|
app := s.Appender(ctx) |
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
|
sl := newScrapeLoop(ctx, |
|
|
|
@ -1678,14 +1692,14 @@ func TestScrapeLoopDiscardUnnamedMetrics(t *testing.T) {
|
|
|
|
|
return l |
|
|
|
|
}, |
|
|
|
|
nopMutator, |
|
|
|
|
func() storage.Appender { return app }, |
|
|
|
|
func(ctx context.Context) storage.Appender { return app }, |
|
|
|
|
nil, |
|
|
|
|
0, |
|
|
|
|
true, |
|
|
|
|
) |
|
|
|
|
defer cancel() |
|
|
|
|
|
|
|
|
|
slApp := sl.appender() |
|
|
|
|
slApp := sl.appender(ctx) |
|
|
|
|
_, _, _, err := sl.append(slApp, []byte("nok 1\nnok2{drop=\"drop\"} 1\n"), "", time.Time{}) |
|
|
|
|
testutil.NotOk(t, err) |
|
|
|
|
testutil.Ok(t, slApp.Rollback()) |
|
|
|
@ -1901,7 +1915,7 @@ func TestScrapeAddFast(t *testing.T) {
|
|
|
|
|
) |
|
|
|
|
defer cancel() |
|
|
|
|
|
|
|
|
|
slApp := sl.appender() |
|
|
|
|
slApp := sl.appender(ctx) |
|
|
|
|
_, _, _, err := sl.append(slApp, []byte("up 1\n"), "", time.Time{}) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, slApp.Commit()) |
|
|
|
@ -1912,7 +1926,7 @@ func TestScrapeAddFast(t *testing.T) {
|
|
|
|
|
v.ref++ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
slApp = sl.appender() |
|
|
|
|
slApp = sl.appender(ctx) |
|
|
|
|
_, _, _, err = sl.append(slApp, []byte("up 1\n"), "", time.Time{}.Add(time.Second)) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, slApp.Commit()) |
|
|
|
|