Skip to content

Commit 42dc8b5

Browse files
committed
Add stat logger plugin unit tests
Signed-off-by: tovam <tovam@pliops.com>
1 parent 222a2e4 commit 42dc8b5

File tree

5 files changed

+103
-23
lines changed

5 files changed

+103
-23
lines changed

.buildkite/test-pipeline.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,11 @@ steps:
944944
- pytest -v -s plugins_tests/test_io_processor_plugins.py
945945
- pip uninstall prithvi_io_processor_plugin -y
946946
# end io_processor plugins test
947+
# begin stat_logger plugins test
948+
- pip install -e ./plugins/vllm_add_dummy_stat_logger
949+
- pytest -v -s plugins_tests/test_stats_logger_plugins.py
950+
- pip uninstall vllm_add_dummy_stat_logger -y
951+
# end stat_logger plugins test
947952
# other tests continue here:
948953
- pytest -v -s plugins_tests/test_scheduler_plugins.py
949954
- pip install -e ./plugins/vllm_add_dummy_model
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3+
4+
from setuptools import setup
5+
6+
setup(
7+
name='vllm_add_dummy_stat_logger',
8+
version='0.1',
9+
packages=['vllm_add_dummy_stat_logger'],
10+
entry_points={
11+
'vllm.stat_logger_plugins': [
12+
'dummy_stat_logger = vllm_add_dummy_stat_logger.dummy_stat_logger:DummyStatLogger' # noqa
13+
]
14+
})
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3+
4+
from vllm.v1.metrics.loggers import StatLoggerBase
5+
6+
7+
class DummyStatLogger(StatLoggerBase):
8+
"""
9+
A dummy stat logger for testing purposes.
10+
Implements the minimal interface expected by StatLoggerManager.
11+
"""
12+
13+
def __init__(self, vllm_config, engine_idx=0):
14+
self.vllm_config = vllm_config
15+
self.engine_idx = engine_idx
16+
self.recorded = []
17+
self.logged = False
18+
self.engine_initialized = False
19+
20+
def record(self, scheduler_stats, iteration_stats, engine_idx):
21+
self.recorded.append((scheduler_stats, iteration_stats, engine_idx))
22+
23+
def log(self):
24+
self.logged = True
25+
26+
def log_engine_initialized(self):
27+
self.engine_initialized = True
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3+
4+
import pytest
5+
from vllm_add_dummy_stat_logger.dummy_stat_logger import DummyStatLogger
6+
7+
from vllm.config import VllmConfig
8+
from vllm.engine.arg_utils import AsyncEngineArgs
9+
from vllm.v1.engine.async_llm import AsyncLLM
10+
from vllm.v1.metrics.loggers import load_stat_logger_plugin_factories
11+
12+
13+
def test_stat_logger_plugin_is_discovered(monkeypatch: pytest.MonkeyPatch):
14+
with monkeypatch.context() as m:
15+
m.setenv("VLLM_PLUGINS", "dummy_stat_logger")
16+
17+
factories = load_stat_logger_plugin_factories()
18+
# there should only be our dummy plugin
19+
factories = load_stat_logger_plugin_factories()
20+
assert len(factories) == 1, f"Expected 1 factory, got {len(factories)}"
21+
assert factories[0] is DummyStatLogger, \
22+
f"Expected DummyStatLogger class, got {factories[0]}"
23+
24+
# instantiate and confirm the right type
25+
vllm_config = VllmConfig()
26+
instance = factories[0](vllm_config)
27+
assert isinstance(instance, DummyStatLogger)
28+
29+
30+
def test_no_plugins_loaded_if_env_empty(monkeypatch: pytest.MonkeyPatch):
31+
with monkeypatch.context() as m:
32+
m.setenv("VLLM_PLUGINS", "")
33+
34+
factories = load_stat_logger_plugin_factories()
35+
assert factories == []
36+
37+
38+
@pytest.mark.asyncio
39+
async def test_stat_logger_plugin_integration_with_engine(
40+
monkeypatch: pytest.MonkeyPatch):
41+
with monkeypatch.context() as m:
42+
m.setenv("VLLM_PLUGINS", "dummy_stat_logger")
43+
44+
engine_args = AsyncEngineArgs(
45+
model="facebook/opt-125m",
46+
enforce_eager=True, # reduce test time
47+
)
48+
49+
engine = AsyncLLM.from_engine_args(engine_args=engine_args)
50+
51+
assert len(engine.logger_manager.per_engine_logger_dict[0]) == 2
52+
assert isinstance(engine.logger_manager.per_engine_logger_dict[0][0],
53+
DummyStatLogger)
54+
55+
engine.shutdown()

tests/v1/metrics/test_engine_logger_apis.py

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,12 @@
44

55
import pytest
66

7+
from tests.plugins.vllm_add_dummy_stat_logger.vllm_add_dummy_stat_logger.dummy_stat_logger import ( # noqa E501
8+
DummyStatLogger)
79
from vllm.v1.engine.async_llm import AsyncEngineArgs, AsyncLLM
810
from vllm.v1.metrics.ray_wrappers import RayPrometheusStatLogger
911

1012

11-
class DummyStatLogger:
12-
"""
13-
A dummy stat logger for testing purposes.
14-
Implements the minimal interface expected by StatLoggerManager.
15-
"""
16-
17-
def __init__(self, vllm_config, engine_idx):
18-
self.vllm_config = vllm_config
19-
self.engine_idx = engine_idx
20-
self.recorded = []
21-
self.logged = False
22-
self.engine_initialized = False
23-
24-
def record(self, scheduler_stats, iteration_stats, engine_idx):
25-
self.recorded.append((scheduler_stats, iteration_stats, engine_idx))
26-
27-
def log(self):
28-
self.logged = True
29-
30-
def log_engine_initialized(self):
31-
self.engine_initialized = True
32-
33-
3413
@pytest.fixture
3514
def log_stats_enabled_engine_args():
3615
"""

0 commit comments

Comments
 (0)