-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: flightrecorder to enable Go trace
feature: allow configuration for Go x/trace.FlightRecorder pass default period to define what means skipper to be slow Signed-off-by: Sandor Szücs <[email protected]>
- Loading branch information
Showing
6 changed files
with
302 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package proxy_test | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
"time" | ||
|
||
"github.com/zalando/skipper/eskip" | ||
"github.com/zalando/skipper/filters" | ||
"github.com/zalando/skipper/filters/diag" | ||
"github.com/zalando/skipper/proxy" | ||
"github.com/zalando/skipper/proxy/proxytest" | ||
xtrace "golang.org/x/exp/trace" | ||
) | ||
|
||
func TestFlightRecorder(t *testing.T) { | ||
ch := make(chan int) | ||
service := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != "PUT" { | ||
w.WriteHeader(http.StatusMethodNotAllowed) | ||
w.Write([]byte(http.StatusText(http.StatusMethodNotAllowed))) | ||
ch <- http.StatusMethodNotAllowed | ||
return | ||
} | ||
|
||
var buf bytes.Buffer | ||
n, err := io.Copy(&buf, r.Body) | ||
if err != nil { | ||
t.Fatalf("Failed to copy data: %v", err) | ||
} | ||
if n < 100 { | ||
t.Fatalf("Failed to write enough data: %d bytes", n) | ||
} | ||
w.WriteHeader(http.StatusCreated) | ||
w.Write([]byte(http.StatusText(http.StatusCreated))) | ||
ch <- http.StatusCreated | ||
})) | ||
defer service.Close() | ||
|
||
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusOK) | ||
w.Write([]byte(http.StatusText(http.StatusOK))) | ||
})) | ||
defer backend.Close() | ||
|
||
flightRecorder := xtrace.NewFlightRecorder() | ||
flightRecorder.Start() | ||
|
||
spec := diag.NewLatency() | ||
fr := make(filters.Registry) | ||
fr.Register(spec) | ||
|
||
doc := fmt.Sprintf(`r: * -> latency("100ms") -> "%s"`, backend.URL) | ||
rr := eskip.MustParse(doc) | ||
|
||
pr := proxytest.WithParams(fr, proxy.Params{ | ||
FlightRecorder: flightRecorder, | ||
FlightRecorderTargetURL: service.URL, | ||
FlightRecorderPeriod: 90 * time.Millisecond, | ||
}, rr...) | ||
defer pr.Close() | ||
|
||
rsp, err := pr.Client().Get(pr.URL) | ||
if err != nil { | ||
t.Fatalf("Failed to GET %q: %v", pr.URL, err) | ||
} | ||
defer rsp.Body.Close() | ||
_, err = io.ReadAll(rsp.Body) | ||
if err != nil { | ||
t.Fatalf("Failed to read body: %v", err) | ||
} | ||
|
||
switch rsp.StatusCode { | ||
case http.StatusOK: | ||
// ok | ||
default: | ||
t.Fatalf("Failed to get status OK: %d", rsp.StatusCode) | ||
} | ||
|
||
statusCode := <-ch | ||
switch statusCode { | ||
case http.StatusCreated: | ||
// ok | ||
default: | ||
t.Fatalf("Failed to get status OK: %d", rsp.StatusCode) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.