Metrics: don't count the dashboard's own /api/v2/metrics polling (#135)
The ops dashboard polls the metrics endpoint every few seconds; counting those hits just shows the monitor watching itself and inflates the inbound totals. Skip the 'metrics' category in record_inbound (so it's excluded from inbound_total too), and hide it in the dashboard's inbound list defensively.
This commit is contained in:
parent
d6a62cc2de
commit
19f4965258
2 changed files with 15 additions and 0 deletions
|
|
@ -97,6 +97,10 @@ def classify_inbound(path: str, base: str = "") -> str:
|
||||||
|
|
||||||
def record_inbound(category: str, status) -> None:
|
def record_inbound(category: str, status) -> None:
|
||||||
"""Count one inbound request in ``category``, bucketed by status class."""
|
"""Count one inbound request in ``category``, bucketed by status class."""
|
||||||
|
# The metrics endpoint is polled by the dashboard itself — counting it would just
|
||||||
|
# show the monitor watching itself, so it's excluded from traffic entirely.
|
||||||
|
if category == "metrics":
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
bucket = _status_bucket(status)
|
bucket = _status_bucket(status)
|
||||||
with _lock:
|
with _lock:
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,17 @@ def test_record_inbound_buckets_by_status():
|
||||||
assert snap["inbound_total"] == 4
|
assert snap["inbound_total"] == 4
|
||||||
|
|
||||||
|
|
||||||
|
def test_metrics_endpoint_polling_is_not_counted():
|
||||||
|
# The dashboard polls the metrics endpoint; that self-traffic must be excluded.
|
||||||
|
m = _fresh()
|
||||||
|
m.record_inbound("metrics", 200)
|
||||||
|
m.record_inbound("metrics", 404)
|
||||||
|
m.record_inbound("api:place", 200)
|
||||||
|
snap = m.snapshot()
|
||||||
|
assert "metrics" not in snap["inbound"]
|
||||||
|
assert snap["inbound_total"] == 1
|
||||||
|
|
||||||
|
|
||||||
def test_record_outbound_by_source_and_outcome():
|
def test_record_outbound_by_source_and_outcome():
|
||||||
m = _fresh()
|
m = _fresh()
|
||||||
m.record_outbound("history_fetch", "ok")
|
m.record_outbound("history_fetch", "ok")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue