Skip to content

Commit 6c829fc

Browse files
committed
Linting
Signed-off-by: Mihai Criveti <[email protected]>
1 parent 327df76 commit 6c829fc

File tree

3 files changed

+45
-46
lines changed

3 files changed

+45
-46
lines changed

docs/docs/manage/observability.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,21 @@ appears in OpenAPI / Swagger) and gzip compression is enabled by default
5252

5353
1. Ensure `ENABLE_METRICS=true` in your shell or `.env`.
5454

55-
```bash
56-
export ENABLE_METRICS=true
57-
export METRICS_CUSTOM_LABELS="env=local,team=dev"
58-
export METRICS_EXCLUDED_HANDLERS="/servers/.*/sse,/static/.*"
59-
```
55+
```bash
56+
export ENABLE_METRICS=true
57+
export METRICS_CUSTOM_LABELS="env=local,team=dev"
58+
export METRICS_EXCLUDED_HANDLERS="/servers/.*/sse,/static/.*"
59+
```
6060

6161
2. Start the gateway (development). By default the app listens on port 4444. The Prometheus endpoint will be:
6262

63-
http://localhost:4444/metrics/prometheus
63+
http://localhost:4444/metrics/prometheus
6464

6565
3. Quick check (get the first lines of exposition text):
6666

67-
```bash
68-
curl -sS http://localhost:4444/metrics/prometheus | head -n 20
69-
```
67+
```bash
68+
curl -sS http://localhost:4444/metrics/prometheus | head -n 20
69+
```
7070

7171
4. If metrics are disabled, the endpoint returns a small JSON 503 response.
7272

@@ -76,10 +76,10 @@ Add the job below to your `prometheus.yml` for local testing:
7676

7777
```yaml
7878
scrape_configs:
79-
- job_name: 'mcp-gateway'
80-
metrics_path: /metrics/prometheus
81-
static_configs:
82-
- targets: ['localhost:4444']
79+
- job_name: 'mcp-gateway'
80+
metrics_path: /metrics/prometheus
81+
static_configs:
82+
- targets: ['localhost:4444']
8383
```
8484

8585
If Prometheus runs in Docker, adjust the target host accordingly (host networking
@@ -89,32 +89,32 @@ deploying Prometheus in Kubernetes.
8989
### Grafana and dashboards
9090

9191
- Use Grafana to import dashboards for Kubernetes, PostgreSQL and Redis (IDs
92-
suggested elsewhere in the repo). For MCP Gateway app metrics, create panels
93-
for:
94-
- Request rate: `rate(http_requests_total[1m])`
95-
- Error rate: `rate(http_requests_total{status=~"5.."}[5m])`
96-
- P99 latency: `histogram_quantile(0.99, sum(rate(http_request_duration_seconds_bucket[5m])) by (le))`
92+
suggested elsewhere in the repo). For MCP Gateway app metrics, create panels
93+
for:
94+
- Request rate: `rate(http_requests_total[1m])`
95+
- Error rate: `rate(http_requests_total{status=~"5.."}[5m])`
96+
- P99 latency: `histogram_quantile(0.99, sum(rate(http_request_duration_seconds_bucket[5m])) by (le))`
9797

9898
### Common pitfalls — short guidance
9999

100100
- High-cardinality labels
101-
- Never add per-request identifiers (user IDs, full URIs, request IDs) as
102-
Prometheus labels. They explode the number of time series and can crash
103-
Prometheus memory.
104-
- Use `METRICS_CUSTOM_LABELS` only for low-cardinality labels (env, region).
101+
- Never add per-request identifiers (user IDs, full URIs, request IDs) as
102+
Prometheus labels. They explode the number of time series and can crash
103+
Prometheus memory.
104+
- Use `METRICS_CUSTOM_LABELS` only for low-cardinality labels (env, region).
105105

106106
- Compression (gzip) vs CPU
107-
- The metrics exposer in `mcpgateway.services.metrics` enables gzip by
108-
default for the `/metrics/prometheus` endpoint. Compressing the payload
109-
reduces network usage but increases CPU on scrape time. On CPU-constrained
110-
nodes consider increasing scrape interval (e.g. 15s→30s) or disabling gzip
111-
at the instrumentor layer.
107+
- The metrics exposer in `mcpgateway.services.metrics` enables gzip by
108+
default for the `/metrics/prometheus` endpoint. Compressing the payload
109+
reduces network usage but increases CPU on scrape time. On CPU-constrained
110+
nodes consider increasing scrape interval (e.g. 15s→30s) or disabling gzip
111+
at the instrumentor layer.
112112

