Skip to content

Commit

Permalink
add: namespace and pod labels to metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
SHARANTANGEDA committed Sep 27, 2024
1 parent 4001763 commit b9834fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
long_description = readme.read()
setup(
name='vishwa-fastapi-utils',
version="0.0.5",
version="0.0.6",
author="Sai Sharan Tangeda",
author_email="saisarantangeda@gmail.com",
description="Base SDK for FastAPI Utils",
Expand Down
12 changes: 11 additions & 1 deletion vishwa_labs_fastapi_utils/server/common.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import os

from fastapi import FastAPI
from starlette.middleware.gzip import GZipMiddleware
from starlette_exporter import PrometheusMiddleware, handle_metrics

from vishwa_labs_fastapi_utils.core import common
from vishwa_labs_fastapi_utils.server.route_handlers import TelemetryAPI


def instrument_server(service_name: str, app: FastAPI):
app.add_middleware(GZipMiddleware, minimum_size=1000)
app.add_middleware(PrometheusMiddleware, app_name=service_name, group_paths=True)
app.add_middleware(PrometheusMiddleware, app_name=service_name, group_paths=True,
labels={
"namespace": common.NAMESPACE,
"pod": common.POD_NAME,
"container": common.CONTAINER_NAME,
"node": os.getenv("KUBERNETES_NODE_NAME", "unknown_node")
}
)
app.add_route("/metrics", handle_metrics)

app.include_router(TelemetryAPI().router)
Expand Down

0 comments on commit b9834fc

Please sign in to comment.