Skip to content

Commit

Permalink
WIP fix: require named MicroService -> HTTPService instances
Browse files Browse the repository at this point in the history
Creating multiple MicroService()s creates multiple HTTPService()s
which creates multiple Prometheus fastapi instrumentor instances.

While latter handled that fine for ChatQnA and normal HTTP metrics,
that was not the case for its "inprogress" metrics in CI.

Therefore MicroService constructor name argument is now mandatory, so
that it can be used to make "inprogress" metrics for HTTPService
instances unique.

PS. instrumentor requires HTTPService instance specific Starlette
instance, so it cannot be made singleton.

Signed-off-by: Eero Tamminen <[email protected]>
  • Loading branch information
eero-t committed Nov 1, 2024
1 parent 2e2f4a8 commit 1c828f7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions comps/cores/mega/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(
self.input_datatype = input_datatype
self.output_datatype = output_datatype
self.service = MicroService(
self.__class__.__name__,
service_role=ServiceRoleType.MEGASERVICE,
service_type=ServiceType.GATEWAY,
host=self.host,
Expand Down
5 changes: 5 additions & 0 deletions comps/cores/mega/http_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ def __init__(
self.uvicorn_kwargs = uvicorn_kwargs or {}
self.cors = cors
self._app = self._create_app()

# remove part before '@', used by register_microservice() callers, and
# part after '/', added by MicroService(), to get real service name
suffix = self.title.split('/')[0].split('@')[-1].lower()
instrumentator = Instrumentator(
inprogress_name=f"http_requests_inprogress_{suffix}",
should_instrument_requests_inprogress=True,
inprogress_labels=True,
)
Expand Down
4 changes: 2 additions & 2 deletions comps/cores/mega/micro_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MicroService:

def __init__(
self,
name: Optional[str] = None,
name: str,
service_role: ServiceRoleType = ServiceRoleType.MICROSERVICE,
service_type: ServiceType = ServiceType.LLM,
protocol: str = "http",
Expand Down Expand Up @@ -141,7 +141,7 @@ def endpoint_path(self):


def register_microservice(
name: Optional[str] = None,
name: str,
service_role: ServiceRoleType = ServiceRoleType.MICROSERVICE,
service_type: ServiceType = ServiceType.UNDEFINED,
protocol: str = "http",
Expand Down

0 comments on commit 1c828f7

Please sign in to comment.