feat: enable metrics and log blocks served per node after each experiment

Signed-off-by: Chrysostomos Nanakos <chris@include.gr>
This commit is contained in:
Chrysostomos Nanakos 2026-04-06 16:33:21 +03:00
parent 2f4e941c25
commit ff3ff04259
No known key found for this signature in database
4 changed files with 35 additions and 1 deletions

View File

@ -112,6 +112,19 @@ class CodexNode(Node[Cid, CodexMeta], ExperimentComponent):
return response.iter_content(chunk_size=chunk_size)
def blocks_sent(self, metrics_port: int = 8008) -> int:
"""Query the Prometheus metrics endpoint for blocks sent count."""
try:
metrics_url = self.codex_api_url._replace(port=metrics_port, path="/metrics")
response = requests.get(str(metrics_url), timeout=5)
response.raise_for_status()
for line in response.text.splitlines():
if line.startswith("storage_block_exchange_blocks_sent_total"):
return int(float(line.split()[1]))
except Exception:
pass
return 0
def wipe_all_datasets(self):
for dataset in list(self.hosted_datasets):
self.remove(dataset)

View File

@ -15,7 +15,7 @@ from benchmarks.core.network import (
Node,
DownloadHandle,
)
from benchmarks.logging.logging import RequestEvent, EventBoundary
from benchmarks.logging.logging import RequestEvent, EventBoundary, BlocksServedMetric
logger = logging.getLogger(__name__)
@ -119,6 +119,16 @@ class StaticDisseminationExperiment(
]
)
with experiment_stage(self, "blocks_served"):
for i, node in enumerate(self.nodes):
if hasattr(node, "blocks_sent"):
logger.info(
BlocksServedMetric(
node=node.name,
value=node.blocks_sent(),
)
)
with experiment_stage(self, "log_cooldown"):
# FIXME this is a hack to ensure that nodes get a chance to log their data before we
# run the teardown hook and remove the torrents.

View File

@ -249,6 +249,10 @@ class DownloadMetric(Metric):
dataset_name: str
class BlocksServedMetric(Metric):
name: str = "blocks_served"
class EventBoundary(Enum):
start = "start"
end = "end"
@ -279,6 +283,7 @@ def basic_log_parser() -> LogParser:
parser.register(NodeEvent)
parser.register(Metric)
parser.register(DownloadMetric)
parser.register(BlocksServedMetric)
parser.register(RequestEvent)
parser.register(ExperimentStatus)
parser.register(ExperimentStage)

View File

@ -65,6 +65,12 @@ spec:
fieldPath: metadata.name
- name: STORAGE_NAT
value: "none"
- name: STORAGE_METRICS
value: "true"
- name: STORAGE_METRICS_ADDRESS
value: "0.0.0.0"
- name: STORAGE_METRICS_PORT
value: "8008"
- name: STORAGE_BLOCK_TTL
value: {{ .Values.experiment.blockTTL | quote }}
- name: STORAGE_BLOCK_MI