mirror of
https://github.com/prometheus/prometheus.git
synced 2025-08-06 14:17:12 +02:00
adding test
Signed-off-by: Vanshikav123 <vanshikav928@gmail.com>
This commit is contained in:
parent
4d5add3cc3
commit
97f288ad87
@ -822,9 +822,6 @@ func acceptEncodingHeader(enableCompression bool) string {
|
||||
var UserAgent = version.PrometheusUserAgent()
|
||||
|
||||
func (s *targetScraper) scrape(ctx context.Context) (*http.Response, error) {
|
||||
ctx, span := otel.Tracer("").Start(ctx, "Scrape", trace.WithSpanKind(trace.SpanKindClient))
|
||||
defer span.End()
|
||||
|
||||
if s.req == nil {
|
||||
req, err := http.NewRequest(http.MethodGet, s.URL().String(), nil)
|
||||
if err != nil {
|
||||
@ -837,11 +834,10 @@ func (s *targetScraper) scrape(ctx context.Context) (*http.Response, error) {
|
||||
|
||||
s.req = req
|
||||
}
|
||||
|
||||
ctx, span := otel.Tracer("").Start(ctx, "Scrape", trace.WithSpanKind(trace.SpanKindClient))
|
||||
defer span.End()
|
||||
req := s.req.WithContext(ctx)
|
||||
|
||||
otel.GetTextMapPropagator().Inject(ctx, propagation.HeaderCarrier(req.Header))
|
||||
|
||||
return s.client.Do(req)
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,9 @@ import (
|
||||
"github.com/prometheus/common/model"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
|
||||
"github.com/prometheus/prometheus/config"
|
||||
"github.com/prometheus/prometheus/discovery"
|
||||
@ -3119,7 +3122,13 @@ func TestTargetScraperScrapeOK(t *testing.T) {
|
||||
protobufParsing bool
|
||||
allowUTF8 bool
|
||||
qValuePattern = regexp.MustCompile(`q=([0-9]+(\.\d+)?)`)
|
||||
traceparentPattern = regexp.MustCompile(`^[0-9a-f]{2}-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}$`)
|
||||
)
|
||||
tp := sdktrace.NewTracerProvider(
|
||||
sdktrace.WithSampler(sdktrace.AlwaysSample()),
|
||||
)
|
||||
otel.SetTracerProvider(tp)
|
||||
otel.SetTextMapPropagator(propagation.TraceContext{})
|
||||
|
||||
server := httptest.NewServer(
|
||||
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@ -3148,6 +3157,11 @@ func TestTargetScraperScrapeOK(t *testing.T) {
|
||||
timeout := r.Header.Get("X-Prometheus-Scrape-Timeout-Seconds")
|
||||
require.Equal(t, expectedTimeout, timeout, "Expected scrape timeout header.")
|
||||
|
||||
traceparent := r.Header.Get("traceparent")
|
||||
require.NotEmpty(t, traceparent, "Expected traceparent header to be present")
|
||||
require.Regexp(t, traceparentPattern, traceparent,
|
||||
"Traceparent header must match W3C format, got %q", traceparent)
|
||||
|
||||
if allowUTF8 {
|
||||
w.Header().Set("Content-Type", `text/plain; version=1.0.0; escaping=allow-utf-8`)
|
||||
} else {
|
||||
@ -3162,7 +3176,6 @@ func TestTargetScraperScrapeOK(t *testing.T) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
runTest := func(t *testing.T, acceptHeader string) {
|
||||
ts := &targetScraper{
|
||||
Target: &Target{
|
||||
|
Loading…
Reference in New Issue
Block a user