feat(httpapi): harden control plane and speed up prefix refresh
Очередь job получила lease и fencing, телеметрия и прогресс deploy сохраняются, ревизия пишет manifest входов. Обновление префиксов не переписывает неизменённый снимок, большие наборы идут через COPY, а устаревшая ревизия не попадает в deploy. Бандл ноды кэшируется, prune и постановка job больше не держат горячий путь. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
924f111e48
commit
f8e0520817
197 files changed
+18655
-1416
No files matched your search
@@ -0,0 +1,80 @@
|
||||
package nodedispatch_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"evobgp/internal/nodedispatch"
|
||||
"evobgp/internal/store"
|
||||
)
|
||||
|
||||
type telemetryTestBody struct {
|
||||
io.Reader
|
||||
read int
|
||||
closed bool
|
||||
}
|
||||
|
||||
func (b *telemetryTestBody) Read(p []byte) (int, error) {
|
||||
n, err := b.Reader.Read(p)
|
||||
b.read += n
|
||||
return n, err
|
||||
}
|
||||
func (b *telemetryTestBody) Close() error { b.closed = true; return nil }
|
||||
|
||||
type telemetryErrorReader struct{}
|
||||
|
||||
func (telemetryErrorReader) Read([]byte) (int, error) { return 0, errors.New("injected body failure") }
|
||||
|
||||
func TestAgentTelemetryCompleteBodyLimits(t *testing.T) {
|
||||
sp := &store.Speaker{ID: "legacy", Role: "replica", MetaJSON: store.SpeakerMetaJSON(store.SpeakerMeta{AgentDomain: "agent.example.test", AgentSecret: "secret"})}
|
||||
for _, tc := range []struct {
|
||||
name, prefix string
|
||||
limit int
|
||||
call func(nodedispatch.Options) string
|
||||
}{
|
||||
{"health", `{"ok":true}`, 64 << 10, func(opts nodedispatch.Options) string {
|
||||
return nodedispatch.FetchAgentHealth(context.Background(), sp, opts).Error
|
||||
}},
|
||||
{"protocols", `{"sessions":[]}`, 8 << 20, func(opts nodedispatch.Options) string {
|
||||
return nodedispatch.FetchBirdProtocols(context.Background(), sp, opts).Error
|
||||
}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
for _, known := range []bool{true, false} {
|
||||
for _, extra := range []int{0, 1} {
|
||||
data := tc.prefix + strings.Repeat(" ", tc.limit-len(tc.prefix)+extra)
|
||||
body := &telemetryTestBody{Reader: strings.NewReader(data)}
|
||||
client := &http.Client{Transport: legacyRoundTripFunc(func(*http.Request) (*http.Response, error) {
|
||||
length := int64(-1)
|
||||
if known {
|
||||
length = int64(len(data))
|
||||
}
|
||||
return &http.Response{StatusCode: 200, ContentLength: length, Body: body, Header: make(http.Header)}, nil
|
||||
})}
|
||||
err := tc.call(nodedispatch.Options{HTTPClient: client})
|
||||
if (extra == 0 && err != "") || (extra == 1 && err == "") || body.read > tc.limit+1 || !body.closed {
|
||||
t.Fatalf("known=%v extra=%d read=%d closed=%v error=%s", known, extra, body.read, body.closed, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, status := range []int{200, 400} {
|
||||
reader := io.MultiReader(strings.NewReader(tc.prefix), telemetryErrorReader{})
|
||||
if status == 400 {
|
||||
reader = io.MultiReader(strings.NewReader(strings.Repeat("x", 16000)))
|
||||
}
|
||||
body := &telemetryTestBody{Reader: reader}
|
||||
client := &http.Client{Transport: legacyRoundTripFunc(func(*http.Request) (*http.Response, error) {
|
||||
return &http.Response{StatusCode: status, ContentLength: -1, Body: body, Header: make(http.Header)}, nil
|
||||
})}
|
||||
err := tc.call(nodedispatch.Options{HTTPClient: client})
|
||||
if err == "" || !body.closed || (status == 400 && body.read > 4<<10) {
|
||||
t.Fatalf("status=%d read=%d closed=%v error=%s", status, body.read, body.closed, err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user