MCPcopy
hub / github.com/prometheus/prometheus / TestAppendWithSampleLimitAndNativeHistogram

Function TestAppendWithSampleLimitAndNativeHistogram

scrape/target_test.go:773–835  ·  view source on GitHub ↗

Test sample_limit when a scrape contains Native Histograms.

(t *testing.T)

Source from the content-addressed store, hash-verified

771
772// Test sample_limit when a scrape contains Native Histograms.
773func TestAppendWithSampleLimitAndNativeHistogram(t *testing.T) {
774 now := time.Now()
775 t.Run("appV2=false", func(t *testing.T) {
776 app := appenderWithLimits(teststorage.NewAppendable().Appender(t.Context()), 2, 0, histogram.ExponentialSchemaMax)
777
778 // sample_limit is set to 2, so first two scrapes should work
779 _, err := app.Append(0, labels.FromStrings(model.MetricNameLabel, "foo"), timestamp.FromTime(now), 1)
780 require.NoError(t, err)
781
782 // Second sample, should be ok.
783 _, err = app.AppendHistogram(
784 0,
785 labels.FromStrings(model.MetricNameLabel, "my_histogram1"),
786 timestamp.FromTime(now),
787 &histogram.Histogram{},
788 nil,
789 )
790 require.NoError(t, err)
791
792 // This is third sample with sample_limit=2, it should trigger errSampleLimit.
793 _, err = app.AppendHistogram(
794 0,
795 labels.FromStrings(model.MetricNameLabel, "my_histogram2"),
796 timestamp.FromTime(now),
797 &histogram.Histogram{},
798 nil,
799 )
800 require.ErrorIs(t, err, errSampleLimit)
801 })
802 t.Run("appV2=true", func(t *testing.T) {
803 app := appenderV2WithLimits(teststorage.NewAppendable().AppenderV2(t.Context()), 2, 0, histogram.ExponentialSchemaMax)
804
805 // sample_limit is set to 2, so first two scrapes should work
806 _, err := app.Append(0, labels.FromStrings(model.MetricNameLabel, "foo"), 0, timestamp.FromTime(now), 1, nil, nil, storage.AOptions{})
807 require.NoError(t, err)
808
809 // Second sample, should be ok.
810 _, err = app.Append(
811 0,
812 labels.FromStrings(model.MetricNameLabel, "my_histogram1"),
813 0,
814 timestamp.FromTime(now),
815 0,
816 &histogram.Histogram{},
817 nil,
818 storage.AOptions{},
819 )
820 require.NoError(t, err)
821
822 // This is third sample with sample_limit=2, it should trigger errSampleLimit.
823 _, err = app.Append(
824 0,
825 labels.FromStrings(model.MetricNameLabel, "my_histogram2"),
826 0,
827 timestamp.FromTime(now),
828 0,
829 &histogram.Histogram{},
830 nil,

Callers

nothing calls this directly

Calls 11

NewAppendableFunction · 0.92
FromStringsFunction · 0.92
FromTimeFunction · 0.92
appenderWithLimitsFunction · 0.85
appenderV2WithLimitsFunction · 0.85
RunMethod · 0.65
AppenderMethod · 0.65
AppendMethod · 0.65
AppendHistogramMethod · 0.65
AppenderV2Method · 0.65
ContextMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…