Slackbot
05/01/2023, 3:50 PMSean
05/02/2023, 6:00 AMbentoml.metrics
? Do you want to ensure metrics gets recorded and emitted correctly? In that case, would it be better to write integration test against the /metrics
endpoint?Ashish Singh
05/02/2023, 12:27 PMdef test_chi_squared_gauge_metric():
label = {}
function_that_will_inc_metric()
)
after = get_metric_value("metric", label)
assert after == 1.0
get_metric_value
looks like this
def get_metric_value(
prom_client: PrometheusClient,
event: str,
result_label: Dict[str, Any],
) -> int | float:
return REGISTRY.get_sample_value(event, result_label) or 0
and change I have done because REGISTRY
is not available directly that works locally, is add a fixture
@pytest.fixture()
def fixture_metrics_client() -> PrometheusClient:
"""This fixtures return a PrometheusClient instance that can be used for testing."""
return BentoMLContainer.metrics_client.get()
But after this change all tests work locally, but all metric test failed on circleci, log points to this code in prom client
@property
def prometheus_client(self):
if self.multiproc and not self._imported:
# step 1: check environment
assert (
"prometheus_client" not in sys.modules
), "prometheus_client is already imported, multiprocessing will not work properly"
assert (
self.multiproc_dir
), f"Invalid prometheus multiproc directory: {self.multiproc_dir}"
> assert os.path.isdir(self.multiproc_dir)
E AssertionError
Not able to assert multiproc_dir
Ashish Singh
05/02/2023, 12:36 PM/bentoml/prometheus_multiproc_dir
to create this folderAshish Singh
05/02/2023, 3:33 PMpyproject.toml
in bentoml repo, which is basically the plugin for pytest
[tool.pytest.ini_options]
addopts = ["-rfEX", "-pbentoml.testing.pytest.plugin"]
Ashish Singh
05/02/2023, 3:35 PMmultiproc
folder that bentoml creates was not there, adding this plugin creates the folder prometheus_multiproc_dir
and then all the tests pass, thanks for all the time and effort 🙏Chaoyu
05/02/2023, 3:56 PM