mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-08 12:52:12 +02:00
fix: safe parsing of Prometheus metric labels in ontology monitoring
Issue #873: The cache_type label extraction via chained split() calls is fragile and would crash with IndexError if the guard on line 477 is ever moved or removed. Add a length check on the split result before indexing, making the code resilient to future refactoring.
This commit is contained in:
parent
4f2445bf71
commit
a943c4d4b6
1 changed files with 5 additions and 2 deletions
|
|
@ -475,8 +475,11 @@ class PerformanceMonitor:
|
|||
cache_types = set()
|
||||
for metric_name in self.metrics_collector.counters.keys():
|
||||
if 'cache_type=' in metric_name:
|
||||
cache_type = metric_name.split('cache_type=')[1].split(',')[0].split('}')[0]
|
||||
cache_types.add(cache_type)
|
||||
# Safely extract cache_type label value
|
||||
parts = metric_name.split('cache_type=')
|
||||
if len(parts) >= 2:
|
||||
cache_type = parts[1].split(',')[0].split('}')[0]
|
||||
cache_types.add(cache_type)
|
||||
|
||||
for cache_type in cache_types:
|
||||
labels = {'cache_type': cache_type}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue