Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ second command matches; Postgres's volume goes with its `Cluster`.
cd openmeter-setup && go test ./... # bootstrap and ensure-secret against fakes
cd usage-console/server && go test ./internal/openmeter/ # the console API against a fake OpenMeter
cd usage-console/console && npm ci --ignore-scripts && npx vitest run
cd dev && make usage-e2e # on the kind cluster: install, send traffic, check totals
cd dev && make usage-e2e # on the kind cluster: the integration profile, then the journey suite's usage features (F10, F12)
```

## History
Expand Down
40 changes: 30 additions & 10 deletions dev/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ FEATURES ?=
# otherwise shadow the locked packages.
JOURNEYS_PIXI := cd ../tests/journeys && PYTHONNOUSERSITE=1 pixi run --locked

# Every suite run (integration-test and the four feature targets) is one
# `journeys-run` under this checkout's run lock, tests/journeys/results/.run.lock
# (llm_journeys.runlock), held from the profile check to the report. A second
# run started while one is in progress fails at once (the lock step exits 1,
# so make exits 2), before it checks the profile, reinstalls nebari_journeys
# or touches results/ under the first. The kernel drops the lock however a
# run ends.
JOURNEYS_RUN = $(JOURNEYS_PIXI) python -m llm_journeys.runlock results/.run.lock -- $(MAKE) -C $(CURDIR) --no-print-directory journeys-run

# Pin every kubectl to the local kind cluster's context. Without this, the dev
# targets act on whatever your current kube-context happens to be - which could
# be a remote/production cluster - and would deploy the auth-bypassing dev-mode
Expand All @@ -41,7 +50,7 @@ HELM_MAJOR := $(shell helm version --template '{{.Version}}' 2>/dev/null | sed -
EG_CHART := oci://docker.io/envoyproxy/gateway-helm
EG_SKIP_BUNDLED_CRDS := $(if $(filter-out 1 2 3,$(HELM_MAJOR)),--skip-crds --set crds.gatewayAPI.safeUpgradePolicy.enabled=false,)

.PHONY: setup teardown build-images load-images deploy integration-up spa-real-auth deploy-operator deploy-key-manager deploy-keycloak apply-test-model apply-passthrough-model create-openrouter-secret run-dev ui test-auth test-model-scope deploy-cnpg usage-e2e usage-tracer usage-forgery-check test-usage-collector integration-test profile-check logs-operator logs-key-manager logs-keycloak pf-key-manager pf-keycloak clean help render-pins
.PHONY: setup teardown build-images load-images deploy integration-up spa-real-auth deploy-operator deploy-key-manager deploy-keycloak apply-test-model apply-passthrough-model create-openrouter-secret run-dev ui test-auth test-model-scope deploy-cnpg usage-e2e usage-tracer usage-forgery-check test-usage-collector integration-test journeys-run profile-check logs-operator logs-key-manager logs-keycloak pf-key-manager pf-keycloak clean help render-pins

help: ## Show this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\nTargets:\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
Expand Down Expand Up @@ -111,6 +120,14 @@ profile-check: ## Exit 0 when the kind-dev profile the journey suite needs is co
$(JOURNEYS_PIXI) python -m llm_journeys.preflight --target kind-dev --kube-context kind-$(CLUSTER_NAME) --gateway-https-port $(GATEWAY_HOST_HTTPS_PORT)

integration-test: ## Run the journey suite's integration tier on kind-dev and report it by feature (FEATURES=F4,F8 narrows it); run make integration-up first, an incomplete profile fails the run
$(JOURNEYS_RUN) FEATURES=$(FEATURES)

# The steps every suite run shares, run only through $(JOURNEYS_RUN), which
# holds the run lock. ENSURE_PROFILE=1 (the four feature targets) first runs
# integration-up when profile-check fails.
journeys-run:
@test -n "$$LLM_JOURNEYS_RUN_LOCK" || { echo "journeys-run is not a target to run on its own: use make integration-test" >&2; exit 2; }
$(if $(ENSURE_PROFILE),$(MAKE) --no-print-directory profile-check || $(MAKE) --no-print-directory integration-up)
tag="$$(nic/resolve-nic-tag.sh)" && $(JOURNEYS_PIXI) ./install-helpers.sh "$$tag"
$(JOURNEYS_PIXI) python ../../dev/mock-vllm/test_server.py
$(JOURNEYS_PIXI) pytest tests_lib -W error
Expand Down Expand Up @@ -159,19 +176,22 @@ ui: ## Run the React UI dev server against the local cluster (alias for run-dev)
@echo "Starting the one-command dev environment (cluster + models + API port-forward + Vite)..."
./run-dev.sh

test-auth: ## Verify the key-manager's real bearer-token JWKS validation (deploys Keycloak, flips off dev mode, mints a token, asserts 200/401). KEEP_AUTH=1 leaves real-auth mode on.
./test-auth.sh
# The four feature targets run integration-up when profile-check fails, then
# their features through the suite. They leave the cluster on the integration
# profile (no dev mode on exit, Q75): make deploy switches back for run-dev.
test-auth: ## Journey suite F4 (key REST API; the key-manager rejects missing and invalid bearers) on the kind-dev profile, running integration-up first if it is not up; leaves the integration profile (make deploy for dev mode). For the SPA login: make spa-real-auth
$(JOURNEYS_RUN) FEATURES=F4 ENSURE_PROFILE=1

test-model-scope: ## Verify per-model API-key scoping and x-llm-client-id anti-spoofing through the gateway (deploys two mock models, asserts the 200/403/401 matrix). KEEP=1 leaves the models.
./test-model-scope.sh
test-model-scope: ## Journey suite F8 (per-model API-key scope, client-id anti-spoofing) on the kind-dev profile, running integration-up first if it is not up; leaves the integration profile (make deploy for dev mode)
$(JOURNEYS_RUN) FEATURES=F8 ENSURE_PROFILE=1

usage-e2e: ## Usage metering end to end with the bundled OpenMeter and usage console: alice and bob call the mock provider, per-person and per-team totals read back from OpenMeter's meters and the console's API (run `make setup` first)
./usage-e2e.sh
usage-e2e: ## Journey suite F10 and F12 (usage metering and the usage console; network isolation) on the kind-dev profile, running integration-up first if it is not up; leaves the integration profile (make deploy for dev mode)
$(JOURNEYS_RUN) FEATURES=F10,F12 ENSURE_PROFILE=1

usage-forgery-check: ## Check callers cannot choose the identity or request id the usage access log records (after usage-e2e)
./usage-forgery-check.sh
usage-forgery-check: ## Journey suite F14 (callers cannot choose the identity or request id the usage log records) on the kind-dev profile, running integration-up first if it is not up; leaves the integration profile (make deploy for dev mode)
$(JOURNEYS_RUN) FEATURES=F14 ENSURE_PROFILE=1

usage-tracer: ## Web page that sends one request and follows it through the gateway log, collector, Kafka, ClickHouse, OpenMeter and the console, at http://127.0.0.1:18894 (run `make usage-e2e` first)
usage-tracer: ## Web page that sends one request and follows it through the gateway log, collector, Kafka, ClickHouse, OpenMeter and the console, at http://127.0.0.1:18894 (run `make integration-up` first)
python3 usage-tracer/server.py

test-usage-collector: ## Run the usage collector pipeline tests in the pinned collector image
Expand Down
2 changes: 1 addition & 1 deletion dev/manifests/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ spec:
- name: LLM_EXTERNAL_GATEWAY_NAMESPACE
value: "envoy-gateway-system"
- name: LLM_INTERNAL_GATEWAY_NAME
value: "nebari-internal-gateway"
value: "nebari-gateway"
- name: LLM_INTERNAL_GATEWAY_NAMESPACE
value: "envoy-gateway-system"
# Issue the shared llm.local / llm-internal.local cert via the
Expand Down
206 changes: 206 additions & 0 deletions dev/tests/profile-check-branch.test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
#!/usr/bin/env bash
# Tests for the dev targets that run the journey suite: `test-auth`,
# `test-model-scope`, `usage-e2e`, `usage-forgery-check` and `integration-test`.
#
# bash dev/tests/profile-check-branch.test.sh
#
# It runs a copy of dev/Makefile in a temp tree with stub sub-steps, so it
# needs no cluster, no pixi and no network:
# - the four targets run `integration-up` only when `profile-check` fails,
# then the suite with their own --feature list; `integration-test` never
# runs either;
# - every run holds the checkout's run lock (tests/journeys/results/.run.lock)
# from the profile check to the report, so a second run started while one
# is in progress stops before it installs nebari_journeys or runs anything,
# and a run killed with SIGKILL leaves no lock behind.
# The lock itself is the real llm_journeys.runlock, run with this machine's python3.
set -euo pipefail

here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
repo="$(cd "$here/../.." && pwd)"

work="$(mktemp -d)"
cleanup() {
touch "$work/release" 2>/dev/null || true
wait 2>/dev/null || true
rm -rf "$work"
}
trap cleanup EXIT

tree="$work/tree"
mkdir -p "$tree/dev/nic" "$tree/tests/journeys" "$work/bin"
cp "$repo/dev/Makefile" "$tree/dev/Makefile"
cp "$repo/versions.env" "$tree/versions.env"

stub() { # stub PATH BODY
printf '#!/usr/bin/env bash\n%s\n' "$2" >"$1"
chmod +x "$1"
}

# Every stub appends one line to $STUB_LOG/calls.
stub "$tree/dev/integration-up.sh" 'echo integration-up >>"$STUB_LOG/calls"'
stub "$tree/dev/nic/resolve-nic-tag.sh" 'echo v0.0.1'
stub "$tree/tests/journeys/install-helpers.sh" 'echo "install-helpers $*" >>"$STUB_LOG/calls"'
# run-suite.sh: with STUB_SUITE_BLOCK=1 it says it started and waits for
# $STUB_RELEASE (at most 60s), so a second run can be started beside it.
stub "$tree/tests/journeys/run-suite.sh" '
echo "run-suite $*" >>"$STUB_LOG/calls"
if [ "${STUB_SUITE_BLOCK:-0}" = 1 ]; then
touch "$STUB_LOG/started"
for _ in $(seq 1 600); do [ -e "$STUB_RELEASE" ] && break; sleep 0.1; done
fi
exit 0'
stub "$work/bin/pixi" '
[ "$1 $2" = "run --locked" ] || { echo "unexpected pixi call: $*" >&2; exit 99; }
shift 2
exec "$@"'
stub "$work/bin/pytest" 'echo "pytest $*" >>"$STUB_LOG/calls"'
stub "$work/bin/python" '
case "$1 ${2:-}" in
"-m llm_journeys.preflight") echo "preflight" >>"$STUB_LOG/calls"; exit "${STUB_PREFLIGHT_CODE:-0}" ;;
"-m llm_journeys.runlock") shift 2; PYTHONPATH="$REAL_SUITE" exec python3 -s -m llm_journeys.runlock "$@" ;;
"../../dev/mock-vllm/test_server.py ") echo "mock-vllm-test" >>"$STUB_LOG/calls"; exit 0 ;;
esac
echo "unexpected python call: $*" >&2
exit 99'

failures=0
fail() {
echo "FAIL: $*" >&2
failures=$((failures + 1))
}

# run_make LOG TARGET [VAR=VALUE...]: run the copied Makefile; prints its exit code.
run_make() {
local log="$1" code=0
shift
mkdir -p "$log"
: >"$log/calls"
env -u MAKEFLAGS -u MAKELEVEL -u MFLAGS -u CLUSTER_NAME -u FEATURES \
PATH="$work/bin:$PATH" STUB_LOG="$log" REAL_SUITE="$repo/tests/journeys" STUB_RELEASE="$work/release" \
make -C "$tree/dev" --no-print-directory "$@" >"$log/out" 2>&1 || code=$?
echo "$code"
}

suite_line() { # suite_line FEATURE-ARGS
echo "run-suite --tier integration --strict-known-failures $1-- journeys --target=kind-dev --kube-context=kind-llm-serving-test --gateway-https-port=48443"
}

steps_after_profile() { # the shared steps, then the suite
printf '%s\n' "install-helpers v0.0.1" "mock-vllm-test" "pytest tests_lib -W error" "$(suite_line "$1")"
}

# expect NAME CODE WANT_CODE LOG WANT_CALLS
expect() {
local name="$1" code="$2" want_code="$3" log="$4" want="$5"
if [ "$code" != "$want_code" ]; then
fail "$name: exit $code, want $want_code"
sed 's/^/ /' "$log/out" >&2
fi
if [ "$(cat "$log/calls")" != "$want" ]; then
fail "$name: calls were:"
sed 's/^/ /' "$log/calls" >&2
echo " want:" >&2
printf '%s\n' "$want" | sed 's/^/ /' >&2
fi
}

# --- profile-check branch: target, its --feature list --------------------------
for row in "test-auth F4" "test-model-scope F8" "usage-e2e F10,F12" "usage-forgery-check F14"; do
target="${row% *}"
features="${row#* }"

# profile-check fails: integration-up runs, then the target's features.
log="$work/$target-down"
code="$(STUB_PREFLIGHT_CODE=1 run_make "$log" "$target")"
expect "$target (profile down)" "$code" 0 "$log" \
"$(printf '%s\n' preflight integration-up; steps_after_profile "--feature $features ")"

# profile-check passes: no integration-up.
log="$work/$target-up"
code="$(STUB_PREFLIGHT_CODE=0 run_make "$log" "$target")"
expect "$target (profile up)" "$code" 0 "$log" \
"$(printf '%s\n' preflight; steps_after_profile "--feature $features ")"

# A FEATURES given on the command line does not change the target's list.
log="$work/$target-features"
code="$(STUB_PREFLIGHT_CODE=0 run_make "$log" "$target" FEATURES=F2)"
expect "$target FEATURES=F2" "$code" 0 "$log" \
"$(printf '%s\n' preflight; steps_after_profile "--feature $features ")"
done

# integration-test never checks or provisions the profile.
log="$work/integration-test"
code="$(STUB_PREFLIGHT_CODE=1 run_make "$log" integration-test FEATURES=F4,F8)"
expect "integration-test FEATURES=F4,F8" "$code" 0 "$log" "$(steps_after_profile "--feature F4,F8 ")"
log="$work/integration-test-all"
code="$(STUB_PREFLIGHT_CODE=1 run_make "$log" integration-test)"
expect "integration-test" "$code" 0 "$log" "$(steps_after_profile "")"

# The shared steps are not a target to run on their own (no lock held).
log="$work/journeys-run"
code="$(run_make "$log" journeys-run)"
[ "$code" != 0 ] || fail "journeys-run without the lock: exit 0, want non-zero"
[ ! -s "$log/calls" ] || fail "journeys-run without the lock ran: $(tr '\n' ';' <"$log/calls")"

# --- the run lock ------------------------------------------------------------------
# wait_started LOG: wait (at most 30s) for the blocking suite stub to start.
wait_started() {
for _ in $(seq 1 300); do [ -e "$1/started" ] && return 0; sleep 0.1; done
fail "the first run's suite never started"
sed 's/^/ /' "$1/out" >&2
return 1
}

# A first run is in its suite; a second one of each kind is refused at once,
# before it checks the profile, installs the helpers or runs anything.
rm -f "$work/release"
first="$work/first"
mkdir -p "$first"
STUB_SUITE_BLOCK=1 run_make "$first" test-auth >"$work/first.code" &
first_pid=$!
if wait_started "$first"; then
for second in "integration-test FEATURES=F4" "usage-e2e"; do
log="$work/second-${second%% *}"
# shellcheck disable=SC2086 # the row is a target and its variables
code="$(STUB_PREFLIGHT_CODE=1 run_make "$log" $second)"
[ "$code" != 0 ] || fail "second run ($second) beside a running one: exit 0, want non-zero"
[ ! -s "$log/calls" ] || fail "second run ($second) ran steps: $(tr '\n' ';' <"$log/calls")"
grep -q "another journey run" "$log/out" || {
fail "second run ($second) does not say why it stopped:"
sed 's/^/ /' "$log/out" >&2
}
done
fi
touch "$work/release"
wait "$first_pid" || true
expect "first run (a second run refused beside it)" "$(cat "$work/first.code")" 0 "$first" \
"$(printf '%s\n' preflight; steps_after_profile "--feature F4 ")"

# Once the first run has finished, the next one runs.
log="$work/after"
code="$(run_make "$log" integration-test FEATURES=F4)"
expect "run after the first finished" "$code" 0 "$log" "$(steps_after_profile "--feature F4 ")"

# A run killed with SIGKILL (every process of it) leaves no lock behind.
rm -f "$work/release"
killed="$work/killed"
mkdir -p "$killed"
set -m
STUB_SUITE_BLOCK=1 run_make "$killed" integration-test FEATURES=F4 >/dev/null &
killed_pid=$!
set +m
if wait_started "$killed"; then
kill -9 -- "-$killed_pid" 2>/dev/null || fail "could not kill the run's process group"
wait "$killed_pid" 2>/dev/null || true
log="$work/after-kill"
code="$(run_make "$log" integration-test FEATURES=F4)"
expect "run after a killed run" "$code" 0 "$log" "$(steps_after_profile "--feature F4 ")"
fi
touch "$work/release"

if [ "$failures" -gt 0 ]; then
echo "$failures failure(s)" >&2
exit 1
fi
echo "profile-check-branch.test.sh: all passed"
8 changes: 4 additions & 4 deletions dev/usage-tracer/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
# Ports of their own, so a port-forward started by hand doesn't get in the way.
FORWARDS = {
"gateway-external": (GW_NS, "gateway:nebari-gateway", 28443, 443),
"gateway-internal": (GW_NS, "gateway:nebari-internal-gateway", 28444, 443),
"gateway-internal": (GW_NS, "gateway:nebari-gateway", 28444, 443),
"key-manager": (NS, "svc/llm-key-manager", 28440, 8080),
# The key-owner lookup the collector makes (internal port, cluster-only).
"key-owners": (NS, "svc/llm-key-manager-owners", 28446, 8081),
Expand Down Expand Up @@ -140,8 +140,8 @@ def api_key(person, token):

# name -> (namespace, label selector, what it is). The pods are read live.
COMPONENTS = {
"gateway": (GW_NS, "gateway.envoyproxy.io/owning-gateway-name in (nebari-gateway,nebari-internal-gateway)",
"Envoy (C++), in pods Envoy Gateway creates for each Gateway: one for API keys (nebari-gateway), one for logins (nebari-internal-gateway). Envoy AI Gateway's ext_proc (Go) runs as a sidecar container in the same pod."),
"gateway": (GW_NS, "gateway.envoyproxy.io/owning-gateway-name=nebari-gateway",
"Envoy (C++), in the pods Envoy Gateway creates for the one Gateway, nebari-gateway, which serves API keys (llm.local) and logins (llm-internal.local). Envoy AI Gateway's ext_proc (Go) runs as a sidecar container in the same pod."),
"model": (NS, "app=mock-provider", "A small Python server (dev/mock-vllm) that answers like an OpenAI-compatible model."),
"collector": (NS, "app=llm-operator-usage-collector",
"OpenMeter's Benthos collector (Go). Its pipeline is the pack's files/usage-collector.yaml, mounted at /etc/usage-collector/."),
Expand Down Expand Up @@ -256,7 +256,7 @@ def send(person, path, model, cancel):
tid = str(len(_traces) + 1)
_traces[tid] = {
"person": person, "path": path, "model": model, "cancel": cancel, "sentAt": sent,
"gateway": f"nebari-{'internal-' if path == 'login' else ''}gateway", "match": match,
"gateway": "nebari-gateway", "match": match,
"collectorBefore": before, "status": code, "attempts": attempts, "usage": usage, "tookMs": int(took * 1000), "stages": {}, "polling": threading.Lock(),
}
return tid
Expand Down
Loading
Loading