(t *testing.T, appV2 bool)
| 224 | } |
| 225 | |
| 226 | func 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 |
| 231 | test_metric_total 1 |
| 232 | # TYPE test_metric2 gauge |
| 233 | # HELP test_metric2 other help text |
| 234 | test_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 |
| 237 | test_metric3_metric4{foo="bar"} 2 |
| 238 | # EOF` |
| 239 | scrape2 = `# TYPE test_metric counter |
| 240 | # HELP test_metric different help text |
| 241 | test_metric_total 11 |
| 242 | # TYPE test_metric2 gauge |
| 243 | # HELP test_metric2 other help text |
| 244 | # UNIT test_metric2 metric2 |
| 245 | test_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{ |
no test coverage detected
searching dependent graphs…