Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions discovery/shared/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/livepeer/node/destination"
)

const MaxBody = 1 << 20
const MaxBody = 3 << 20
const ClockSkew = 30 * time.Second

// Runner exposes the fields used to validate and compare an inventory record.
Expand All @@ -34,7 +34,7 @@ func ValidateURL(u *url.URL) error {
func Read(body io.Reader) ([]byte, error) {
data, err := io.ReadAll(io.LimitReader(body, MaxBody+1))
if err != nil || len(data) > MaxBody {
return nil, errors.New("discovery response unreadable or exceeds 1 MiB")
return nil, errors.New("discovery response unreadable or exceeds 3 MiB")
}
return data, nil
}
Expand Down
4 changes: 2 additions & 2 deletions docs/discovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Duplicate URLs are skipped. Private sources require
returned node metadata are not followed.

Refreshes run at startup and every `RefreshInterval` (default `5m`), with at most
five concurrent requests, a three-second timeout, and a 1 MiB limit per response.
five concurrent requests, a three-second timeout, and a 3 MiB limit per response.
HTTPS uses system trust. A successful response replaces that source's inventory,
including when empty. Failures retain the cached inventory and last successful
query time until `MaxFailedRefreshes` consecutive failures (default `6`). Set `0`
Expand All @@ -54,7 +54,7 @@ discovery has no public identity of its own. See the
rules. `AdvertiseNodes` and `AdvertiseRunners` default to `true`; disabling either
omits the metadata entry or runner entries, respectively. Disabling both returns
`[]` and stops collection. Oversized responses are served with a warning, but
signers reject responses larger than 1 MiB.
signers reject responses larger than 3 MiB.

The metrics listener defaults to `127.0.0.1:8940` and serves `/healthz`,
`/readyz`, and `/metrics`, including source health, cached inventory, refresh
Expand Down
2 changes: 1 addition & 1 deletion docs/signer.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ DiscoveryGrants = ["127.0.0.1:8935"]

The signer appends `/discovery` to static base URLs and uses webhook URLs unchanged.
It polls at startup and every `DiscoveryRefreshInterval` (positive, default `5m`).
Fetches have a five-second timeout and 1 MiB response limit. Failed polls retain
Inventory fetches have a five-second timeout and a 3 MiB limit. Failed polls retain
the last inventory until `DiscoveryMaxFailedRefreshes` consecutive failures
(default `6`, nonnegative) remove it; `0` evicts on the first failure. Recovered
sources reappear on subsequent polls.
Expand Down
8 changes: 6 additions & 2 deletions signer/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func discoveryResponse(s *Service, query string) *httptest.ResponseRecorder {

func TestSignerDiscovery(t *testing.T) {
const advertised = `[{"address":"http://localhost:9000","runners":[{"url":"http://localhost:9000/app","observed_at":"2026-01-01T00:00:00Z","app":"retained","version":"v1","metadata":"model-x","mode":"single-shot","gpu":{"id":"0","name":" H100 ","vram_mb":80000},"capacity":3,"capacity_used":1,"capacity_available":2,"price_info":{"price":10,"price_usd":0.1,"currency":"wei","unit":"fixed"}},{"url":"http://localhost:9000/cpu","observed_at":"2026-01-01T00:00:00Z","app":"cpu","mode":"single-shot","capacity":1,"price_info":{"price":1,"currency":"wei","unit":"fixed"}}]}]`
const maxBytes = 3 << 20
bodies := map[string]string{
"empty": "[]", "good": advertised, "failed": "", "malformed": "not JSON",
"lenient": strings.NewReplacer(
Expand All @@ -38,8 +39,10 @@ func TestSignerDiscovery(t *testing.T) {
`"app":"cpu",`, `"app":"cpu","version":null,"metadata":null,"gpu":null,"capacity_used":null,"capacity_available":null,`,
).Replace(advertised),
"metadata": `[{"nodes":[]}]`,
"truncated": `[{"address":`, "oversized": `[{"address":"` + strings.Repeat("a", 1<<20) + `"}]`,
"invalid": `[{"address":"file:///invalid","runners":[{"url":"http://localhost/app","app":"example"}]},{"address":"https://orch.example","runners":[{"url":"http://localhost/app"},{"app":"example"}]}]`,
"truncated": `[{"address":`,
"max-size": advertised + strings.Repeat(" ", maxBytes-len(advertised)),
"oversized": advertised + strings.Repeat(" ", maxBytes+1-len(advertised)),
"invalid": `[{"address":"file:///invalid","runners":[{"url":"http://localhost/app","app":"example"}]},{"address":"https://orch.example","runners":[{"url":"http://localhost/app"},{"app":"example"}]}]`,
}
var connections atomic.Int32
server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -102,6 +105,7 @@ func TestSignerDiscovery(t *testing.T) {
{[]string{"metadata"}, "", 200, nil},
{[]string{"failed"}, "", 503, nil}, {[]string{"malformed"}, "", 503, nil},
{[]string{"truncated"}, "", 503, nil}, {[]string{"oversized"}, "", 503, nil},
{[]string{"max-size"}, "", 200, []string{"retained", "cpu"}},
{[]string{"denied", "failed", "malformed", "good"}, "", 200, []string{"retained", "cpu"}},
{[]string{"collected"}, "", 200, []string{"retained", "cpu"}},
{[]string{"lenient"}, "", 200, []string{"retained", "cpu"}},
Expand Down
Loading