MCPcopy
hub / github.com/prometheus/prometheus / testScrapeAppendMetadataUpdate

Function testScrapeAppendMetadataUpdate

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

Source from the content-addressed store, hash-verified

224}
225
226func testScrapeAppendMetadataUpdate(t *testing.T, appV2 bool) {
227 const (
228 scrape1 = `# TYPE test_metric counter
229# HELP test_metric some help text
230# UNIT test_metric metric
231test_metric_total 1
232# TYPE test_metric2 gauge
233# HELP test_metric2 other help text
234test_metric2{foo="bar"} 2
235# TYPE test_metric3 gauge
236# HELP test_metric3 this represents tricky case of "broken" text that is not trivial to detect
237test_metric3_metric4{foo="bar"} 2
238# EOF`
239 scrape2 = `# TYPE test_metric counter
240# HELP test_metric different help text
241test_metric_total 11
242# TYPE test_metric2 gauge
243# HELP test_metric2 other help text
244# UNIT test_metric2 metric2
245test_metric2{foo="bar"} 22
246# EOF`
247 )
248
249 appTest := teststorage.NewAppendable()
250 sl, _ := newTestScrapeLoop(t, withAppendable(appTest, appV2))
251
252 now := time.Now()
253 app := sl.appender()
254 _, _, _, err := app.append([]byte(scrape1), "application/openmetrics-text", now)
255 require.NoError(t, err)
256 require.NoError(t, app.Commit())
257 teststorage.RequireEqual(t, []sample{
258 {L: labels.FromStrings("__name__", "test_metric_total"), M: metadata.Metadata{Type: "counter", Unit: "metric", Help: "some help text"}},
259 {L: labels.FromStrings("__name__", "test_metric2", "foo", "bar"), M: metadata.Metadata{Type: "gauge", Unit: "", Help: "other help text"}},
260 }, appTest.ResultMetadata())
261 appTest.ResultReset()
262
263 app = sl.appender()
264 _, _, _, err = app.append([]byte(scrape1), "application/openmetrics-text", now.Add(15*time.Second))
265 require.NoError(t, err)
266 require.NoError(t, app.Commit())
267 if appV2 {
268 // Next (the same) scrape should pass new metadata entries as per always-on metadata Appendable V2 contract.
269 teststorage.RequireEqual(t, []sample{
270 {L: labels.FromStrings("__name__", "test_metric_total"), M: metadata.Metadata{Type: "counter", Unit: "metric", Help: "some help text"}},
271 {L: labels.FromStrings("__name__", "test_metric2", "foo", "bar"), M: metadata.Metadata{Type: "gauge", Unit: "", Help: "other help text"}},
272 }, appTest.ResultMetadata())
273 } else {
274 // Next (the same) scrape should not add new metadata entries.
275 require.Empty(t, appTest.ResultMetadata())
276 }
277 appTest.ResultReset()
278
279 app = sl.appender()
280 _, _, _, err = app.append([]byte(scrape2), "application/openmetrics-text", now.Add(15*time.Second))
281 require.NoError(t, err)
282 require.NoError(t, app.Commit())
283 teststorage.RequireEqual(t, []sample{

Callers 1

Calls 11

ResultMetadataMethod · 0.95
ResultResetMethod · 0.95
NewAppendableFunction · 0.92
RequireEqualFunction · 0.92
FromStringsFunction · 0.92
newTestScrapeLoopFunction · 0.85
withAppendableFunction · 0.85
appendMethod · 0.65
CommitMethod · 0.65
AddMethod · 0.65
appenderMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…