diff --git a/comps/cores/mega/http_service.py b/comps/cores/mega/http_service.py index 470059b824..86c5ba8d5f 100644 --- a/comps/cores/mega/http_service.py +++ b/comps/cores/mega/http_service.py @@ -4,6 +4,7 @@ from typing import Optional from fastapi import FastAPI +from prometheus_fastapi_instrumentator import Instrumentator from uvicorn import Config, Server from .base_service import BaseService @@ -32,6 +33,7 @@ def __init__( self.uvicorn_kwargs = uvicorn_kwargs or {} self.cors = cors self._app = self._create_app() + Instrumentator().instrument(self._app).expose(self._app) @property def app(self): diff --git a/requirements.txt b/requirements.txt index 12e0cdd9cb..6a453d50fb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ httpx opentelemetry-api opentelemetry-exporter-otlp opentelemetry-sdk +prometheus-fastapi-instrumentator pyyaml requests shortuuid diff --git a/tests/cores/mega/test_microservice.py b/tests/cores/mega/test_microservice.py index 126fb03ca5..dbaff9a760 100644 --- a/tests/cores/mega/test_microservice.py +++ b/tests/cores/mega/test_microservice.py @@ -31,6 +31,8 @@ def test_add_route(self): response = self.client.post("/v1/add", json={"text": "Hello, "}) self.assertEqual(response.status_code, 200) self.assertEqual(response.json()["text"], "Hello, OPEA Project!") + response = self.client.get("/metrics") + self.assertEqual(response.status_code, 200) if __name__ == "__main__":