From acf07cd90dfcd5f9035c9993d67f2339f4c64df3 Mon Sep 17 00:00:00 2001 From: Sihan Chen <39623753+Spycsh@users.noreply.github.com> Date: Mon, 4 Nov 2024 12:00:02 +0800 Subject: [PATCH] fix prometheus invalid metric name (#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> --- comps/cores/mega/http_service.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/comps/cores/mega/http_service.py b/comps/cores/mega/http_service.py index 62b9cd5e3..9efc55e3f 100644 --- a/comps/cores/mega/http_service.py +++ b/comps/cores/mega/http_service.py @@ -1,6 +1,7 @@ # Copyright (C) 2024 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import re from typing import Optional from fastapi import FastAPI @@ -35,8 +36,10 @@ def __init__( self._app = self._create_app() # remove part before '@', used by register_microservice() callers, and - # part after '/', added by MicroService(), to get real service name - suffix = self.title.split("/")[0].split("@")[-1].lower() + # part after '/', added by MicroService(), to get real service name, and + # convert invalid characters to '_' + suffix = re.sub(r"[^a-zA-Z0-9]", "_", self.title.split("/")[0].split("@")[-1].lower()) + instrumentator = Instrumentator( inprogress_name=f"http_requests_inprogress_{suffix}", should_instrument_requests_inprogress=True,