Skip to content

Commit 3904431

Browse files
committed
WIP: try prometheus_client HTTP server instead of MicroService in test
Signed-off-by: Eero Tamminen <[email protected]>
1 parent 12dafb7 commit 3904431

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

tests/cores/mega/test_service_orchestrator_streaming.py

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,11 @@
88

99
import requests
1010
from fastapi.responses import StreamingResponse
11+
from prometheus_client import start_http_server
1112

12-
from comps import (
13-
MicroService,
14-
ServiceOrchestrator,
15-
ServiceRoleType,
16-
ServiceType,
17-
TextDoc,
18-
opea_microservices,
19-
register_microservice,
20-
)
21-
from comps.cores.proto.api_protocol import ChatCompletionRequest, ChatCompletionResponse
13+
from comps import ServiceOrchestrator, ServiceType, TextDoc, opea_microservices, register_microservice
2214

23-
_MEGA_PORT = 8888
15+
_METRIC_PORT = 8000
2416

2517

2618
@register_microservice(name="s1", host="0.0.0.0", port=8083, endpoint="/v1/add")
@@ -58,19 +50,13 @@ def setUpClass(cls):
5850

5951
cls.service_builder = ServiceOrchestrator()
6052

61-
cls.service_builder.add(cls.s0).add(cls.s1)
53+
# simpler?: cls.service_builder.add(cls.s0).add(cls.s1)
54+
cls.service_builder.add(opea_microservices["s0"]).add(opea_microservices["s1"])
6255
cls.service_builder.flow_to(cls.s0, cls.s1)
6356

64-
cls.service = MicroService(
65-
"megaservice",
66-
service_role=ServiceRoleType.MEGASERVICE,
67-
host="0.0.0.0",
68-
port=_MEGA_PORT,
69-
endpoint="/whatever",
70-
input_datatype=ChatCompletionRequest,
71-
output_datatype=ChatCompletionResponse,
72-
)
73-
cls.service.start()
57+
print(f"serving metrics from: http://localhost:{_METRIC_PORT}/metrics")
58+
# requires prometheus_client >= 0.20.0 (earlier versions return None)
59+
cls.server, cls.thread = start_http_server(_METRIC_PORT)
7460

7561
@classmethod
7662
def tearDownClass(cls):
@@ -79,6 +65,9 @@ def tearDownClass(cls):
7965
cls.process1.terminate()
8066
cls.process2.terminate()
8167

68+
cls.server.shutdown()
69+
cls.thread.join()
70+
8271
async def test_schedule(self):
8372
result_dict, _ = await self.service_builder.schedule(initial_inputs={"text": "hello, "})
8473
response = result_dict["s1/MicroService"]
@@ -87,9 +76,10 @@ async def test_schedule(self):
8776
async for k in response.__reduce__()[2]["body_iterator"]:
8877
self.assertEqual(self.service_builder.extract_chunk_str(k).strip(), res_expected[idx])
8978
idx += 1
90-
# check the metric increases from above
91-
r = requests.get(f"http://localhost:{_MEGA_PORT}/metrics", timeout=10)
79+
# check ServiceOrchestrator "megaservice_*" metrics resulting from above processing
80+
r = await requests.get(f"http://localhost:{_METRIC_PORT}/metrics", timeout=5)
9281
self.assertEqual(r.status_code, 200)
82+
# TODO: verify that the expected metrics are present
9383
print(r.text)
9484

9585
def test_extract_chunk_str(self):

0 commit comments

Comments
 (0)