Добавить генератор нагрузки, сбор метрик реплик и сценарии экспериментов для отказов, rolling update и трека 1
This commit is contained in:
@@ -67,3 +67,24 @@ func Run(ctx context.Context, log *slog.Logger, ln net.Listener, h http.Handler,
|
||||
log.Info("shutdown completed")
|
||||
return nil
|
||||
}
|
||||
|
||||
// RunDebug serves h, the internal metrics of the process, on ln until ctx is
|
||||
// cancelled. Nothing outside the stand's network reaches it and no request
|
||||
// depends on it, so it closes at once instead of draining.
|
||||
func RunDebug(ctx context.Context, log *slog.Logger, ln net.Listener, h http.Handler) error {
|
||||
srv := &http.Server{
|
||||
Handler: h,
|
||||
ReadHeaderTimeout: 5 * time.Second,
|
||||
WriteTimeout: 10 * time.Second,
|
||||
ErrorLog: slog.NewLogLogger(log.Handler(), slog.LevelWarn),
|
||||
}
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
_ = srv.Close()
|
||||
}()
|
||||
log.Info("debug listening", "addr", ln.Addr().String())
|
||||
if err := srv.Serve(ln); !errors.Is(err, http.ErrServerClosed) {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -143,3 +143,27 @@ func waitFor(t *testing.T, url string, status int) {
|
||||
}
|
||||
t.Fatalf("%s did not return %d in time", url, status)
|
||||
}
|
||||
|
||||
// The debug listener has no drain: it serves the benchmark's metrics scraper
|
||||
// only and stops with the process.
|
||||
func TestRunDebugServesUntilCancelled(t *testing.T) {
|
||||
log := slog.New(slog.NewTextHandler(io.Discard, nil))
|
||||
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusTeapot) })
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
done := make(chan error, 1)
|
||||
go func() { done <- server.RunDebug(ctx, log, ln, h) }()
|
||||
waitFor(t, "http://"+ln.Addr().String()+"/debug/vars", http.StatusTeapot)
|
||||
cancel()
|
||||
select {
|
||||
case err := <-done:
|
||||
if err != nil {
|
||||
t.Fatalf("RunDebug returned %v", err)
|
||||
}
|
||||
case <-time.After(2 * time.Second):
|
||||
t.Fatal("RunDebug did not stop after cancel")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user