mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-29 07:29:42 -08:00
[BUGFIX] Scraping: allow multiple samples on same series (#14685)
So long as they specify timestamps. We don't check that the timestamps are different. Extend test, and use client_golang/prometheus/testutil to simplify metric check. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
6e971a7dc9
commit
d697719db6
|
@ -1621,7 +1621,7 @@ loop:
|
||||||
updateMetadata(lset, true)
|
updateMetadata(lset, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
if seriesAlreadyScraped {
|
if seriesAlreadyScraped && parsedTimestamp == nil {
|
||||||
err = storage.ErrDuplicateSampleForTimestamp
|
err = storage.ErrDuplicateSampleForTimestamp
|
||||||
} else {
|
} else {
|
||||||
if ctMs := p.CreatedTimestamp(); sl.enableCTZeroIngestion && ctMs != nil {
|
if ctMs := p.CreatedTimestamp(); sl.enableCTZeroIngestion && ctMs != nil {
|
||||||
|
|
|
@ -35,6 +35,7 @@ import (
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
prom_testutil "github.com/prometheus/client_golang/prometheus/testutil"
|
||||||
dto "github.com/prometheus/client_model/go"
|
dto "github.com/prometheus/client_model/go"
|
||||||
config_util "github.com/prometheus/common/config"
|
config_util "github.com/prometheus/common/config"
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
|
@ -3627,6 +3628,7 @@ func TestScrapeLoopSeriesAddedDuplicates(t *testing.T) {
|
||||||
require.Equal(t, 3, total)
|
require.Equal(t, 3, total)
|
||||||
require.Equal(t, 3, added)
|
require.Equal(t, 3, added)
|
||||||
require.Equal(t, 1, seriesAdded)
|
require.Equal(t, 1, seriesAdded)
|
||||||
|
require.Equal(t, 2.0, prom_testutil.ToFloat64(sl.metrics.targetScrapeSampleDuplicate))
|
||||||
|
|
||||||
slApp = sl.appender(ctx)
|
slApp = sl.appender(ctx)
|
||||||
total, added, seriesAdded, err = sl.append(slApp, []byte("test_metric 1\ntest_metric 1\ntest_metric 1\n"), "", time.Time{})
|
total, added, seriesAdded, err = sl.append(slApp, []byte("test_metric 1\ntest_metric 1\ntest_metric 1\n"), "", time.Time{})
|
||||||
|
@ -3635,12 +3637,18 @@ func TestScrapeLoopSeriesAddedDuplicates(t *testing.T) {
|
||||||
require.Equal(t, 3, total)
|
require.Equal(t, 3, total)
|
||||||
require.Equal(t, 3, added)
|
require.Equal(t, 3, added)
|
||||||
require.Equal(t, 0, seriesAdded)
|
require.Equal(t, 0, seriesAdded)
|
||||||
|
require.Equal(t, 4.0, prom_testutil.ToFloat64(sl.metrics.targetScrapeSampleDuplicate))
|
||||||
|
|
||||||
metric := dto.Metric{}
|
// When different timestamps are supplied, multiple samples are accepted.
|
||||||
err = sl.metrics.targetScrapeSampleDuplicate.Write(&metric)
|
slApp = sl.appender(ctx)
|
||||||
|
total, added, seriesAdded, err = sl.append(slApp, []byte("test_metric 1 1001\ntest_metric 1 1002\ntest_metric 1 1003\n"), "", time.Time{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
value := metric.GetCounter().GetValue()
|
require.NoError(t, slApp.Commit())
|
||||||
require.Equal(t, 4.0, value)
|
require.Equal(t, 3, total)
|
||||||
|
require.Equal(t, 3, added)
|
||||||
|
require.Equal(t, 0, seriesAdded)
|
||||||
|
// Metric is not higher than last time.
|
||||||
|
require.Equal(t, 4.0, prom_testutil.ToFloat64(sl.metrics.targetScrapeSampleDuplicate))
|
||||||
}
|
}
|
||||||
|
|
||||||
// This tests running a full scrape loop and checking that the scrape option
|
// This tests running a full scrape loop and checking that the scrape option
|
||||||
|
|
Loading…
Reference in a new issue