Skip to content

Commit

Permalink
Support prometheus metrics for opea microservices (#225)
Browse files Browse the repository at this point in the history
* add preload env in run.sh

Signed-off-by: lvliang-intel <[email protected]>

* Support prometheus metrics for all opea microservices

Signed-off-by: lvliang-intel <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Signed-off-by: lvliang-intel <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
lvliang-intel and pre-commit-ci[bot] authored Jun 21, 2024
1 parent 4468ed2 commit 7589142
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions comps/cores/mega/http_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ httpx
opentelemetry-api
opentelemetry-exporter-otlp
opentelemetry-sdk
prometheus-fastapi-instrumentator
pyyaml
requests
shortuuid
2 changes: 2 additions & 0 deletions tests/cores/mega/test_microservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down

0 comments on commit 7589142

Please sign in to comment.