Skip to content

test(grpc): cover TokenSpeed and SGLang server-info label conversion - #1654

Merged
slin1237 merged 1 commit into
mainfrom
test/grpc-server-info-labels
Jun 11, 2026
Merged

slin1237 merged 1 commit into
mainfrom
test/grpc-server-info-labels

Conversation

@slin1237

@slin1237 slin1237 commented Jun 11, 2026 •

Copy link
Copy Markdown
Member

Description

Follow-up to #1574 (closed). For gRPC-connected workers, backend server/model
info is not served by a router endpoint: the worker registration workflow calls
the backend's GetModelInfo / GetServerInfo RPCs (discover_metadata.rs) and
surfaces the results as worker labels in GET /workers. The TokenSpeed arms of
that pipeline landed with #1351, but the label-conversion layer
(ModelInfo::to_labels / ServerInfo::to_labels) had no unit coverage, and the
admin API docs did not say where this data lives in gRPC mode.

Changes

  • Add unit tests for the worker-label conversion in routers/grpc/client.rs:
    • TokenSpeed ServerInfo: curated TOKENSPEED_GRPC_KEYS picked from the
      server_args Struct, integral numbers formatted without a decimal point,
      tokenspeed_version → version, unlisted keys / scheduler_info /
      transient runtime state excluded.
    • SGLang ServerInfo: same contract via SGLANG_GRPC_KEYS, including
      is_embedding=false kept as a label (embedding detection relies on it) and
      non-curated keys (e.g. api_key) excluded.
    • TokenSpeed ModelInfo: flat_labels skip/keep rules — empty strings and
      zero numbers skipped, false booleans kept, arrays JSON-encoded.
  • docs/reference/api/admin.md: note on /get_server_info and
    /get_model_info that they are HTTP-worker passthroughs; gRPC workers expose
    the same metadata as labels in GET /workers, with live scheduler state on
    /get_loads.

Test Plan

$ cargo +nightly fmt --all
(clean)

$ cargo clippy --all-targets --all-features -- -D warnings
Finished `dev` profile [unoptimized + debuginfo] target(s) in 1m 05s

$ cargo test -p smg --lib routers::grpc::client::tests
running 3 tests
test routers::grpc::client::tests::server_info_to_labels_tokenspeed_picks_curated_keys_and_version ... ok
test routers::grpc::client::tests::server_info_to_labels_sglang_picks_curated_keys_and_version ... ok
test routers::grpc::client::tests::model_info_to_labels_tokenspeed_flat_serializes_skipping_empty_and_zero ... ok
test result: ok. 3 passed; 0 failed

$ cargo test
86 suites, all `test result: ok`, 0 failures

Summary by CodeRabbit

  • Documentation
    • Updated API documentation to clarify that worker information endpoints are only available for HTTP-connected workers. Added details on how the gateway exposes and manages worker information through the API.

ModelInfo::to_labels and ServerInfo::to_labels feed the worker labels
surfaced by GET /workers for gRPC-connected workers, but had no unit
coverage. Add tests for the TokenSpeed and SGLang arms: curated
server_args key picking, integer formatting, version mapping, and the
flat_labels skip/keep rules (empty strings, zero numbers, false
booleans, JSON-encoded arrays).

Also document in the admin API reference that /get_server_info and
/get_model_info are HTTP-worker passthroughs: gRPC workers surface the
same metadata as labels in GET /workers (discovered at registration via
the GetServerInfo/GetModelInfo RPCs), with live scheduler state on
/get_loads.

Signed-off-by: Simo Lin <25425177+slin1237@users.noreply.github.com>
@github-actions github-actions Bot added documentation Improvements or additions to documentation grpc gRPC client and router changes model-gateway Model gateway crate changes labels Jun 11, 2026
@coderabbitai

coderabbitai Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4e0a2606-c55f-48fc-9927-aa46221ea075

📥 Commits

Reviewing files that changed from the base of the PR and between 064553f and 4f62125.

📒 Files selected for processing (2)
  • docs/reference/api/admin.md
  • model_gateway/src/routers/grpc/client.rs

📝 Walkthrough

Walkthrough

This PR updates API documentation and adds unit test coverage for gRPC worker label extraction. The get_model_info and get_server_info endpoints are clarified to work only with HTTP-connected workers, while gRPC workers obtain metadata at registration and expose it as worker labels. Tests validate label conversion logic across different backend types.

Changes

gRPC Worker Label Extraction and Testing

