Skip to content

Commit 96ef6ef

Browse files
committed
prometheus: per-namespace track scrape, non-overlapping targets
/metrics/track matches a namespace prefix, so a parent and its child return the same tracks and every aggregate double-counts. Targets are top-level namespaces only: they do not overlap and their prefixes still cover everything beneath them. The endpoint documents itself as enabled by default but the resolved value was false, so it shipped dead; the deployed config states it explicitly.
1 parent d6c9278 commit 96ef6ef

6 files changed

Lines changed: 26 additions & 12 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@ docker/grafana/provisioning/dashboards/archive/
4343

4444
# Version stamp for source trees with no .git (cmake/MoqxVersion.cmake).
4545
/VERSION
46+
47+
# Python bytecode from local tooling.
48+
__pycache__/
49+
*.pyc

docker/config.docker.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@ services:
5959

6060
admin:
6161
port: ${MOQX_ADMIN_PORT}
62+
track_metrics_enabled: true
6263
address: "${MOQX_BIND_ADDR}"
6364
plaintext: true

docker/prometheus/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ read as "no live tracks".
2222
Namespaces come and go with events, so the target list cannot be static.
2323
`namespace-targets.py` walks the relay's `/state` namespace tree every 30s and
2424
writes one target per namespace to a file Prometheus rereads without a restart.
25-
It collects every node carrying a namespace rather than only the leaves, since
26-
tracks can be published at any depth.
25+
It emits only top-level namespaces. The endpoint matches a prefix, so scraping
26+
a parent and its child would return the same tracks twice and every aggregate
27+
would double-count; top-level namespaces do not overlap, and their prefixes
28+
still cover every track beneath them. If one grows past the limit it has to be
29+
split by descending a level.
2730

2831
Targets are namespace values in the moq-transport safe form — `[A-Za-z0-9_]`
2932
passes through, every other byte becomes `.<hex>`, tuple elements join with
-3.58 KB
Binary file not shown.

docker/prometheus/namespace-targets.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,20 @@ def safe_namespace(tuple_elements):
3838
return "-".join(safe_element(e) for e in tuple_elements)
3939

4040

41-
def walk(node, found):
42-
"""Collect every node carrying a namespace, not just the leaves: tracks can
43-
be published at any depth."""
44-
full = node.get("full_namespace") or []
45-
if full:
46-
found.append(full)
47-
for child in (node.get("children") or {}).values():
48-
walk(child, found)
41+
def top_level(tree):
42+
"""Only the tree's immediate children.
43+
44+
The endpoint matches a namespace prefix, so scraping both a parent and its
45+
child returns the same tracks twice and every aggregate double-counts.
46+
Top-level namespaces do not overlap each other and their prefixes still
47+
cover every track beneath them.
48+
"""
49+
out = []
50+
for child in (tree.get("children") or {}).values():
51+
full = child.get("full_namespace") or []
52+
if full:
53+
out.append(full)
54+
return out
4955

5056

5157
def namespaces():
@@ -55,7 +61,7 @@ def namespaces():
5561
for service in (state.get("services") or {}).values():
5662
tree = service.get("namespace_tree")
5763
if tree:
58-
walk(tree, found)
64+
found.extend(top_level(tree))
5965
# A namespace can appear under more than one service.
6066
return sorted({tuple(ns) for ns in found})
6167

src/config/Config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ struct ServiceConfig {
227227
struct AdminConfig {
228228
folly::SocketAddress address;
229229
std::optional<TlsConfig> tls;
230-
bool trackMetricsEnabled{false};
230+
bool trackMetricsEnabled{true};
231231
uint32_t trackMetricsLimit{10};
232232
uint32_t trackMetricsMaxLimit{1000};
233233
};

0 commit comments

Comments
 (0)