MCPcopy
hub / github.com/prometheus/prometheus / testScrapeLoopDiscardDuplicateLabels

Function testScrapeLoopDiscardDuplicateLabels

scrape/scrape_test.go:4897–4930  ·  view source on GitHub ↗
(t *testing.T, appV2 bool)

Source from the content-addressed store, hash-verified

4895}
4896
4897func testScrapeLoopDiscardDuplicateLabels(t *testing.T, appV2 bool) {
4898 s := teststorage.New(t)
4899
4900 appTest := teststorage.NewAppendable().Then(s)
4901 sl, _ := newTestScrapeLoop(t, withAppendable(appTest, appV2))
4902
4903 // We add a good and a bad metric to check that both are discarded.
4904 app := sl.appender()
4905 _, _, _, err := app.append([]byte("test_metric{le=\"500\"} 1\ntest_metric{le=\"600\",le=\"700\"} 1\n"), "text/plain", time.Time{})
4906 require.Error(t, err)
4907 require.NoError(t, app.Rollback())
4908 // We need to cycle staleness cache maps after a manual rollback. Otherwise, they will have old entries in them,
4909 // which would cause ErrDuplicateSampleForTimestamp errors on the next append.
4910 sl.cache.iterDone(true)
4911
4912 q, err := s.Querier(time.Time{}.UnixNano(), 0)
4913 require.NoError(t, err)
4914 series := q.Select(sl.ctx, false, nil, labels.MustNewMatcher(labels.MatchRegexp, "__name__", ".*"))
4915 require.False(t, series.Next(), "series found in tsdb")
4916 require.NoError(t, series.Err())
4917
4918 // We add a good metric to check that it is recorded.
4919 app = sl.appender()
4920 _, _, _, err = app.append([]byte("test_metric{le=\"500\"} 1\n"), "text/plain", time.Time{})
4921 require.NoError(t, err)
4922 require.NoError(t, app.Commit())
4923
4924 q, err = s.Querier(time.Time{}.UnixNano(), 0)
4925 require.NoError(t, err)
4926 series = q.Select(sl.ctx, false, nil, labels.MustNewMatcher(labels.MatchEqual, "le", "500"))
4927 require.True(t, series.Next(), "series not found in tsdb")
4928 require.NoError(t, series.Err())
4929 require.False(t, series.Next(), "more than one series found in tsdb")
4930}
4931
4932func TestScrapeLoopDiscardUnnamedMetrics(t *testing.T) {
4933 foreachAppendable(t, func(t *testing.T, appV2 bool) {

Callers 1

Calls 15

NewFunction · 0.92
NewAppendableFunction · 0.92
MustNewMatcherFunction · 0.92
newTestScrapeLoopFunction · 0.85
withAppendableFunction · 0.85
ThenMethod · 0.80
iterDoneMethod · 0.80
appendMethod · 0.65
ErrorMethod · 0.65
RollbackMethod · 0.65
QuerierMethod · 0.65
SelectMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…