Layer / File(s) Summary
API documentation updates for worker metadata endpoints
docs/reference/api/admin.md
GET /get_model_info and GET /get_server_info endpoint descriptions are updated to specify HTTP-only proxying, with new notes documenting that gRPC workers have metadata obtained once at registration and curated results exposed as worker labels via GET /workers and live state via GET /get_loads.
Unit tests for ServerInfo and ModelInfo label conversion
model_gateway/src/routers/grpc/client.rs
Added test module validates ServerInfo::to_labels() curated key selection and version labeling for TokenSpeed and SGLang backends, and validates ModelInfo::to_labels() flat serialization rules: skipping empty strings and zero values while preserving booleans and JSON-encoding non-empty arrays.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • lightseekorg/smg#447: New test cases in client.rs directly exercise the same label-conversion logic (flat_labels/gRPC field picking) refactored in that PR.
  • lightseekorg/smg#1529: Both PRs center on ServerInfo→label extraction/flattening, with retrieved PR adding max_running_requests to SGLang ServerInfo model and testing it via flat_labels.

Suggested labels

grpc, model-gateway, documentation

Suggested reviewers

  • CatherineSue
  • key4ng

Poem

🐰 A label doth spring from metadata,
Where gRPC workers once met the gate,
Now tests ensure the curated flow,
As docs make crystal what users should know. 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding test coverage for TokenSpeed and SGLang server-info label conversion in the gRPC client module.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/grpc-server-info-labels

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude

claude Bot commented Jun 11, 2026

Copy link
Copy Markdown

👋 The PR description doesn't fully follow PULL_REQUEST_TEMPLATE.md:

  • Missing header: ### Problem
  • Missing header: ### Solution

Please update the PR description so reviewers have the context they need.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the API documentation to clarify that /get_model_info and /get_server_info are proxied to HTTP workers, adding notes on how gRPC-connected workers are handled. It also introduces unit tests in model_gateway/src/routers/grpc/client.rs to verify the serialization of server and model info into labels for TokenSpeed and Sglang backends. The review feedback suggests improving test code maintainability by introducing a bool_value helper function to simplify the construction of boolean values in tests.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +852 to +856
fn number_value(n: f64) -> prost_types::Value {
prost_types::Value {
kind: Some(prost_types::value::Kind::NumberValue(n)),
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To complete the set of test helper functions for prost_types::Value types and avoid verbose inline construction of boolean values later in the tests, consider adding a bool_value helper function alongside string_value and number_value.

    fn number_value(n: f64) -> prost_types::Value {
        prost_types::Value {
            kind: Some(prost_types::value::Kind::NumberValue(n)),
        }
    }

    fn bool_value(b: bool) -> prost_types::Value {
        prost_types::Value {
            kind: Some(prost_types::value::Kind::BoolValue(b)),
        }
    }
References
  1. Extract duplicated logic into a shared helper function to improve maintainability and reduce redundancy.

Comment on lines +915 to +920
(
"is_embedding".to_string(),
prost_types::Value {
kind: Some(prost_types::value::Kind::BoolValue(false)),
},
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the newly added bool_value helper function to simplify the construction of the is_embedding field and improve test readability.

                    ("is_embedding".to_string(), bool_value(false)),
References
  1. Extract duplicated logic into a shared helper function to improve maintainability and reduce redundancy.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f62125359

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

fn server_info_to_labels_tokenspeed_picks_curated_keys_and_version() {
let info = ServerInfo::TokenSpeed(Box::new(tokenspeed_proto::GetServerInfoResponse {
server_args: Some(prost_types::Struct {
fields: BTreeMap::from([

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Use HashMap for prost Struct fields

When these unit tests are compiled, prost_types::Struct::fields expects a HashMap<String, prost_types::Value>, but the new fixtures initialize it with BTreeMap::from(...). That type mismatch prevents the test target from compiling anywhere routers::grpc::client::tests is built, and the same pattern repeats for the other Struct fixtures in this module.

Useful? React with 👍 / 👎.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid test coverage for the gRPC worker-label conversion layer. Tests correctly verify curated-key picking, version mapping, skip/keep rules (empty strings, zero numbers, booleans, arrays), and exclusion of non-curated keys and runtime state. Doc updates are accurate.

@slin1237
slin1237 merged commit 484d272 into main Jun 11, 2026
76 of 83 checks passed
@slin1237
slin1237 deleted the test/grpc-server-info-labels branch June 11, 2026 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation grpc gRPC client and router changes model-gateway Model gateway crate changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant