lab3: балансировка, идемпотентность, отказ реплики, трек 1

- X-Instance-Id, обязательный Idempotency-Key (PostgreSQL, одна транзакция)
- HAProxy + 2..N реплик API, readiness/drain по SIGTERM, однократные миграции
- скрипты stop-one/restore/restart/rolling-update/collect-evidence
- трек 1: параметризованный стенд, cmd/bench, оркестратор и анализ
- workflow реального прогона Docker-стенда на GitHub Actions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-23 17:24:54 +03:00
co-authored by Claude Opus 5.5
parent 0ab3a341aa
commit 2e7a80be92
68 changed files with 4747 additions and 17 deletions
@@ -0,0 +1,29 @@
package middleware
import (
"crypto/rand"
"fmt"
"net/http"
"github.com/charawein/mtusi2026lab3/internal/transport/httputil"
)
func RequestID(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
id := r.Header.Get("X-Request-Id")
if id == "" {
id = newRequestID()
}
w.Header().Set("X-Request-Id", id)
ctx := httputil.ContextWithRequestID(r.Context(), id)
next.ServeHTTP(w, r.WithContext(ctx))
})
}
func newRequestID() string {
var b [12]byte
if _, err := rand.Read(b[:]); err != nil {
panic(fmt.Sprintf("crypto/rand failed: %v", err))
}
return fmt.Sprintf("%x", b[:])
}