(t *testing.T, appV2 bool)
| 6430 | } |
| 6431 | |
| 6432 | func 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 | } |
no test coverage detected
searching dependent graphs…