MCPcopy
hub / github.com/prometheus/prometheus / testScrapeLoopCompression

Function testScrapeLoopCompression

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

Source from the content-addressed store, hash-verified

6430}
6431
6432func testScrapeLoopCompression(t *testing.T, appV2 bool) {
6433 s := teststorage.New(t)
6434
6435 metricsText := makeTestGauges(10)
6436
6437 for _, tc := range []struct {
6438 enableCompression bool
6439 acceptEncoding string
6440 }{
6441 {
6442 enableCompression: true,
6443 acceptEncoding: "gzip",
6444 },
6445 {
6446 enableCompression: false,
6447 acceptEncoding: "identity",
6448 },
6449 } {
6450 t.Run(fmt.Sprintf("compression=%v,acceptEncoding=%s", tc.enableCompression, tc.acceptEncoding), func(t *testing.T) {
6451 scraped := make(chan bool)
6452
6453 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
6454 require.Equal(t, tc.acceptEncoding, r.Header.Get("Accept-Encoding"), "invalid value of the Accept-Encoding header")
6455 _, _ = fmt.Fprint(w, string(metricsText))
6456 close(scraped)
6457 }))
6458 defer ts.Close()
6459
6460 cfg := &config.ScrapeConfig{
6461 JobName: "test",
6462 SampleLimit: 100,
6463 Scheme: "http",
6464 ScrapeInterval: model.Duration(100 * time.Millisecond),
6465 ScrapeTimeout: model.Duration(100 * time.Millisecond),
6466 EnableCompression: tc.enableCompression,
6467 MetricNameValidationScheme: model.UTF8Validation,
6468 MetricNameEscapingScheme: model.AllowUTF8,
6469 }
6470
6471 sa := selectAppendable(s, appV2)
6472 sp, err := newScrapePool(cfg, sa.V1(), sa.V2(), 0, nil, nil, &Options{}, newTestScrapeMetrics(t))
6473 require.NoError(t, err)
6474 defer sp.stop()
6475
6476 testURL, err := url.Parse(ts.URL)
6477 require.NoError(t, err)
6478 sp.Sync([]*targetgroup.Group{
6479 {
6480 Targets: []model.LabelSet{{model.AddressLabel: model.LabelValue(testURL.Host)}},
6481 },
6482 })
6483 require.Len(t, sp.ActiveTargets(), 1)
6484
6485 select {
6486 case <-time.After(5 * time.Second):
6487 t.Fatalf("target was not scraped")
6488 case <-scraped:
6489 }

Callers 1

Calls 15

NewFunction · 0.92
makeTestGaugesFunction · 0.85
selectAppendableFunction · 0.85
newScrapePoolFunction · 0.85
newTestScrapeMetricsFunction · 0.85
DurationMethod · 0.80
V1Method · 0.80
V2Method · 0.80
ActiveTargetsMethod · 0.80
RunMethod · 0.65
GetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…