Skip to content

Commit 366b6cd

Browse files
committed
add prometheus friendly app name
1 parent 0cbf880 commit 366b6cd

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

packages/service-library/src/servicelib/utils_meta.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ def app_name(self) -> str:
5050
"""
5151
return self._distribution.metadata["Name"]
5252

53+
@property
54+
def prometheus_friendly_app_name(self) -> str:
55+
"""
56+
Returns a version of the app name which is compatible with Prometheus metrics naming conventions (no dashes).
57+
"""
58+
return self.app_name.replace("-", "_")
59+
5360
@property
5461
def version(self) -> Version:
5562
return Version(self._distribution.version)

packages/service-library/tests/test_utils_meta.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def test_app_name(
6060
info = PackageInfo(package_name=package_name)
6161
if is_correct_app_name:
6262
assert info.app_name == app_name
63+
assert info.prometheus_friendly_app_name == app_name.replace("-", "_")
6364
else:
6465
with pytest.raises(ValueError):
6566
_ = PackageInfo(package_name=package_name)

services/web/server/src/simcore_service_webserver/_meta.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
# legacy consts
2121
APP_NAME: Final[str] = info.app_name
22+
PROMETHEUS_FRIENDLY_APP_NAME: Final[str] = info.prometheus_friendly_app_name
2223
api_version_prefix: str = API_VTAG
2324

2425

services/web/server/src/simcore_service_webserver/diagnostics/_monitoring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def setup_monitoring(app: web.Application):
5555
)
5656

5757
monitor_services.add_instrumentation(
58-
app, get_collector_registry(app), _meta.APP_NAME
58+
app, get_collector_registry(app), _meta.PROMETHEUS_FRIENDLY_APP_NAME
5959
)
6060

6161
# on-the fly stats

0 commit comments

Comments
 (0)