Skip to content

Commit acf07cd

Browse files
fix prometheus invalid metric name (opea-project#849)
* fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent a6998a1 commit acf07cd

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

comps/cores/mega/http_service.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright (C) 2024 Intel Corporation
22
# SPDX-License-Identifier: Apache-2.0
33

4+
import re
45
from typing import Optional
56

67
from fastapi import FastAPI
@@ -35,8 +36,10 @@ def __init__(
3536
self._app = self._create_app()
3637

3738
# remove part before '@', used by register_microservice() callers, and
38-
# part after '/', added by MicroService(), to get real service name
39-
suffix = self.title.split("/")[0].split("@")[-1].lower()
39+
# part after '/', added by MicroService(), to get real service name, and
40+
# convert invalid characters to '_'
41+
suffix = re.sub(r"[^a-zA-Z0-9]", "_", self.title.split("/")[0].split("@")[-1].lower())
42+
4043
instrumentator = Instrumentator(
4144
inprogress_name=f"http_requests_inprogress_{suffix}",
4245
should_instrument_requests_inprogress=True,

0 commit comments

Comments
 (0)