Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpc_server: use x-correlation-id as request-id when possible #128

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
13 changes: 11 additions & 2 deletions src/vllm_tgis_adapter/grpc/grpc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,17 @@ def _convert_output( # noqa: PLR0913
return response

@staticmethod
def request_id(context: ServicerContext) -> str: # noqa: ARG004
return uuid.uuid4().hex
def request_id(context: ServicerContext) -> str:
metadata = context.invocation_metadata()
if not metadata:
return uuid.uuid4().hex

correlation_id = dict(metadata).get("x-correlation-id")
dtrifiro marked this conversation as resolved.
Show resolved Hide resolved

if not correlation_id:
return uuid.uuid4().hex

return correlation_id
dtrifiro marked this conversation as resolved.
Show resolved Hide resolved

async def _validate_and_convert_params(
self,
Expand Down
27 changes: 27 additions & 0 deletions tests/test_grpc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,30 @@ def test_lora_request(grpc_client, lora_adapter_name):
response = grpc_client.make_request("hello", adapter_id=lora_adapter_name)

assert response.text


def test_request_id(grpc_client, mocker):
from vllm_tgis_adapter.grpc.grpc_server import TextGenerationService, uuid

spy = mocker.spy(TextGenerationService, "request_id")
response = grpc_client.make_request(
"The answer to life the universe and everything is ",
metadata=[("x-correlation-id", "dummy-correlation-id")],
)
assert response.text

spy.assert_called_once()
assert spy.spy_return == "dummy-correlation-id"

spy.reset_mock()

request_id = uuid.uuid4()
mocker.patch.object(uuid, "uuid4", return_value=request_id)

response = grpc_client.make_request(
"The answer to life the universe and everything is ",
)
assert response.text

spy.assert_called_once()
assert spy.spy_return == request_id.hex
2 changes: 2 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def make_request(
model_id: str | None = None,
max_new_tokens: int = 10,
adapter_id: str | None = None,
metadata: list[tuple[str, str]] | None = None,
) -> GenerationResponse | Sequence[GenerationResponse]:
# assert model_id # FIXME: is model_id required?

Expand All @@ -143,6 +144,7 @@ def make_request(

response = self.generation_service_stub.Generate(
request=request,
metadata=metadata,
)

if single_request:
Expand Down
Loading