Добавить генератор нагрузки, сбор метрик реплик и сценарии экспериментов для отказов, rolling update и трека 1

This commit is contained in:
2026-11-02 17:44:59 +03:00
parent c5cdcb3377
commit b2973405f3
30 changed files with 2067 additions and 18 deletions
+36
View File
@@ -10,6 +10,8 @@ import (
"time"
"github.com/google/uuid"
"messenger/internal/chat"
)
// client is a minimal typed HTTP client for the messenger API.
@@ -50,6 +52,40 @@ func (c *client) postMessage(chatID, token, text string, out any) error {
return c.do(req, token, http.StatusCreated, out)
}
// sendWithKey sends one attempt of a message under the given key on a
// connection of its own and reports the status, the message (on 201) and the
// replica that answered.
func (c *client) sendWithKey(chatID, token, key, text string) (int, chat.MessageResponse, string, error) {
var msg chat.MessageResponse
raw, err := json.Marshal(map[string]string{"text": text})
if err != nil {
return 0, msg, "", err
}
req, err := http.NewRequest(http.MethodPost, c.base+"/api/v1/chats/"+chatID+"/messages", bytes.NewReader(raw))
if err != nil {
return 0, msg, "", err
}
req.Close = true
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Idempotency-Key", key)
resp, err := c.http.Do(req)
if err != nil {
return 0, msg, "", err
}
defer resp.Body.Close()
payload, err := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
if err != nil {
return 0, msg, "", err
}
if resp.StatusCode == http.StatusCreated {
if err := json.Unmarshal(payload, &msg); err != nil {
return 0, msg, "", err
}
}
return resp.StatusCode, msg, resp.Header.Get("X-Instance-Id"), nil
}
// login opens a session with Basic credentials and returns its bearer token.
func (c *client) login(username, password string) (string, error) {
req, err := http.NewRequest(http.MethodPost, c.base+"/api/v1/auth/sessions", nil)