MCPcopy
hub / github.com/zalando/skipper / TestTracingProxySpanWithLoopbackIfStatusFilter

Function TestTracingProxySpanWithLoopbackIfStatusFilter

proxy/tracing_test.go:550–619  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

548}
549
550func TestTracingProxySpanWithLoopbackIfStatusFilter(t *testing.T) {
551 // b: backend server that returns 404 to trigger loopbackIfStatus
552 // fb: fallback backend server for loopback request
553 // We cannot use shunt backends instead because in that case the proxy span will be nil
554 b := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
555 w.WriteHeader(http.StatusNotFound)
556 w.Write([]byte("Hello! I'm main backend!"))
557 }))
558 defer b.Close()
559 fb := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
560 w.WriteHeader(http.StatusOK)
561 w.Write([]byte("Hello! I'm fallback backend!"))
562 }))
563 defer fb.Close()
564
565 doc := fmt.Sprintf(`
566main: Path("/main") -> loopbackIfStatus(404, "/fallback") -> "%s";
567fallback: Path("/fallback") -> "%s";
568`, b.URL, fb.URL)
569
570 tracer := tracingtest.NewTracer()
571 params := Params{
572 OpenTracing: &OpenTracingParams{
573 Tracer: tracer,
574 },
575 Flags: FlagsNone,
576 }
577
578 t.Setenv("HOSTNAME", "shadow-tag.tracing.test")
579
580 tp, err := newTestProxyWithParams(doc, params)
581 if err != nil {
582 t.Fatal(err)
583 }
584 defer tp.close()
585
586 ps := httptest.NewServer(tp.proxy)
587 defer ps.Close()
588
589 req, err := http.NewRequest("GET", ps.URL+"/main", nil)
590 if err != nil {
591 t.Fatal(err)
592 }
593 req.Header.Set("X-Flow-Id", "test-flow-id-fallback")
594
595 rsp, err := ps.Client().Do(req)
596 if err != nil {
597 t.Fatal(err)
598 }
599 defer rsp.Body.Close()
600 io.Copy(io.Discard, rsp.Body)
601 t.Logf("got response %d", rsp.StatusCode)
602
603 pxSpanCount := 0
604 for _, s := range tracer.FinishedSpans() {
605 if s.OperationName == "proxy" {
606 pxSpanCount++
607 verifyNoTag(t, s, "shadow")

Callers

nothing calls this directly

Calls 13

NewTracerFunction · 0.92
newTestProxyWithParamsFunction · 0.85
verifyNoTagFunction · 0.85
ClientMethod · 0.80
FinishedSpansMethod · 0.80
verifyTagFunction · 0.70
CloseMethod · 0.65
SetMethod · 0.65
DoMethod · 0.65
WriteHeaderMethod · 0.45
WriteMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…