(t *testing.T)
| 1787 | } |
| 1788 | |
| 1789 | func TestScrapeLoopAppend_StartTimeSynthesis(t *testing.T) { |
| 1790 | ts := time.Now() |
| 1791 | |
| 1792 | requireSample := func(t *testing.T, s teststorage.Sample, name string, val float64, ts, st int64, isNaN bool) { |
| 1793 | t.Helper() |
| 1794 | require.Equal(t, name, s.L.Get(model.MetricNameLabel)) |
| 1795 | require.Equal(t, ts, s.T) |
| 1796 | if isNaN { |
| 1797 | require.True(t, value.IsStaleNaN(s.V)) |
| 1798 | } else { |
| 1799 | require.Equal(t, val, s.V) |
| 1800 | } |
| 1801 | require.Equal(t, st, s.ST) |
| 1802 | } |
| 1803 | |
| 1804 | s := teststorage.New(t) |
| 1805 | |
| 1806 | appTest := teststorage.NewAppendable().Then(s) |
| 1807 | sl, _ := newTestScrapeLoop(t, withAppendable(appTest, true), func(sl *scrapeLoop) { |
| 1808 | sl.synthesizeST = true |
| 1809 | sl.parseST = true |
| 1810 | }) |
| 1811 | |
| 1812 | // First Scrape: anchor the start time, append is skipped. |
| 1813 | scrapeA := []byte(`# TYPE test_metric counter |
| 1814 | test_metric 10 |
| 1815 | # TYPE test_gauge gauge |
| 1816 | test_gauge 10 |
| 1817 | # EOF |
| 1818 | `) |
| 1819 | app := sl.appender() |
| 1820 | _, _, _, err := app.append(scrapeA, "application/openmetrics-text", ts) |
| 1821 | require.NoError(t, err) |
| 1822 | require.NoError(t, app.Commit()) |
| 1823 | |
| 1824 | // Gauge should have 1 point, Counter should be skipped. |
| 1825 | got := appTest.ResultSamples() |
| 1826 | require.Len(t, got, 1) |
| 1827 | requireSample(t, got[0], "test_gauge", 10, timestamp.FromTime(ts), 0, false) |
| 1828 | |
| 1829 | // Second Scrape: Counter should yield 1 point with delta = 5, and ST = ts. |
| 1830 | ts2 := ts.Add(time.Second) |
| 1831 | scrapeB := []byte(`# TYPE test_metric counter |
| 1832 | test_metric 15 |
| 1833 | # TYPE test_gauge gauge |
| 1834 | test_gauge 12 |
| 1835 | # EOF |
| 1836 | `) |
| 1837 | app = sl.appender() |
| 1838 | _, _, _, err = app.append(scrapeB, "application/openmetrics-text", ts2) |
| 1839 | require.NoError(t, err) |
| 1840 | require.NoError(t, app.Commit()) |
| 1841 | |
| 1842 | got = appTest.ResultSamples() |
| 1843 | |
| 1844 | require.Len(t, got, 3) |
| 1845 | requireSample(t, got[0], "test_gauge", 10, timestamp.FromTime(ts), 0, false) |
| 1846 | requireSample(t, got[1], "test_metric", 5, timestamp.FromTime(ts2), timestamp.FromTime(ts), false) |
nothing calls this directly
no test coverage detected
searching dependent graphs…