babylon.metrics.interfaces
Metrics collector interfaces and protocols.
This module defines the contract that all metrics collectors must implement, enabling dependency injection and testability throughout the codebase.
Classes
|
Protocol defining the contract for metrics collectors. |
- class babylon.metrics.interfaces.MetricsCollectorProtocol(*args, **kwargs)[source]
Bases:
ProtocolProtocol defining the contract for metrics collectors.
This protocol ensures both the real MetricsCollector and any test doubles (spies, mocks) implement the same interface.
The protocol follows the “Dumb Spy” pattern for test doubles: implementations should record what was called, not calculate statistics. Statistical analysis belongs in the production MetricsCollector only.
Example
def process_data(collector: MetricsCollectorProtocol) -> None: collector.increment("items_processed") with collector.time("processing_duration"): # ... do work ... pass
- gauge(name, value)[source]
Set a gauge value.
Gauges represent point-in-time values that can go up or down.
- time(name)[source]
Context manager for timing operations.
- Parameters:
name (
str) – Timer name.- Return type:
- Returns:
Context manager that records duration on exit.
Example
with collector.time("embedding.generation"): embeddings = generate_embeddings(texts)
- clear()[source]
Clear all recorded metrics.
Used primarily for testing or resetting between game sessions.
- Return type:
- __init__(*args, **kwargs)