113113
- Duplicate collectors during reloads/tests
114-
- Instrumentation registers collectors on the global Prometheus registry.
115-
When reloading the app in the same process (tests, interactive sessions)
116-
you may see "collector already registered"; restart the process or clear
117-
the registry in test fixtures.
114+
- Instrumentation registers collectors on the global Prometheus registry.
115+
When reloading the app in the same process (tests, interactive sessions)
116+
you may see "collector already registered"; restart the process or clear
117+
the registry in test fixtures.
118118

119119
### Quick checklist
120120

@@ -127,9 +127,9 @@ deploying Prometheus in Kubernetes.
127127
## Where to look in the code
128128

129129
- `mcpgateway/main.py` — wiring: imports and calls `setup_metrics(app)` from
130-
`mcpgateway.services.metrics`. The function call instruments the app at
131-
startup; the actual HTTP handler for `/metrics/prometheus` is registered by
132-
the `Instrumentator` inside `mcpgateway/services/metrics.py`.
130+
`mcpgateway.services.metrics`. The function call instruments the app at
131+
startup; the actual HTTP handler for `/metrics/prometheus` is registered by
132+
the `Instrumentator` inside `mcpgateway/services/metrics.py`.
133133
- `mcpgateway/services/metrics.py` — instrumentation implementation and env-vars.
134134
- `mcpgateway/config.py` — settings defaults and names used by the app.
135135

mcpgateway/bootstrap_db.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@
3535
from typing import Any, cast
3636

3737
# Third-Party
38-
from sqlalchemy import create_engine, inspect
39-
4038
from alembic import command
4139
from alembic.config import Config
40+
from sqlalchemy import create_engine, inspect
4241

4342
# First-Party
4443
from mcpgateway.config import settings

tests/unit/mcpgateway/test_metrics.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
- test_metrics_endpoint: Verifies that the /metrics endpoint returns Prometheus format data
1515
- test_metrics_contains_standard_metrics: Verifies key metric families exist
1616
- test_metrics_counters_increment: Ensures counters increase after requests
17-
- test_metrics_excluded_paths: Ensures excluded paths dont appear in metrics
17+
- test_metrics_excluded_paths: Ensures excluded paths don't appear in metrics
1818
- test_metrics_disabled: Ensures disabling metrics hides the endpoint
1919
"""
2020

@@ -29,26 +29,26 @@
2929
def client(monkeypatch):
3030
"""Provides a FastAPI TestClient with metrics enabled."""
3131
monkeypatch.setenv("ENABLE_METRICS", "true")
32-
32+
3333
# Clear the prometheus registry to avoid duplicates
3434
from prometheus_client import REGISTRY
3535
REGISTRY._collector_to_names.clear()
3636
REGISTRY._names_to_collectors.clear()
37-
37+
3838
# Create a fresh app instance with metrics enabled
3939
from fastapi import FastAPI
4040
from mcpgateway.services.metrics import setup_metrics
41-
41+
4242
app = FastAPI()
4343
setup_metrics(app)
44-
44+
4545
return TestClient(app)
4646

4747

4848
def test_metrics_endpoint(client):
4949
"""✅ /metrics endpoint returns Prometheus format data."""
5050
response = client.get("/metrics/prometheus")
51-
51+
5252
assert response.status_code == 200, f"Expected HTTP 200 OK, got {response.status_code}"
5353
assert "text/plain" in response.headers["content-type"]
5454
assert len(response.text) > 0, "Metrics response should not be empty"
@@ -72,7 +72,7 @@ def test_metrics_counters_increment(client):
7272

7373
# Trigger another request
7474
client.get("/health")
75-
75+
7676
# Second scrape
7777
resp2 = client.get("/metrics/prometheus")
7878
after_lines = len(resp2.text.splitlines())
@@ -94,13 +94,13 @@ def test_metrics_excluded_paths(monkeypatch):
9494
# Create fresh app with exclusions
9595
from fastapi import FastAPI
9696
from mcpgateway.services.metrics import setup_metrics
97-
97+
9898
app = FastAPI()
99-
99+
100100
@app.get("/health")
101101
async def health():
102102
return {"status": "ok"}
103-
103+
104104
setup_metrics(app)
105105
client = TestClient(app)
106106

0 commit comments

Comments
 (0)