Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def __init__(self, mongodb_uri, cache_ttl=60):
logger.info(" Tool metrics: %s", self.enable_tool_metrics)
logger.info(" File metrics: %s", self.enable_file_metrics)

logger.info("Cache configuration:")
logger.info(" Cache enabled: %s", self.cache_enabled)
logger.info(" Cache TTL: %d seconds", self.cache_ttl)

def _start_background_collection(self):
"""
Start background thread for metrics collection.
Expand Down Expand Up @@ -115,10 +119,6 @@ def _collect_loop(self):
# Sleep for cache_ttl seconds or until stop event
self._stop_collection.wait(self.cache_ttl)

logger.info("Cache configuration:")
logger.info(" Cache enabled: %s", self.cache_enabled)
logger.info(" Cache TTL: %d seconds", self.cache_ttl)

def describe(self):
"""
Return an empty descriptor list.
Expand All @@ -134,7 +134,14 @@ def describe(self):
def collect(self):
"""
Collect metrics and yield Prometheus metrics.
If caching is enabled, serve from cache. Otherwise, collect fresh metrics.

Behavior depends on cache state:
- Cache enabled and populated: serve cached metrics.
- Cache enabled but still warming up (background thread hasn't
finished its first collection): yield nothing. The next scrape
after warm-up will see real data. This avoids blocking the
scrape and racing the background thread.
- Cache disabled: collect fresh metrics on every scrape.
"""
if self.cache_enabled:
# Serve from cache
Expand Down