Provider-Namen, Endpunkte aus der Umgebung, ein Modell zur Zeit, echte Erreichbarkeit
Vier Dinge, die zusammengehören: der Router soll sagen, WER bezahlt wird, er soll nicht
für jeden Schlüssel einen Block verlangen, er soll eine lokale Box nicht überfahren, und
er soll wissen, ob ein Ziel überhaupt da ist.
Namen: `cloud` heißt jetzt `opencode-go`, `cloud-free` heißt `opencode-go-free`. Ein Name,
der eine Betriebsform beschreibt („cloud"), sagt nichts darüber, wer die Rechnung
schickt. In der Live-Konfiguration und in allen Beispielen umbenannt, alle Verweise mit.
Schlüssel = Endpunkt (`auto_endpoints on`): OPENCODE_GO_API_KEY[_N] → opencode-go[N],
OLLAMA_KEY[_N] → ollama[N], ANTHROPIC_API_KEY oder CLAUDE_API_KEY[_N] → claude[N]. Die
Datei gewinnt, wo sie spricht; die Automatik füllt nur Lücken. <PROVIDER>_BASE biegt die
Basis um (für Tests und einen eigenen Proxy). Kein erfundener context: Grenzen gehören
den Modellen und kommen aus ihrer Liste. Eine Datei ohne Endpunkt-Blöcke ist damit
gültig, wenn die Umgebung sie liefert.
`max_model_inflight 1` am Endpunkt: eine Anfrage je (Endpunkt, Modell), der Rest wartet
in der Schlange. Gemessen mit einem 2-s-Stub: dasselbe Modell zweimal braucht 4 s (also
nacheinander), zwei verschiedene Modelle 2 s (also gleichzeitig). `strip "local/"` an der
Regel schneidet das Präfix ab, bevor die Anfrage den Router verlässt — auch im Rumpf, was
ohne `as_model` nur im Router passiert wäre; der Stub bestätigt, dass die Box
qwen3.6-35b sieht und nicht local/qwen3.6-35b. `strip` muss vor `pass` stehen, weil
`pass` die Zeile beendet.
Erreichbarkeit (`probe_interval`, `probe_timeout`, `probe off`): ein Hintergrundfaden
holt die Modellliste jedes Endpunkts. Entscheidend ist der TCP-Verbindungsaufbau, nicht
der Statuscode: `-w '%{time_connect}'` gleich 0 heißt unerreichbar. Beide falschen
Abkürzungen sind mir dabei passiert und beide sind jetzt ausgeschlossen — „jeder
curl-Fehler ist offline" nimmt langsame Ziele dauerhaft aus dem Verkehr, „nur 6/7 ist
offline" hält einen Host für gesund, der Pakete verwirft (die lokalen Ports auf
172.25.206.3 taten genau das: 28 nach Zeitablauf, also laut erster Regel „lebt").
Live: probe meldet lokal1–local4 und den lokalen opencode-Serve korrekt offline
(TCP kommt nicht zustande), eine Anfrage auf local/qwen3.6-35b antwortet in 1,7 s mit
`503 no_endpoint_available` statt nach 6 s in vier Verbindungszeitabläufe zu laufen.
Tests: drei neue Abschnitte (17 Prüfungen) — gleiches Modell 4 s, zwei Modelle 2 s,
Präfix weg; toter Endpunkt ohne Anfrage erkannt, Anfrage überspringt ihn in 1,2 ms, kommt
von selbst zurück, `probe off` hält ein Ziel heraus; Schlüssel aus der Umgebung ergeben
Endpunkte, OLLAMA_KEY2 wird ollama2 und nicht ein größerer Pool, `auto_endpoints off`
erfindet nichts. tests/run.sh räumt Provider-Variablen weg, sonst legt eine zufällig
gesetzte Variable in der Shell Endpunkte an, die kein Test erwartet.
make test: PASS, 249 Prüfungen, 174 s.
This commit is contained in:
1 parent
db422ba36d
commit
5f8ef9bab7
12 files changed
+823
-47
No files matched your search
@@ -531,6 +531,67 @@ after a reboot), and `prometheus-junction.yml`, the alert rules for `/metrics`
|
||||
(router down, endpoint unusable, heavy failover, a key near its budget, a peer cache
|
||||
that answers badly, a drain that never finishes).
|
||||
|
||||
## Providers from the environment
|
||||
|
||||
A key in the environment is an endpoint. No block needs to be written for it:
|
||||
|
||||
| variable | endpoint | base (override) |
|
||||
|---|---|---|
|
||||
| `OPENCODE_GO_API_KEY` [1…8] | `opencode-go` [`1`…`8`] | `https://opencode.ai/zen/go/v1` (`OPENCODE_GO_BASE`) |
|
||||
| `OLLAMA_KEY` [1…8] | `ollama` [`1`…`8`] | `https://ollama.com/v1` (`OLLAMA_BASE`) |
|
||||
| `ANTHROPIC_API_KEY` or `CLAUDE_API_KEY` [1…8] | `claude` [`1`…`8`] | `https://api.anthropic.com/v1` (`CLAUDE_BASE`) |
|
||||
|
||||
```conf
|
||||
auto_endpoints on # default; off disables the whole mechanism
|
||||
```
|
||||
|
||||
What the file already defines wins — the automatic endpoints only fill gaps, and the
|
||||
log names every one it adds (`endpoint ollama1 added from OLLAMA_KEY1 (base …)`). No
|
||||
`context` is invented: limits belong to the models and come from their own list. A
|
||||
config with no `endpoint` block at all is valid if the environment supplies one.
|
||||
The `<PROVIDER>_BASE` override exists for a local proxy and for tests.
|
||||
|
||||
## One request per model
|
||||
|
||||
```conf
|
||||
endpoint box {
|
||||
base http://172.25.206.3:8080/v1
|
||||
max_model_inflight 1
|
||||
}
|
||||
pool local box, box2, box3, box4
|
||||
|
||||
req for "local/*" strip "local/" pass local
|
||||
```
|
||||
|
||||
`max_model_inflight 1` means: one request at a time **per model name** on that endpoint;
|
||||
the next one waits in line instead of pushing a box that holds the model in memory into
|
||||
swap. Different models are different slots — four models are four parallel requests.
|
||||
The number is per (endpoint, model), so a pool of four boxes gives four slots.
|
||||
|
||||
`strip` removes a prefix before the request leaves the router: a client asks for
|
||||
`local/qwen3.6-35b`, the box receives `qwen3.6-35b` — in the body, in the pricing lookup
|
||||
and in the log. `strip` must stand before `pass`, because `pass` ends the line.
|
||||
|
||||
A request that waits for a model slot holds its `max_inflight` slot meanwhile; size
|
||||
`max_inflight` to at least (models × 1) plus room, or leave it generous for a local pool.
|
||||
|
||||
## Is the endpoint really there?
|
||||
|
||||
```conf
|
||||
probe_interval 20 # seconds between background checks (0 = off)
|
||||
probe_timeout 3 # per check
|
||||
# endpoint ... { probe off } # exclude one (sleeping box, a list that costs money)
|
||||
```
|
||||
|
||||
A background thread asks every endpoint for its model list (`GET <base>/models`). No
|
||||
answer (no TCP, no HTTP) means: offline for `offline_hold_s`, logged as `probe_offline`.
|
||||
The next round asks again, and a recovered endpoint is back before any request had to
|
||||
pay for the discovery (`probe_recovered`). A `4xx` counts as alive — a wrong key is a
|
||||
different problem than a machine that is off.
|
||||
|
||||
`/status` carries `probe_ok` and `probe_age_s` per endpoint, so "the router thinks it is
|
||||
down" and "the router has not looked yet" are distinguishable.
|
||||
|
||||
## Cluster: several instances, one port, one cache
|
||||
|
||||
No Redis, no etcd, no proxy in front — the cluster is two mechanisms, both optional.
|
||||
@@ -665,7 +726,13 @@ The latency histogram is pinned too: the `+Inf` bucket must carry the same count
|
||||
served requests, the buckets must be monotone (Prometheus computes quantiles from
|
||||
cumulative buckets — non-monotone ones produce nonsense, not an error), and `/status`
|
||||
must carry a `p95_ms`.
|
||||
Pass = `PASS` (232 checks), including two that would have caught the two mistakes this
|
||||
Three sections cover the local pool, the probe and the environment: two requests for the
|
||||
same model take 4 s together (one at a time), two different models take 2 s (parallel),
|
||||
and the box never sees the `local/` prefix — measured on the header the stub echoes.
|
||||
A dead endpoint is noticed by the background check without a request being sent to it,
|
||||
a request then skips it in 1.2 ms, and it is re-admitted by the next check once it
|
||||
answers again; `probe off` keeps an endpoint out of the checks entirely.
|
||||
Pass = `PASS` (249 checks), including two that would have caught the two mistakes this
|
||||
design invites: a serial stub making a concurrent router look serialised, and a
|
||||
"waiting" comment leaking into a caller that never asked for a stream.
|
||||
|
||||
|
||||
+23
-7
@@ -47,6 +47,22 @@ retry_max_wait 30
|
||||
# scrape the numbers here without reaching the model port (and /admin) at all.
|
||||
# metrics tcp 192.168.1.148:9180
|
||||
|
||||
# --- providers from the environment -------------------------------------------
|
||||
# A key is an endpoint: OLLAMA_KEY[_N] -> ollama[N], OPENCODE_GO_API_KEY[_N] ->
|
||||
# opencode-go[N], ANTHROPIC_API_KEY/_CLAUDE_API_KEY[_N] -> claude[N]. What this file
|
||||
# defines wins; the mechanism only fills gaps. <PROVIDER>_BASE overrides the base.
|
||||
# auto_endpoints on
|
||||
|
||||
# --- is it really there? ------------------------------------------------------
|
||||
# Background check: every N seconds GET <base>/models. No TCP connection = offline for
|
||||
# offline_hold_s, then checked again. A slow answer is not offline.
|
||||
# probe_interval 20
|
||||
# probe_timeout 3
|
||||
|
||||
# --- one request per model ----------------------------------------------------
|
||||
# endpoint box { base http://172.25.206.3:8080/v1; max_model_inflight 1 }
|
||||
# req for "local/*" strip "local/" pass box
|
||||
|
||||
# --- cluster, without a service in between -----------------------------------
|
||||
# Several instances may share one port, and each may hand its cache to the others.
|
||||
# so_reuseport on
|
||||
@@ -98,9 +114,9 @@ endpoint workstation {
|
||||
hook /opt/junction/hooks/check-budget.sh
|
||||
}
|
||||
|
||||
endpoint cloud {
|
||||
endpoint opencode-go {
|
||||
base https://api.example.com/v1
|
||||
kind cloud
|
||||
kind opencode-go
|
||||
# A fallback, not a truth: junction reads the model limits from the endpoint's own
|
||||
# model list at startup (GET /models -> limit.context / limit.output). This number
|
||||
# applies only when that fetch fails or the model is missing from it.
|
||||
@@ -108,7 +124,7 @@ endpoint cloud {
|
||||
priority 90
|
||||
timeout 900
|
||||
idle_timeout 120
|
||||
cache off # never store cloud answers
|
||||
cache off # never store opencode-go answers
|
||||
api_key_env EXAMPLE_API_KEY
|
||||
# A second account is a second quota: the line may be repeated. Each attempt takes
|
||||
# the next key, so a 429 on the first is answered with the second instead of giving
|
||||
@@ -135,7 +151,7 @@ endpoint cloud {
|
||||
# A virtual key is a token junction mints: the client sends it, the real upstream key
|
||||
# never leaves the process. allow/endpoints restrict what the key may use; rpm and
|
||||
# budget (USD per calendar month) limit what it may consume. Both optional.
|
||||
# vkey "webui" token_env VKEY_WEBUI allow "deepseek-*" endpoints "cloud,peer1" rpm 60 budget 10
|
||||
# vkey "webui" token_env VKEY_WEBUI allow "deepseek-*" endpoints "opencode-go,peer1" rpm 60 budget 10
|
||||
|
||||
# A caller without a key is routed as before - a vkey is accounting, not a door.
|
||||
|
||||
@@ -148,7 +164,7 @@ endpoint cloud {
|
||||
# A client that DECLARES more output than the peers can hold goes to the big box.
|
||||
# 'need' reads max_tokens from the request; there is no character counting and no
|
||||
# default, so a request that states nothing is not sized by guesswork.
|
||||
req need >64000 pass workstation, cloud
|
||||
req need >64000 pass workstation, opencode-go
|
||||
|
||||
# Coding work: prefer the workstation, wake it, wait up to 5 minutes for the hooks,
|
||||
# and hand it the model name it actually serves.
|
||||
@@ -156,7 +172,7 @@ req for "*coder*" check hooks retry 300 pass workstation as "Qwen3.8-Flash-Next-
|
||||
req for "Qwen3.8-Flash-Next*" check hooks retry 60 pass workstation, peer1, peer2
|
||||
|
||||
# Cheap metadata calls never need a model at all.
|
||||
req path "/v1/models" check none pass peer1, peer2, cloud
|
||||
req path "/v1/models" check none pass peer1, peer2, opencode-go
|
||||
|
||||
# Anything unseen is refused rather than silently sent to the cloud.
|
||||
# Anything unseen is refused rather than silently sent to the opencode-go.
|
||||
req for "*" block
|
||||
@@ -80,6 +80,50 @@ offline_wait 20
|
||||
metrics tcp 192.168.1.148:9180
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- providers from env
|
||||
#
|
||||
# A key in the environment is an endpoint, so that a host with three provider keys needs
|
||||
# no endpoint block at all:
|
||||
#
|
||||
# OPENCODE_GO_API_KEY[1..8] -> opencode-go, opencode-go1 … (OPENCODE_GO_BASE)
|
||||
# OLLAMA_KEY[1..8] -> ollama, ollama1 … (OLLAMA_BASE)
|
||||
# ANTHROPIC_API_KEY | CLAUDE_API_KEY [1..8]
|
||||
# -> claude, claude1 … (CLAUDE_BASE)
|
||||
#
|
||||
# The file always wins: an endpoint with the same name is not touched. No `context` is
|
||||
# invented — limits belong to the models and come from their own list. The base override
|
||||
# exists for a local proxy and for tests.
|
||||
auto_endpoints on
|
||||
|
||||
# ---------------------------------------------------------------- liveness
|
||||
#
|
||||
# A background thread asks every endpoint for its model list (GET <base>/models). No TCP
|
||||
# connection means offline for offline_hold_s; the next round asks again, so a returning
|
||||
# endpoint is back before any request had to pay for the discovery. A slow answer is not
|
||||
# offline: only a missing connection counts. `probe off` in an endpoint block keeps that
|
||||
# endpoint out of the checks (a box that sleeps on purpose).
|
||||
probe_interval 20
|
||||
probe_timeout 3
|
||||
|
||||
# ---------------------------------------------------------------- one request per model
|
||||
#
|
||||
# max_model_inflight 1 means: one request at a time per MODEL on this endpoint. The next
|
||||
# one waits instead of pushing a box that holds the model in memory into swap. Different
|
||||
# models are different slots — four models are four parallel requests. The limit is per
|
||||
# (endpoint, model), so a pool of four boxes gives four slots.
|
||||
#
|
||||
# endpoint box {
|
||||
# base http://172.25.206.3:8080/v1
|
||||
# timeout 600
|
||||
# max_model_inflight 1
|
||||
# }
|
||||
#
|
||||
# `strip` takes a prefix off the model before the request leaves the router: a client asks
|
||||
# for local/qwen3.6-35b, the box receives qwen3.6-35b. It must stand before `pass`,
|
||||
# because `pass` ends the line.
|
||||
#
|
||||
# req for "local/*" strip "local/" pass box
|
||||
|
||||
# ---------------------------------------------------------------- cluster
|
||||
#
|
||||
# Several instances on one port and one cache shared between them — no Redis, no
|
||||
@@ -197,13 +241,13 @@ spend_log /var/lib/junction/spend.jsonl
|
||||
# Endpoints
|
||||
# ============================================================================
|
||||
|
||||
# ---------------------------------------------------------------- subscription cloud
|
||||
# ---------------------------------------------------------------- subscription opencode-go
|
||||
#
|
||||
# The most expensive path per request, but already paid for: the marginal cost is
|
||||
# nearly zero. `cost` here is a comparison weight, not a sum of money.
|
||||
endpoint cloud {
|
||||
endpoint opencode-go {
|
||||
base https://opencode.ai/zen/go/v1
|
||||
kind cloud
|
||||
kind opencode-go
|
||||
context 200000
|
||||
|
||||
# Lower number wins when a rule names several targets without an order of its
|
||||
@@ -243,7 +287,7 @@ endpoint cloud {
|
||||
cache off
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------- credit cloud, two accounts
|
||||
# ---------------------------------------------------------------- credit opencode-go, two accounts
|
||||
#
|
||||
# Two accounts of the same provider, each with its own monthly credit. Both
|
||||
# endpoints look alike; they differ only in key, usage measurement and priority.
|
||||
@@ -252,7 +296,7 @@ endpoint cloud {
|
||||
endpoint ollama1 {
|
||||
weight 3
|
||||
base https://ollama.com/v1
|
||||
kind cloud
|
||||
kind opencode-go
|
||||
context 128000
|
||||
priority 50
|
||||
timeout 900
|
||||
@@ -275,7 +319,7 @@ endpoint ollama1 {
|
||||
|
||||
endpoint ollama2 {
|
||||
base https://ollama.com/v1
|
||||
kind cloud
|
||||
kind opencode-go
|
||||
# Two accounts as two endpoints: that keeps the quota per account visible
|
||||
# (usage_cmd 1 vs. 2). As one endpoint with two api_key_env lines junction would
|
||||
# rotate to the second account on a 429, but usage_cmd and /api/show would only
|
||||
@@ -406,7 +450,7 @@ endpoint embed {
|
||||
# local id, the last the requested one.
|
||||
|
||||
# Model list: no hook needed, a sleeping machine answers it too.
|
||||
req path "/v1/models" check none pass cloud
|
||||
req path "/v1/models" check none pass opencode-go
|
||||
|
||||
# Embedders run locally, no matter what else applies.
|
||||
req for "*embed*" check none pass embed
|
||||
@@ -416,43 +460,43 @@ req for "opencode/*" pass opencode
|
||||
req for "*-free" pass opencode
|
||||
|
||||
# Image requests: always to the image model, independent of the requested name.
|
||||
# First the own machine (costs nothing), then the cloud — there with a rewritten
|
||||
# First the own machine (costs nothing), then the opencode-go — there with a rewritten
|
||||
# model name. "as" applies to the target directly before it, not to the whole rule.
|
||||
req vision pass workstation, cloud as "vision-capable-model"
|
||||
req vision pass workstation, opencode-go as "vision-capable-model"
|
||||
|
||||
# Small requests to the own machine, medium ones to the credit account, large ones to
|
||||
# the subscription with the big context. Order matters: narrowest window first,
|
||||
# otherwise the larger one catches everything. The numbers are policy and belong
|
||||
# here, not in the code.
|
||||
req ctx <2000 pass workstation
|
||||
req ctx <50000 pass ollama1, cloud
|
||||
req ctx >50000 pass cloud
|
||||
req ctx <50000 pass ollama1, opencode-go
|
||||
req ctx >50000 pass opencode-go
|
||||
|
||||
# Large budgets cannot be held by the local machine — so do not send them there.
|
||||
req need >64000 pass cloud, ollama1
|
||||
req need >64000 pass opencode-go, ollama1
|
||||
|
||||
# A model that only exists locally, with a local name; otherwise the same request is
|
||||
# passed on to the cloud.
|
||||
req for "*coder*" retry 300 pass workstation as "qwen3.8-flash-next-q1m", cloud
|
||||
# passed on to the opencode-go.
|
||||
req for "*coder*" retry 300 pass workstation as "qwen3.8-flash-next-q1m", opencode-go
|
||||
|
||||
# A model that must not exist. 403, not a silent redirect.
|
||||
req for "blocked-*" block
|
||||
|
||||
# Everything else: first the awake local machine, then the cloud, then credits.
|
||||
# Everything else: first the awake local machine, then the opencode-go, then credits.
|
||||
# No match for a request means 503 no_matching_rule — a gap in the configuration is
|
||||
# not a case for "send it somewhere".
|
||||
# Give chains a name. A pool may point at another pool; it is resolved at load time,
|
||||
# so a rule does not have to spell out five targets every time.
|
||||
pool lokal ollama1, ollama2
|
||||
pool alles cloud, lokal
|
||||
pool alles opencode-go, lokal
|
||||
|
||||
# An endpoint may also fit on one line when it is small:
|
||||
# endpoint kurz { base http://127.0.0.1:8080/v1; timeout 60 }
|
||||
|
||||
# This one rule wants plain failover, whatever the global setting is.
|
||||
req for "starr*" balance first pass workstation, cloud
|
||||
req for "starr*" balance first pass workstation, opencode-go
|
||||
|
||||
req for "*" check hooks pass workstation, cloud, ollama1, ollama2
|
||||
req for "*" check hooks pass workstation, opencode-go, ollama1, ollama2
|
||||
|
||||
|
||||
# ============================================================================
|
||||
|
||||
+14
-14
@@ -107,13 +107,13 @@ endpoint desk {
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# The cloud. Last resort for context that does not fit, models the van does not
|
||||
# The opencode-go. Last resort for context that does not fit, models the van does not
|
||||
# have, and anything the local boxes refuse. Key never lives in this file.
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
endpoint cloud {
|
||||
endpoint opencode-go {
|
||||
base https://opencode.ai/zen/go/v1
|
||||
kind cloud
|
||||
kind opencode-go
|
||||
context 200000
|
||||
priority 90
|
||||
timeout 900
|
||||
@@ -129,9 +129,9 @@ endpoint cloud {
|
||||
# ===========================================================================
|
||||
|
||||
# Metadata calls are cheap and must never wake anything.
|
||||
req path "/v1/models" check none pass peer-a, peer-b, cloud
|
||||
req path "/v1/models" check none pass peer-a, peer-b, opencode-go
|
||||
|
||||
# Embeddings stay local. No cloud fallback: a travelling text does not belong
|
||||
# Embeddings stay local. No opencode-go fallback: a travelling text does not belong
|
||||
# in a request to a third party, and the local box has the model.
|
||||
req for "*embed*" check none pass kitt-embed
|
||||
|
||||
@@ -139,24 +139,24 @@ req for "*embed*" check none pass kitt-embed
|
||||
# candidate. "need" only ever reads max_tokens/max_completion_tokens from the request:
|
||||
# no character counting, no assumed default — a request that states no budget matches
|
||||
# this rule not at all, and the router does not pretend to know its size.
|
||||
req need >65536 pass desk, cloud
|
||||
req need >65536 pass desk, opencode-go
|
||||
|
||||
# Coding work wants the big context local box; the workstation gets woken for it,
|
||||
# then the peers, then (reluctantly) the cloud.
|
||||
req for "*coder*" check hooks retry 300 pass desk, peer-a, peer-b, cloud
|
||||
# then the peers, then (reluctantly) the opencode-go.
|
||||
req for "*coder*" check hooks retry 300 pass desk, peer-a, peer-b, opencode-go
|
||||
|
||||
# The peers answer to a different id than clients ask for: "as <model>" after a target
|
||||
# rewrites the model field for THAT target only, so the cloud still gets the name the
|
||||
# rewrites the model field for THAT target only, so the opencode-go still gets the name the
|
||||
# client asked for.
|
||||
req for "Qwen3.8-Flash-Next*" retry 60 pass peer-a, peer-b, cloud
|
||||
req for "Qwen3.8-Flash-Next*" retry 60 pass peer-a, peer-b, opencode-go
|
||||
|
||||
# Anything with the local-only prefix never leaves the van, and if the vans own
|
||||
# boxes are down the request fails loudly instead of going out.
|
||||
req for "local-only-*" pass peer-a, peer-b
|
||||
|
||||
# Cloud-only model ids.
|
||||
req for "deepseek-*" pass cloud
|
||||
req for "gpt-*" pass cloud
|
||||
req for "deepseek-*" pass opencode-go
|
||||
req for "gpt-*" pass opencode-go
|
||||
|
||||
# A model that must never be called at all. Refused with 403 and the rule's line
|
||||
# number, which is the fastest way to answer "why is this not working?".
|
||||
@@ -164,6 +164,6 @@ req for "blocked-*" block
|
||||
|
||||
# Everything else: local first. Because a single-model box hangs on an id it does not
|
||||
# know, the catch-all hands it the id that is really loaded — the client may ask for
|
||||
# whatever it likes, the van answers with what it has. The cloud keeps the client's
|
||||
# whatever it likes, the van answers with what it has. The opencode-go keeps the client's
|
||||
# own name and is only reached when nothing local answers.
|
||||
req for "*" pass peer-a as "Qwen3.8-Flash-Next-GSQ-RCO-IQ1_M", peer-b as "Qwen3.8-Flash-Next-GSQ-RCO-IQ1_M", desk, cloud
|
||||
req for "*" pass peer-a as "Qwen3.8-Flash-Next-GSQ-RCO-IQ1_M", peer-b as "Qwen3.8-Flash-Next-GSQ-RCO-IQ1_M", desk, opencode-go
|
||||
+134
-1
@@ -93,6 +93,9 @@ void j_config_defaults(j_config *cfg)
|
||||
cfg->cache_deterministic_only = 1;
|
||||
cfg->cache_peer_timeout_ms = 150;
|
||||
cfg->drain_timeout_s = 15.0;
|
||||
cfg->auto_endpoints = 1;
|
||||
cfg->probe_interval_s = 20.0;
|
||||
cfg->probe_timeout_s = 3.0;
|
||||
snprintf(cfg->prices_path, sizeof cfg->prices_path, "/etc/junction/prices.conf");
|
||||
cfg->compress = J_COMPRESS_OFF;
|
||||
cfg->compress_keep = 4;
|
||||
@@ -120,6 +123,7 @@ static void endpoint_defaults(j_endpoint *ep)
|
||||
ep->hook_backoff_s = 5;
|
||||
ep->last_ms = -1;
|
||||
ep->tls_verify = 1;
|
||||
ep->probe_on = 1; /* Erreichbarkeit prüfen: ja, außer ausdrücklich abgewählt */
|
||||
ep->cache_on = -1;
|
||||
ep->on_hard_skip = 1; /* ein erschoepftes Budget wird uebersprungen, nicht benutzt */
|
||||
ep->offpeak_from = -1;
|
||||
@@ -303,6 +307,33 @@ static int global_kw(j_config *cfg, char **w, int n, int lineno, char *err, size
|
||||
}
|
||||
goto bad;
|
||||
}
|
||||
if (!strcmp(k, "probe_interval")) {
|
||||
/* probe_interval 20 (0 = keine Prüfung)
|
||||
* Jeder Endpunkt wird im Hintergrund abgefragt: antwortet er nicht, geht er für
|
||||
* offline_hold_s offline und wird danach weiter geprüft. Ein toter Peer kostet
|
||||
* so keine Anfrage mehr, sondern nur einen Platz in der Schlange. */
|
||||
if (n != 2 || as_double(w[1], &cfg->probe_interval_s)) goto bad;
|
||||
if (cfg->probe_interval_s < 0 || cfg->probe_interval_s > 3600) goto bad;
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(k, "probe_timeout")) {
|
||||
if (n != 2 || as_double(w[1], &cfg->probe_timeout_s)) goto bad;
|
||||
if (cfg->probe_timeout_s <= 0 || cfg->probe_timeout_s > 60) goto bad;
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(k, "auto_endpoints")) {
|
||||
/* auto_endpoints on|off
|
||||
*
|
||||
* Ein Schlüssel in der Umgebung ist ein Provider: OLLAMA_KEY[_N] → ollama[N],
|
||||
* OPENCODE_GO_API_KEY[_N] → opencode-go[N], ANTHROPIC_API_KEY[_N] oder
|
||||
* CLAUDE_API_KEY[_N] → claude[N]. Was in der Datei schon steht, bleibt
|
||||
* unangetastet — die Automatik füllt Lücken, sie überschreibt nichts. */
|
||||
if (n != 2) goto bad;
|
||||
if (!strcmp(w[1], "on")) cfg->auto_endpoints = 1;
|
||||
else if (!strcmp(w[1], "off")) cfg->auto_endpoints = 0;
|
||||
else goto bad;
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(k, "so_reuseport")) {
|
||||
/* so_reuseport on
|
||||
*
|
||||
@@ -613,6 +644,23 @@ static int endpoint_kw(j_endpoint *ep, char **w, int n, int lineno, char *err, s
|
||||
else goto bad;
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(k, "probe")) {
|
||||
/* probe off — dieser Endpunkt wird nicht geprüft (schlafende Box, bezahlte
|
||||
* Listen). Standard ist an. */
|
||||
if (n != 2) goto bad;
|
||||
if (!strcmp(w[1], "on")) ep->probe_on = 1;
|
||||
else if (!strcmp(w[1], "off")) ep->probe_on = 0;
|
||||
else goto bad;
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(k, "max_model_inflight")) {
|
||||
/* max_model_inflight 1 — eine Anfrage je Modell gleichzeitig, der Rest wartet.
|
||||
* Für Boxen gedacht, die ein Modell im Speicher halten: die zweite Anfrage
|
||||
* würde sie in den Swap treiben, nicht schneller machen. */
|
||||
if (n != 2 || as_int(w[1], &ep->max_model_inflight)) goto bad;
|
||||
if (ep->max_model_inflight < 0) goto bad;
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(k, "header")) {
|
||||
/* header "X-Name: value" — repeatable; forwarded on every request to this endpoint */
|
||||
if (n < 2) goto bad;
|
||||
@@ -746,6 +794,13 @@ static int parse_rule(char **w, int n, int lineno, j_rule *r, char *err, size_t
|
||||
} else if (!strcmp(k, "retry")) {
|
||||
if (i + 1 >= n || as_double(w[i + 1], &r->retry_s)) goto bad;
|
||||
i += 2;
|
||||
} else if (!strcmp(k, "strip")) {
|
||||
/* strip "local/" — das Präfix fällt vor dem Weiterleiten vom Modellnamen.
|
||||
* Damit kann ein Client local/qwen3.6-35b verlangen und die Box bekommt
|
||||
* qwen3.6-35b, ohne dass die Regel jedes Modell einzeln aufzählen muss. */
|
||||
if (i + 1 >= n) goto bad;
|
||||
snprintf(r->strip, sizeof r->strip, "%s", w[i + 1]);
|
||||
i += 2;
|
||||
} else if (!strcmp(k, "block")) {
|
||||
r->block = 1;
|
||||
i++;
|
||||
@@ -796,6 +851,76 @@ bad:
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Ein Schlüssel in der Umgebung ist ein Provider.
|
||||
*
|
||||
* Wer OLLAMA_KEY1 setzt, will ollama1 benutzen — ohne dafür einen Endpunkt-Block zu
|
||||
* schreiben. Die Namen folgen der Variablen (ollama1, opencode-go, claude2), die Basis
|
||||
* ist der veröffentlichte Endpunkt des Anbieters und lässt sich über <PROVIDER>_BASE
|
||||
* umbiegen (für Tests und für einen eigenen Proxy). Grenzen (context/output) stehen
|
||||
* bewusst NICHT hier: sie gehören den Modellen und kommen aus deren Liste.
|
||||
*/
|
||||
typedef struct {
|
||||
const char *env; /* Präfix der Variablen */
|
||||
const char *name; /* Endpunktname ohne Nummer */
|
||||
const char *base; /* Standard-Basis */
|
||||
const char *base_env; /* Überschreibung der Basis */
|
||||
const char *header; /* zusätzliche Kopfzeile, "" = keine */
|
||||
int priority;
|
||||
} env_provider;
|
||||
|
||||
static const env_provider ENV_PROVIDERS[] = {
|
||||
{ "OPENCODE_GO_API_KEY", "opencode-go", "https://opencode.ai/zen/go/v1",
|
||||
"OPENCODE_GO_BASE", "", 90 },
|
||||
{ "OLLAMA_KEY", "ollama", "https://ollama.com/v1", "OLLAMA_BASE", "", 50 },
|
||||
{ "ANTHROPIC_API_KEY", "claude", "https://api.anthropic.com/v1",
|
||||
"CLAUDE_BASE", "anthropic-version: 2023-06-01", 70 },
|
||||
{ "CLAUDE_API_KEY", "claude", "https://api.anthropic.com/v1",
|
||||
"CLAUDE_BASE", "anthropic-version: 2023-06-01", 70 },
|
||||
};
|
||||
|
||||
static int endpoint_named(const j_config *cfg, const char *name)
|
||||
{
|
||||
for (int i = 0; i < cfg->endpoint_count; i++)
|
||||
if (!strcmp(cfg->endpoints[i].name, name)) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void auto_endpoints(j_config *cfg)
|
||||
{
|
||||
if (!cfg->auto_endpoints) return;
|
||||
for (size_t p = 0; p < sizeof ENV_PROVIDERS / sizeof ENV_PROVIDERS[0]; p++) {
|
||||
const env_provider *pr = &ENV_PROVIDERS[p];
|
||||
/* Ohne Nummer und mit 1 … 8: OLLAMA_KEY, OLLAMA_KEY1, … */
|
||||
for (int slot = 0; slot <= 8; slot++) {
|
||||
char var[J_NAME_MAX], name[J_NAME_MAX];
|
||||
if (slot == 0) snprintf(var, sizeof var, "%s", pr->env);
|
||||
else snprintf(var, sizeof var, "%s%d", pr->env, slot);
|
||||
const char *val = getenv(var);
|
||||
if (!val || !*val) continue;
|
||||
if (slot == 0) snprintf(name, sizeof name, "%s", pr->name);
|
||||
else snprintf(name, sizeof name, "%s%d", pr->name, slot);
|
||||
if (endpoint_named(cfg, name)) continue; /* Datei gewinnt */
|
||||
if (cfg->endpoint_count >= J_MAX_ENDPOINTS) return;
|
||||
j_endpoint *ep = &cfg->endpoints[cfg->endpoint_count++];
|
||||
endpoint_defaults(ep);
|
||||
snprintf(ep->name, sizeof ep->name, "%s", name);
|
||||
const char *base = getenv(pr->base_env);
|
||||
snprintf(ep->base, sizeof ep->base, "%s",
|
||||
(base && *base) ? base : pr->base);
|
||||
snprintf(ep->kind, sizeof ep->kind, "cloud");
|
||||
ep->priority = pr->priority;
|
||||
ep->timeout_s = 900;
|
||||
ep->idle_timeout_s = 120;
|
||||
snprintf(ep->api_key_env[0], sizeof ep->api_key_env[0], "%s", var);
|
||||
ep->key_env_count = 1;
|
||||
if (pr->header[0] && ep->header_count < J_MAX_EP_HEADERS)
|
||||
snprintf(ep->headers[ep->header_count++], J_HDR_LINE_MAX, "%s", pr->header);
|
||||
fprintf(stderr, "[%s] endpoint %s added from %s (base %s)\n",
|
||||
cfg->log_prefix, name, var, ep->base);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int j_config_load(const char *path, j_config *cfg, char *err, size_t errlen)
|
||||
{
|
||||
FILE *fh = fopen(path, "r");
|
||||
@@ -1023,8 +1148,16 @@ int j_config_load(const char *path, j_config *cfg, char *err, size_t errlen)
|
||||
snprintf(err, errlen, "endpoint %s: block not closed with '}'", cur->name);
|
||||
return -1;
|
||||
}
|
||||
/* Provider aus der Umgebung, bevor geprüft wird: eine Datei ohne Endpunkt-Blöcke ist
|
||||
* gültig, wenn die Schlüssel sie liefern. */
|
||||
auto_endpoints(cfg);
|
||||
if (!cfg->endpoint_count) {
|
||||
snprintf(err, errlen, "no 'endpoint NAME {' blocks in %s", path);
|
||||
if (!cfg->auto_endpoints)
|
||||
snprintf(err, errlen, "no 'endpoint NAME {' blocks in %s (auto_endpoints is off)",
|
||||
path);
|
||||
else
|
||||
snprintf(err, errlen, "no 'endpoint NAME {' blocks in %s and no provider key "
|
||||
"in the environment", path);
|
||||
return -1;
|
||||
}
|
||||
for (int i = 0; i < cfg->endpoint_count; i++) {
|
||||
|
||||
@@ -166,6 +166,16 @@ typedef struct {
|
||||
* einen Bildaufruf, der es stillschweigend als leeren Text beantwortet. */
|
||||
int vision;
|
||||
|
||||
/* Wie viele Anfragen DESSELBE Modell an diesem Endpunkt gleichzeitig bedienen darf.
|
||||
* 0 = unbegrenzt (Standard). 1 heißt: eine lokale Box, die ein Modell im Speicher
|
||||
* hält, bekommt genau eine Anfrage; die nächste wartet in der Schlange, statt die
|
||||
* Box in den Swap zu treiben. Vier Modelle sind dann vier parallele Anfragen. */
|
||||
int max_model_inflight;
|
||||
|
||||
/* 1 = dieser Endpunkt wird geprüft (Standard), 0 = nicht (z. B. ein Ziel, dessen
|
||||
* /models Geld kostet oder das absichtlich schläft). */
|
||||
int probe_on;
|
||||
|
||||
/* runtime state — not from the file */
|
||||
double offline_until;
|
||||
double cooldown_until;
|
||||
@@ -185,6 +195,8 @@ typedef struct {
|
||||
unsigned long lat_bucket[J_LAT_BUCKETS + 1]; /* letzter Eimer: +Inf */
|
||||
unsigned long lat_n;
|
||||
double lat_sum_s;
|
||||
int probe_ok; /* letzte Prüfung: 1 = antwortet */
|
||||
double probe_at; /* wann zuletzt geprüft */
|
||||
char last_error[256];
|
||||
char last_hook_reason[256];
|
||||
|
||||
@@ -228,6 +240,9 @@ typedef struct {
|
||||
* different ids ("Qwen3.8-Flash-Next" is loaded as "qwen3.8-flash-next-q1m"), so
|
||||
* the rewrite belongs to the target, not to the rule. */
|
||||
char target_as[J_MAX_TARGETS][J_GLOB_MAX];
|
||||
/* Präfix, das vor dem Weiterleiten vom Modellnamen fällt: `strip "local/"` macht aus
|
||||
* local/qwen3.6-35b das qwen3.6-35b, das die Box kennt. */
|
||||
char strip[J_NAME_MAX];
|
||||
int target_count;
|
||||
int line;
|
||||
} j_rule;
|
||||
@@ -298,6 +313,17 @@ typedef struct {
|
||||
int so_reuseport;
|
||||
double drain_timeout_s;
|
||||
|
||||
/* Provider aus der Umgebung: wer OLLAMA_KEY (oder _1 …) setzt, hat einen Endpunkt.
|
||||
* Abschaltbar, weil eine automatisch angelegte Quelle auch überraschen kann. */
|
||||
int auto_endpoints;
|
||||
|
||||
/* Erreichbarkeit prüfen, nicht nur beim ersten Fehler: ein Hintergrundfaden holt
|
||||
* alle probe_interval_s die Modellliste jedes Endpunkts mit kurzem Zeitablauf. Ein
|
||||
* Endpunkt, der nicht antwortet, geht für offline_hold_s offline und wird danach
|
||||
* weiter geprüft — ohne dass eine Anfrage dafür bezahlen muss. 0 = aus. */
|
||||
double probe_interval_s;
|
||||
double probe_timeout_s;
|
||||
|
||||
/* Zeichen pro Token für die Prompt-Schätzung. 0 = aus, dann kann keine Regel eine
|
||||
* ctx-Bedingung tragen. Der Wert ist eine Annahme über die Tokenisierung, keine
|
||||
* Messung — deshalb steht er in der Konfiguration und nicht im Code. */
|
||||
|
||||
+221
-5
@@ -131,6 +131,89 @@ static double lat_p95_ms(const j_endpoint *ep)
|
||||
return -1.0; /* nur im +Inf-Eimer: keine Aussage außer "über 60 s" */
|
||||
}
|
||||
|
||||
/* Ein Platz je (Endpunkt, Modell). Eine Box, die ein Modell geladen hält, bedient es
|
||||
* einmal gleichzeitig; die zweite Anfrage wartet, statt die Maschine in den Swap zu
|
||||
* treiben. Vier Modelle sind damit vier parallele Anfragen — ohne dass jemand
|
||||
* Konfiguration nachzählt: max_model_inflight steht am Endpunkt. */
|
||||
#define MODEL_SLOTS 64
|
||||
|
||||
static double now_s(void);
|
||||
|
||||
static struct {
|
||||
pthread_mutex_t mu;
|
||||
pthread_cond_t cv;
|
||||
struct { char ep[J_NAME_MAX]; char model[J_GLOB_MAX]; int n; } slot[MODEL_SLOTS];
|
||||
} MODEL_GATE = { .mu = PTHREAD_MUTEX_INITIALIZER, .cv = PTHREAD_COND_INITIALIZER };
|
||||
|
||||
static int model_gate_acquire(const char *ep, const char *model, int limit, double timeout_s)
|
||||
{
|
||||
if (limit <= 0) return 0;
|
||||
double deadline = now_s() + timeout_s;
|
||||
int idx = -1;
|
||||
pthread_mutex_lock(&MODEL_GATE.mu);
|
||||
for (;;) {
|
||||
int free_slot = -1, current = 0;
|
||||
for (int i = 0; i < MODEL_SLOTS; i++) {
|
||||
if (MODEL_GATE.slot[i].ep[0] &&
|
||||
!strcmp(MODEL_GATE.slot[i].ep, ep) &&
|
||||
!strcmp(MODEL_GATE.slot[i].model, model)) {
|
||||
idx = i;
|
||||
current = MODEL_GATE.slot[i].n;
|
||||
break;
|
||||
}
|
||||
if (!MODEL_GATE.slot[i].ep[0] && free_slot < 0) free_slot = i;
|
||||
}
|
||||
if (current < limit) {
|
||||
if (idx < 0) {
|
||||
if (free_slot < 0) { /* Tabelle voll: nicht blockieren */
|
||||
pthread_mutex_unlock(&MODEL_GATE.mu);
|
||||
return 0;
|
||||
}
|
||||
idx = free_slot;
|
||||
snprintf(MODEL_GATE.slot[idx].ep, sizeof MODEL_GATE.slot[idx].ep, "%s", ep);
|
||||
snprintf(MODEL_GATE.slot[idx].model, sizeof MODEL_GATE.slot[idx].model,
|
||||
"%s", model);
|
||||
MODEL_GATE.slot[idx].n = 0;
|
||||
}
|
||||
MODEL_GATE.slot[idx].n++;
|
||||
pthread_mutex_unlock(&MODEL_GATE.mu);
|
||||
return 0;
|
||||
}
|
||||
double left = deadline - now_s();
|
||||
if (left <= 0) {
|
||||
pthread_mutex_unlock(&MODEL_GATE.mu);
|
||||
return -1;
|
||||
}
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
double step = left < 1.0 ? left : 1.0;
|
||||
ts.tv_sec += (time_t)step;
|
||||
ts.tv_nsec += (long)((step - (time_t)step) * 1e9);
|
||||
if (ts.tv_nsec >= 1000000000L) { ts.tv_sec++; ts.tv_nsec -= 1000000000L; }
|
||||
pthread_cond_timedwait(&MODEL_GATE.cv, &MODEL_GATE.mu, &ts);
|
||||
idx = -1;
|
||||
}
|
||||
}
|
||||
|
||||
static void model_gate_release(const char *ep, const char *model, int limit)
|
||||
{
|
||||
if (limit <= 0) return;
|
||||
pthread_mutex_lock(&MODEL_GATE.mu);
|
||||
for (int i = 0; i < MODEL_SLOTS; i++) {
|
||||
if (MODEL_GATE.slot[i].ep[0] && !strcmp(MODEL_GATE.slot[i].ep, ep) &&
|
||||
!strcmp(MODEL_GATE.slot[i].model, model)) {
|
||||
if (--MODEL_GATE.slot[i].n <= 0) {
|
||||
MODEL_GATE.slot[i].ep[0] = '\0';
|
||||
MODEL_GATE.slot[i].model[0] = '\0';
|
||||
MODEL_GATE.slot[i].n = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
pthread_cond_broadcast(&MODEL_GATE.cv);
|
||||
pthread_mutex_unlock(&MODEL_GATE.mu);
|
||||
}
|
||||
|
||||
static double now_s(void)
|
||||
{
|
||||
struct timespec ts;
|
||||
@@ -721,7 +804,8 @@ static char *build_status(size_t *len_out)
|
||||
used += (size_t)snprintf(out + used, cap - used,
|
||||
"%s{\"name\":\"%s\",\"base\":\"%s\",\"kind\":\"%s\",\"context\":%ld,"
|
||||
"\"priority\":%d,\"paused\":%s,\"inflight\":%d,\"ok\":%lu,\"fail\":%lu,"
|
||||
"\"last_ms\":%ld,\"p95_ms\":%.0f,\"offline_s\":%d,\"cooldown_s\":%d,"
|
||||
"\"last_ms\":%ld,\"p95_ms\":%.0f,\"probe_ok\":%d,\"probe_age_s\":%.0f,"
|
||||
"\"offline_s\":%d,\"cooldown_s\":%d,"
|
||||
"\"usage_percent\":%.2f,\"usage_used_usd\":%.2f,\"usage_budget_usd\":%.2f,"
|
||||
"\"usage_ok\":%d,\"exhausted\":%d,\"budget_soft\":%.0f,\"budget_hard\":%.0f,"
|
||||
"\"offpeak\":%d,\"cost\":%.2f,\"hooks\":%d,\"keys\":%d,"
|
||||
@@ -729,7 +813,8 @@ static char *build_status(size_t *len_out)
|
||||
"\"last_error\":\"%s\",\"last_hook_reason\":\"%s\"}",
|
||||
i ? "," : "", ep->name, ep->base, ep->kind, ep->context, ep->priority,
|
||||
ep->paused ? "true" : "false", ep->inflight, ep->ok_count, ep->fail_count,
|
||||
ep->last_ms, lat_p95_ms(ep),
|
||||
ep->last_ms, lat_p95_ms(ep), ep->probe_ok,
|
||||
ep->probe_at > 0 ? t - ep->probe_at : -1.0,
|
||||
(int)(ep->offline_until > t ? ep->offline_until - t : 0),
|
||||
(int)(ep->cooldown_until > t ? ep->cooldown_until - t : 0),
|
||||
ep->usage_percent, ep->usage_used_usd, ep->usage_budget_usd,
|
||||
@@ -3187,6 +3272,15 @@ static void handle_client(j_conn *client)
|
||||
}
|
||||
|
||||
double queue_started = now_s();
|
||||
/* `strip "local/"`: der Client darf local/qwen3.6-35b verlangen, die Box bekommt
|
||||
* qwen3.6-35b. Das Präfix ist eine Adresse, kein Modellname — es fällt hier weg,
|
||||
* bevor irgendetwas weitergeleitet, bepreist oder geloggt wird. */
|
||||
const char *eff_model = model;
|
||||
{
|
||||
size_t sl = strlen(rule->strip);
|
||||
if (sl && !strncmp(model, rule->strip, sl)) eff_model = model + sl;
|
||||
}
|
||||
|
||||
int slot_rc = slot_acquire(client, head_sent, CFG.queue_timeout_s,
|
||||
streaming ? "stream" : "request");
|
||||
t_queue_ms = (long)((now_s() - queue_started) * 1000.0);
|
||||
@@ -3245,7 +3339,7 @@ static void handle_client(j_conn *client)
|
||||
/* Die Grenze des *Modells* schlägt die des Endpunkts: ein Anbieter mit
|
||||
* mehreren Modellen veröffentlicht pro Modell eine eigene Zahl. Ein "as"
|
||||
* schreibt den Namen um, also gilt der Name, den der Endpunkt sieht. */
|
||||
const char *ep_model = rule->target_as[t][0] ? rule->target_as[t] : model;
|
||||
const char *ep_model = rule->target_as[t][0] ? rule->target_as[t] : eff_model;
|
||||
long mctx = j_models_limit(ep, ep_model, 0);
|
||||
long mout = j_models_limit(ep, ep_model, 1);
|
||||
long ep_ctx = mctx > 0 ? mctx : ep->context;
|
||||
@@ -3280,15 +3374,29 @@ static void handle_client(j_conn *client)
|
||||
struct timespec nap = { .tv_sec = 0, .tv_nsec = 100 * 1000 * 1000 };
|
||||
while (now_s() < until) nanosleep(&nap, NULL);
|
||||
}
|
||||
/* Ein Platz je (Endpunkt, Modell): eine Box, die dieses Modell geladen hält,
|
||||
* bedient es einmal. Der Rest wartet hier — nicht in der Box. */
|
||||
const char *gate_model = rule->target_as[t][0] ? rule->target_as[t] : eff_model;
|
||||
int gate_on = ep->max_model_inflight > 0;
|
||||
if (gate_on &&
|
||||
model_gate_acquire(ep->name, gate_model, ep->max_model_inflight,
|
||||
CFG.queue_timeout_s) != 0) {
|
||||
jlog("model_queue_timeout", "endpoint=%s model=%s limit=%d wait_s=%.0f",
|
||||
ep->name, gate_model, ep->max_model_inflight, CFG.queue_timeout_s);
|
||||
snprintf(err, sizeof err, "model_busy_%s", ep->name);
|
||||
strncat(attempts, " busy", sizeof attempts - strlen(attempts) - 1);
|
||||
continue;
|
||||
}
|
||||
STATE_LOCK();
|
||||
ep->inflight++;
|
||||
STATE_UNLOCK();
|
||||
if (!strcmp(ep->kind, "opencode")) {
|
||||
/* Kein OpenAI-Protokoll: die Brücke übersetzt Anfrage und Antwort. */
|
||||
int brc = opencode_serve(client, ep, &rq, rule->target_as[t][0] ? rule->target_as[t] : model,
|
||||
int brc = opencode_serve(client, ep, &rq, rule->target_as[t][0] ? rule->target_as[t] : eff_model,
|
||||
err, sizeof err);
|
||||
STATE_LOCK();
|
||||
ep->inflight--;
|
||||
if (gate_on) model_gate_release(ep->name, gate_model, ep->max_model_inflight);
|
||||
if (brc == 0) {
|
||||
ep->ok_count++;
|
||||
g_req_ok++;
|
||||
@@ -3319,11 +3427,18 @@ static void handle_client(j_conn *client)
|
||||
g_compress_bytes_out += cstat.bytes_out;
|
||||
}
|
||||
t_rule_line = rule->line;
|
||||
int rc = forward_with_retry(client, ep, &rq, send_body, send_len, rule->target_as[t], model,
|
||||
/* Ein "as" der Regel gewinnt; sonst muss ein abgeschnittenes Präfix den Rumpf
|
||||
* umschreiben, sonst steht der Name nur im Router anders da als bei der Box. */
|
||||
const char *send_model = rule->target_as[t][0] ? rule->target_as[t]
|
||||
: (eff_model != model ? eff_model : "");
|
||||
int rc = forward_with_retry(client, ep, &rq, send_body, send_len, send_model, eff_model,
|
||||
may_cache ? "miss" : "off", started, head_sent,
|
||||
vk ? vk->name : "", err, sizeof err);
|
||||
STATE_LOCK();
|
||||
ep->inflight--;
|
||||
STATE_UNLOCK();
|
||||
if (gate_on) model_gate_release(ep->name, gate_model, ep->max_model_inflight);
|
||||
STATE_LOCK();
|
||||
if (rc == 0) {
|
||||
ep->ok_count++;
|
||||
ep->last_ms = (long)((now_s() - started) * 1000.0);
|
||||
@@ -3462,6 +3577,100 @@ static int make_listener(const j_config *cfg, char *err, size_t errlen)
|
||||
return lfd;
|
||||
}
|
||||
|
||||
/* Erreichbarkeit im Hintergrund prüfen.
|
||||
*
|
||||
* Ein Anfragepfad soll nicht der erste sein, der merkt, dass eine Box weg ist: hier
|
||||
* wird jeder Endpunkt alle probe_interval_s gefragt (GET <base>/models, kurzer
|
||||
* Zeitablauf). Antwortet er nicht — kein TCP, kein HTTP —, geht er für offline_hold_s
|
||||
* offline, und der nächste Lauf prüft weiter. Antwortet er wieder, ist er sofort
|
||||
* zurück, ohne dass jemand eine Anfrage dafür verschwenden musste.
|
||||
*
|
||||
* 4xx zählt als erreichbar: ein 401 heißt "falscher Schlüssel", nicht "Maschine aus".
|
||||
* Für den Router ist das ein anderer Fehler und gehört nicht hierher.
|
||||
*/
|
||||
static int probe_endpoint(const j_endpoint *ep)
|
||||
{
|
||||
char base[J_URL_MAX];
|
||||
snprintf(base, sizeof base, "%s", ep->base);
|
||||
size_t bl = strlen(base);
|
||||
while (bl > 0 && base[bl - 1] == '/') base[--bl] = '\0';
|
||||
if (!bl) return -1;
|
||||
|
||||
char cmd[2048];
|
||||
int off = snprintf(cmd, sizeof cmd, "curl -s -o /dev/null -m %.0f ",
|
||||
CFG.probe_timeout_s > 0 ? CFG.probe_timeout_s : 3.0);
|
||||
/* Dieselbe Vertrauensfrage wie im Anfragepfad: ein Endpunkt mit tls_verify off wird
|
||||
* auch hier nicht geprüft, und eine eigene CA gilt mit. */
|
||||
if (!ep->tls_verify)
|
||||
off += snprintf(cmd + off, sizeof cmd - (size_t)off, "-k ");
|
||||
else if (ep->tls_ca[0])
|
||||
off += snprintf(cmd + off, sizeof cmd - (size_t)off, "--cacert '%s' ", ep->tls_ca);
|
||||
const char *key = ep->key_env_count > 0 ? getenv(ep->api_key_env[0]) : NULL;
|
||||
if (key && *key)
|
||||
off += snprintf(cmd + off, sizeof cmd - (size_t)off,
|
||||
"-H 'Authorization: Bearer %s' ", key);
|
||||
for (int i = 0; i < ep->header_count && off > 0 && (size_t)off < sizeof cmd; i++) {
|
||||
if (strchr(ep->headers[i], '\'')) continue;
|
||||
off += snprintf(cmd + off, sizeof cmd - (size_t)off, "-H '%s' ", ep->headers[i]);
|
||||
}
|
||||
if (off <= 0 || (size_t)off >= sizeof cmd) return -1;
|
||||
/* Zwei Zahlen: Statuscode und die Zeit bis zum TCP-Verbindungsaufbau. Nur die
|
||||
* zweite beantwortet die Frage, um die es geht — ein Server, der langsam antwortet,
|
||||
* hatte eine Verbindung; ein Host, der nicht antwortet, hatte keine. */
|
||||
snprintf(cmd + off, sizeof cmd - (size_t)off,
|
||||
"-w '%%{http_code} %%{time_connect}' '%s/models'", base);
|
||||
|
||||
FILE *f = popen(cmd, "r");
|
||||
if (!f) return -1;
|
||||
char out[64] = "";
|
||||
if (!fgets(out, sizeof out, f)) out[0] = '\0';
|
||||
(void)pclose(f);
|
||||
|
||||
/* "Offline" heißt: keine Verbindung zustande gekommen. Ein Server, der die TCP-
|
||||
* Verbindung aufbaut und dann langsam antwortet, ist erreichbar — er rechnet nur.
|
||||
* Wer hier jeden Zeitablauf als Ausfall wertet, nimmt langsame Endpunkte dauerhaft
|
||||
* aus dem Verkehr (der Stub mit 6 s Antwortzeit ist genau dieser Fall). */
|
||||
double t_connect = 0.0;
|
||||
if (sscanf(out, "%*d %lf", &t_connect) != 1) t_connect = 0.0;
|
||||
return t_connect > 0.0 ? 0 : -1;
|
||||
}
|
||||
|
||||
static void *probe_thread(void *unused)
|
||||
{
|
||||
(void)unused;
|
||||
for (;;) {
|
||||
double t = now_s();
|
||||
for (int i = 0; i < CFG.endpoint_count; i++) {
|
||||
j_endpoint *ep = &CFG.endpoints[i];
|
||||
if (!ep->probe_on || ep->paused || !ep->base[0]) continue;
|
||||
int alive = probe_endpoint(ep) == 0;
|
||||
int was_off = ep->offline_until > now_s();
|
||||
STATE_LOCK();
|
||||
if (!alive) {
|
||||
double hold = CFG.offline_hold_s > 0 ? CFG.offline_hold_s : 20.0;
|
||||
ep->offline_until = now_s() + hold;
|
||||
} else {
|
||||
ep->offline_until = 0;
|
||||
ep->probe_ok = 1;
|
||||
}
|
||||
ep->probe_at = now_s();
|
||||
STATE_UNLOCK();
|
||||
if (!alive && !was_off)
|
||||
jlog("probe_offline", "endpoint=%s base=%s hold_s=%.0f",
|
||||
ep->name, ep->base, CFG.offline_hold_s);
|
||||
else if (alive && was_off)
|
||||
jlog("probe_recovered", "endpoint=%s", ep->name);
|
||||
}
|
||||
double nap = CFG.probe_interval_s > 0 ? CFG.probe_interval_s : 20.0;
|
||||
double next = t + nap;
|
||||
while (now_s() < next) {
|
||||
struct timespec ts = { 0, 200 * 1000 * 1000 };
|
||||
nanosleep(&ts, NULL);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Startroutine des Hintergrundabrufs (models.c). */
|
||||
static void *models_refresh_thread(void *unused)
|
||||
{
|
||||
@@ -3587,6 +3796,13 @@ int main(int argc, char **argv)
|
||||
if (pthread_create(&th, NULL, metrics_thread, NULL) == 0)
|
||||
pthread_detach(th);
|
||||
}
|
||||
if (CFG.probe_interval_s > 0) {
|
||||
pthread_t pt;
|
||||
if (pthread_create(&pt, NULL, probe_thread, NULL) == 0)
|
||||
pthread_detach(pt);
|
||||
jlog("probe", "interval_s=%.0f timeout_s=%.0f endpoints=%d", CFG.probe_interval_s,
|
||||
CFG.probe_timeout_s, CFG.endpoint_count);
|
||||
}
|
||||
/* Gemeinsamer Cache: eigener Port für die Nachbarn, optional. Scheitert er, läuft
|
||||
* der Router weiter — ein Cache ist eine Ersparnis, keine Bedingung. */
|
||||
if (j_mesh_start())
|
||||
|
||||
Executable
+71
@@ -0,0 +1,71 @@
|
||||
#!/bin/bash
|
||||
# Wird von tests/run.sh eingebunden: ein Schlüssel in der Umgebung ist ein Endpunkt.
|
||||
#
|
||||
# Der Fall: wer OLLAMA_KEY1 setzt, will ollama1 benutzen — ohne dafür einen Block in die
|
||||
# Konfiguration zu schreiben. Die Datei bleibt die Wahrheit, wo sie spricht; die
|
||||
# Umgebung füllt nur die Lücken.
|
||||
|
||||
echo
|
||||
echo "== 39. Provider aus der Umgebung =="
|
||||
|
||||
E1=$((PORT+226))
|
||||
E2=$((PORT+227))
|
||||
|
||||
tests/stub $E2 "ENVSTUB" > "$TMP/env_stub.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
sleep 0.4
|
||||
|
||||
# Keine Endpunkt-Blöcke, nur eine Regel — der Endpunkt soll aus der Umgebung kommen.
|
||||
cat > "$TMP/env.conf" <<CFG
|
||||
listen 127.0.0.1:$E1
|
||||
log_prefix env
|
||||
req for "*" check none pass ollama1
|
||||
CFG
|
||||
|
||||
OLLAMA_KEY1=test-key OLLAMA_BASE="http://127.0.0.1:$E2/v1" \
|
||||
./junction --config "$TMP/env.conf" > "$TMP/env.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
wait_port "$E1" 10 || bad "the env-config instance did not come up"
|
||||
|
||||
log_has "$TMP/env.log" "endpoint ollama1 added from OLLAMA_KEY1" \
|
||||
"ollama1 comes from OLLAMA_KEY1 without an endpoint block"
|
||||
|
||||
r=$(curl -s -m 10 -X POST -H 'Content-Type: application/json' \
|
||||
-d '{"model":"m","messages":[{"role":"user","content":"x"}],"max_tokens":3}' \
|
||||
"http://127.0.0.1:$E1/v1/chat/completions")
|
||||
contains "$r" "served by ENVSTUB" "and it actually routes there"
|
||||
|
||||
s=$(curl -s -m 5 "http://127.0.0.1:$E1/status")
|
||||
contains "$s" '"name":"ollama1"' "/status lists the endpoint that was never written down"
|
||||
contains "$s" '"keys":1' "the pool size comes from the single key variable"
|
||||
|
||||
# Die Basis lässt sich umbiegen (hier auf den Stub) — ohne sie wäre es der Anbieter.
|
||||
contains "$s" "127.0.0.1:$E2" "the base was taken from OLLAMA_BASE"
|
||||
|
||||
# Ein zweiter Schlüssel ergibt einen zweiten Endpunkt, kein größeres Kontingent.
|
||||
cat > "$TMP/env2.conf" <<CFG
|
||||
listen 127.0.0.1:$((PORT+228))
|
||||
log_prefix env2
|
||||
req for "*" check none pass ollama1
|
||||
CFG
|
||||
OLLAMA_KEY1=a OLLAMA_KEY2=b OLLAMA_BASE="http://127.0.0.1:$E2/v1" \
|
||||
./junction --config "$TMP/env2.conf" > "$TMP/env2.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
wait_port "$((PORT+228))" 10 || bad "the two-key instance did not come up"
|
||||
log_has "$TMP/env2.log" "endpoint ollama2 added from OLLAMA_KEY2" \
|
||||
"OLLAMA_KEY2 becomes ollama2, not a bigger pool on ollama1"
|
||||
|
||||
# Abschaltbar: ohne Automatik und ohne Block gibt es keinen Endpunkt — und die Regel
|
||||
# nennt damit ein unbekanntes Ziel, was die Datei ungültig macht.
|
||||
cat > "$TMP/env3.conf" <<CFG
|
||||
listen 127.0.0.1:$((PORT+229))
|
||||
log_prefix env3
|
||||
auto_endpoints off
|
||||
req for "*" check none pass ollama1
|
||||
CFG
|
||||
if OLLAMA_KEY1=a ./junction --config "$TMP/env3.conf" --check > "$TMP/env3.out" 2>&1; then
|
||||
bad "auto_endpoints off still invented an endpoint"
|
||||
else
|
||||
contains "$(cat "$TMP/env3.out")" "auto_endpoints is off" \
|
||||
"auto_endpoints off leaves the configuration without invented endpoints"
|
||||
fi
|
||||
Executable
+88
@@ -0,0 +1,88 @@
|
||||
#!/bin/bash
|
||||
# Wird von tests/run.sh eingebunden: ein Modell zur Zeit, aber mehrere Modelle parallel.
|
||||
#
|
||||
# Der Fall dahinter: eine lokale Box hält ein Modell im Speicher. Zwei Anfragen an
|
||||
# dasselbe Modell machen sie nicht schneller, sondern treiben sie in den Swap. Zwei
|
||||
# Anfragen an verschiedene Modelle dagegen sind zwei Modelle, die geladen sind — die
|
||||
# dürfen gleichzeitig laufen. Und der Client soll `local/<modell>` verlangen dürfen,
|
||||
# ohne dass die Box den Präfix je sieht.
|
||||
|
||||
echo
|
||||
echo "== 37. Eine Anfrage je Modell, mehrere Modelle parallel =="
|
||||
|
||||
LP=$((PORT+220))
|
||||
LSTUB=$((PORT+221))
|
||||
|
||||
# 2 s Antwortzeit: damit lässt sich messen, ob zwei Anfragen seriell (4 s) oder
|
||||
# parallel (2 s) liefen.
|
||||
tests/stub $LSTUB "LOCAL" --delay 2 > "$TMP/local_stub.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
sleep 0.4
|
||||
|
||||
cat > "$TMP/local.conf" <<CFG
|
||||
listen 127.0.0.1:$LP
|
||||
log_prefix lp
|
||||
queue_timeout 30
|
||||
max_inflight 8
|
||||
endpoint box {
|
||||
base http://127.0.0.1:$LSTUB/v1
|
||||
timeout 30
|
||||
max_model_inflight 1
|
||||
}
|
||||
req for "local/*" strip "local/" pass box
|
||||
req for "*" pass box
|
||||
CFG
|
||||
./junction --config "$TMP/local.conf" > "$TMP/local.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
wait_port "$LP" 10 || bad "the local pool instance did not come up"
|
||||
|
||||
ask_local() { # ask_local <model> -> Körper der Antwort
|
||||
curl -s -m 30 -X POST -H 'Content-Type: application/json' \
|
||||
-d "{\"model\":\"$1\",\"messages\":[{\"role\":\"user\",\"content\":\"hallo\"}],\"max_tokens\":4}" \
|
||||
"http://127.0.0.1:$LP/v1/chat/completions"
|
||||
}
|
||||
timed_pair() { # timed_pair <mod1> <mod2> -> Sekunden für beide zusammen
|
||||
local start=$(date +%s%N)
|
||||
ask_local "$1" > "$TMP/lp1.txt" &
|
||||
local a=$!
|
||||
ask_local "$2" > "$TMP/lp2.txt" &
|
||||
local b=$!
|
||||
wait $a $b
|
||||
echo $(( ($(date +%s%N) - start) / 1000000000 ))
|
||||
}
|
||||
|
||||
same=$(timed_pair "local/qwen3.6-35b" "local/qwen3.6-35b")
|
||||
if [ "$same" -ge 3 ] && [ "$same" -le 8 ]; then
|
||||
ok "two requests for the same model wait for each other (${same}s, one at a time)"
|
||||
else
|
||||
bad "same model ran in parallel: ${same}s instead of ~4 s"
|
||||
fi
|
||||
|
||||
diff=$(timed_pair "local/qwen3.6-35b" "local/llama-3-8b")
|
||||
if [ "$diff" -ge 1 ] && [ "$diff" -le 4 ]; then
|
||||
ok "two different models run in parallel (${diff}s, not serialised)"
|
||||
else
|
||||
bad "different models were serialised: ${diff}s instead of ~2 s"
|
||||
fi
|
||||
|
||||
# Der Präfix darf die Box nie erreichen — sonst antwortet sie mit 404 oder hängt.
|
||||
# Der Stub meldet, was er bekommen hat, in X-Stub-Model (der Rumpf nennt seinen eigenen
|
||||
# Namen, nicht den angefragten).
|
||||
curl -s -m 30 -D "$TMP/lp_h.txt" -o /dev/null -X POST -H 'Content-Type: application/json' \
|
||||
-d '{"model":"local/qwen3.6-35b","messages":[{"role":"user","content":"hallo"}],"max_tokens":4}' \
|
||||
"http://127.0.0.1:$LP/v1/chat/completions"
|
||||
seen=$(tr -d '\r' < "$TMP/lp_h.txt" | sed -n 's/^X-Stub-Model: //p' | head -1)
|
||||
if [ "$seen" = "qwen3.6-35b" ]; then
|
||||
ok "the strip removed local/ before the request left the router ($seen)"
|
||||
else
|
||||
bad "the box received model '$seen' instead of qwen3.6-35b"
|
||||
fi
|
||||
|
||||
# Und die Grenze ist wirklich pro Modell, nicht pro Box: zwei Modelle gleichzeitig
|
||||
# dürfen die Box nicht als Ganzes blockieren (oben gemessen), aber ein Modell darf
|
||||
# auch nicht mehr als einen Platz bekommen.
|
||||
if grep -q "model_queue_timeout" "$TMP/local.log"; then
|
||||
bad "a model request timed out instead of waiting"
|
||||
else
|
||||
ok "waiting requests are queued, not refused"
|
||||
fi
|
||||
@@ -13,6 +13,7 @@ cat > "$TMP/wait.conf" <<CFG
|
||||
listen 127.0.0.1:$P_W
|
||||
offline_hold_s 2
|
||||
offline_wait 5
|
||||
probe_interval 0 # dieser Abschnitt prüft den Anfragepfad, nicht die Hintergrundprüfung
|
||||
endpoint late {
|
||||
base http://127.0.0.1:$P_DEADS/v1
|
||||
context 64000
|
||||
|
||||
Executable
+95
@@ -0,0 +1,95 @@
|
||||
#!/bin/bash
|
||||
# Wird von tests/run.sh eingebunden: Erreichbarkeit im Hintergrund prüfen.
|
||||
#
|
||||
# Der Fall: eine Box ist weg. Der Router soll das merken, bevor die erste Anfrage
|
||||
# daran hängen bleibt — sie für eine Weile offline nehmen und danach von selbst wieder
|
||||
# nachsehen, statt bei jeder Anfrage erneut in den Zeitablauf zu laufen.
|
||||
|
||||
echo
|
||||
echo "== 38. Erreichbarkeit im Hintergrund (offline, dann wieder prüfen) =="
|
||||
|
||||
PP=$((PORT+222))
|
||||
P_ALIVE=$((PORT+223))
|
||||
P_DEAD=$((PORT+224))
|
||||
|
||||
tests/stub $P_ALIVE "ALIVE" > "$TMP/probe_stub.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
sleep 0.4
|
||||
|
||||
cat > "$TMP/probe.conf" <<CFG
|
||||
listen 127.0.0.1:$PP
|
||||
log_prefix pr
|
||||
probe_interval 2
|
||||
probe_timeout 1
|
||||
offline_hold_s 4
|
||||
queue_timeout 10
|
||||
endpoint alive { base http://127.0.0.1:$P_ALIVE/v1; timeout 10 }
|
||||
endpoint dead { base http://127.0.0.1:$P_DEAD/v1; timeout 10 }
|
||||
req for "*" check none pass dead, alive
|
||||
CFG
|
||||
./junction --config "$TMP/probe.conf" > "$TMP/probe.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
wait_port "$PP" 10 || bad "the probe instance did not come up"
|
||||
|
||||
# Zwei Intervalle abwarten: der tote Endpunkt muss ohne jede Anfrage auffallen.
|
||||
log_has "$TMP/probe.log" "probe_offline endpoint=dead" \
|
||||
"a dead endpoint is noticed without a request being sent to it"
|
||||
|
||||
dead_off=$(curl -s -m 5 "http://127.0.0.1:$PP/status" | python3 -c "
|
||||
import sys,json
|
||||
d=json.load(sys.stdin)
|
||||
for e in d['endpoints']:
|
||||
if e['name']=='dead': print(e['offline_s'], e['probe_ok'])")
|
||||
set -- $dead_off
|
||||
if [ "${1:-0}" -gt 0 ] && [ "${2:-1}" = "0" ]; then
|
||||
ok "it is offline for a while (${1}s left) and marked as not answering"
|
||||
else
|
||||
bad "/status does not show it offline (offline_s=$1 probe_ok=$2)"
|
||||
fi
|
||||
|
||||
# Die Anfrage geht am toten Ziel vorbei, ohne dessen Zeitablauf zu bezahlen.
|
||||
read -r pcode ptime < <(curl -s -o /dev/null -m 15 -w '%{http_code} %{time_total}' \
|
||||
-X POST -H 'Content-Type: application/json' \
|
||||
-d '{"model":"m","messages":[{"role":"user","content":"x"}],"max_tokens":3}' \
|
||||
"http://127.0.0.1:$PP/v1/chat/completions")
|
||||
if [ "$pcode" = "200" ] && awk "BEGIN{exit !($ptime < 2.0)}"; then
|
||||
ok "the request skips the offline target without waiting for it (${ptime}s)"
|
||||
else
|
||||
bad "the request still paid for the dead target: http=$pcode after ${ptime}s"
|
||||
fi
|
||||
|
||||
# Jetzt kommt die Box zurück: die Prüfung muss sie von selbst wieder aufnehmen.
|
||||
tests/stub $P_DEAD "REVIVED" > "$TMP/probe_revived.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
log_has "$TMP/probe.log" "probe_recovered endpoint=dead" \
|
||||
"the returning endpoint is picked up by the next check, not by a failure"
|
||||
|
||||
revived=$(curl -s -m 5 "http://127.0.0.1:$PP/status" | python3 -c "
|
||||
import sys,json
|
||||
d=json.load(sys.stdin)
|
||||
for e in d['endpoints']:
|
||||
if e['name']=='dead': print(e['probe_ok'], int(e['offline_s']))")
|
||||
set -- $revived
|
||||
if [ "${1:-0}" = "1" ] && [ "${2:-1}" = "0" ]; then
|
||||
ok "it is back: probe_ok=1, no offline hold left"
|
||||
else
|
||||
bad "the endpoint did not come back (probe_ok=$1 offline_s=$2)"
|
||||
fi
|
||||
|
||||
# Und die Prüfung ist abschaltbar (probe off) — nicht jedes Ziel darf gefragt werden.
|
||||
cat > "$TMP/probe_off.conf" <<CFG
|
||||
listen 127.0.0.1:$((PORT+225))
|
||||
log_prefix po
|
||||
probe_interval 1
|
||||
endpoint quiet { base http://127.0.0.1:$P_DEAD/v1; probe off; timeout 5 }
|
||||
req for "*" check none pass quiet
|
||||
CFG
|
||||
./junction --config "$TMP/probe_off.conf" > "$TMP/probe_off.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
wait_port "$((PORT+225))" 10 || bad "the probe-off instance did not come up"
|
||||
sleep 2.5
|
||||
if grep -q "probe_offline endpoint=quiet" "$TMP/probe_off.log" 2>/dev/null; then
|
||||
bad "a probe off endpoint was checked anyway"
|
||||
else
|
||||
ok "probe off keeps an endpoint out of the check"
|
||||
fi
|
||||
+20
-1
@@ -2,6 +2,13 @@
|
||||
# junction test suite — stub endpoints only, no network, no models. ~150 s.
|
||||
set -uo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
# Hermetisch: dieser Lauf darf nicht davon abhängen, welche Schlüssel zufällig in der
|
||||
# Umgebung stehen. Sonst legt junction Endpunkte an, die kein Test erwartet.
|
||||
unset OPENCODE_GO_API_KEY OLLAMA_KEY ANTHROPIC_API_KEY CLAUDE_API_KEY 2>/dev/null || true
|
||||
for n in 1 2 3 4 5 6 7 8; do
|
||||
unset "OPENCODE_GO_API_KEY$n" "OLLAMA_KEY$n" "ANTHROPIC_API_KEY$n" "CLAUDE_API_KEY$n" 2>/dev/null || true
|
||||
done
|
||||
|
||||
TMP=$(mktemp -d)
|
||||
PORT=8135
|
||||
P_FAIL=9990; P_GATED=9991; P_DEAD=9992; P_SLOW=9993; P_PONDER=9994
|
||||
@@ -46,7 +53,7 @@ log_has() {
|
||||
# answer requests with somebody else's config), so fail loudly and early.
|
||||
# 8157 gehört auf dieser Maschine dem Hermes-Gateway — der Port wird von keinem
|
||||
# Test benutzt, also darf er die Suite nicht aufhalten.
|
||||
for port in 8347 8348 8349 8350 8351 8352 8353 8354 8345 8346 8335 8336 8337 8338 8339 8340 8341 8342 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8150 8151 8152 8153 8154 8155 8156 8158 8159 8165 8166 8167 8168 8170 8171 8172 8173 8175 8180 8181 8194 8176 8177 8185 8186 8187 8188 8189 8190 9443 9990 9991 9992 9993 9994 9995 9996; do
|
||||
for port in 8361 8362 8363 8364 8357 8358 8359 8360 8355 8356 8347 8348 8349 8350 8351 8352 8353 8354 8345 8346 8335 8336 8337 8338 8339 8340 8341 8342 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8150 8151 8152 8153 8154 8155 8156 8158 8159 8165 8166 8167 8168 8170 8171 8172 8173 8175 8180 8181 8194 8176 8177 8185 8186 8187 8188 8189 8190 9443 9990 9991 9992 9993 9994 9995 9996; do
|
||||
if ss -tln 2>/dev/null | grep -q ":$port "; then
|
||||
echo "port $port is busy — a leftover junction/stub is still running:"
|
||||
ss -tlnp 2>/dev/null | grep ":$port " | sed 's/^/ /'
|
||||
@@ -716,6 +723,18 @@ contains "$OUT" "bad arguments" "an impossible offpeak window is rejected"
|
||||
# shellcheck source=tests/retry-after.sh
|
||||
. "$(dirname "$0")/retry-after.sh"
|
||||
|
||||
# Ein Modell zur Zeit, mehrere Modelle parallel, Präfix weg.
|
||||
# shellcheck source=tests/local-pool.sh
|
||||
. "$(dirname "$0")/local-pool.sh"
|
||||
|
||||
# Erreichbarkeit im Hintergrund prüfen: offline nehmen, dann wieder nachsehen.
|
||||
# shellcheck source=tests/probe.sh
|
||||
. "$(dirname "$0")/probe.sh"
|
||||
|
||||
# Ein Schlüssel in der Umgebung ist ein Endpunkt.
|
||||
# shellcheck source=tests/env-providers.sh
|
||||
. "$(dirname "$0")/env-providers.sh"
|
||||
|
||||
# junction als MCP-Server: Werkzeuge der angebundenen Server bündeln und
|
||||
# Aufrufe an den richtigen Server weiterreichen. Eigenes Programm, weil zwei
|
||||
# erfundene MCP-Server gebraucht werden.
|
||||
|
||||
Reference in new issue
Block a user