mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-05-27 16:25:12 +02:00
Replace hallucinated relative imports with correct absolute imports across the ontology query package, and fix OntologyMatcher reference to match the actual class name OntologyMatcherForQueries. Simplify test to use standard imports instead of importlib hack. Cosmetic, but simpler imports provides undeterministic imports in a dev environment, and also means we're properly testing linkage
56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
"""
|
|
Tests for ontology monitoring metrics.
|
|
"""
|
|
|
|
from trustgraph.query.ontology.monitoring import (
|
|
PerformanceMonitor,
|
|
_extract_metric_label,
|
|
)
|
|
|
|
|
|
def test_extract_metric_label_reads_unquoted_label_value():
|
|
metric_name = "cache_requests_total{cache_type=entity,component=ontology}"
|
|
|
|
assert _extract_metric_label(metric_name, "cache_type") == "entity"
|
|
|
|
|
|
def test_extract_metric_label_reads_quoted_label_value():
|
|
metric_name = 'cache_requests_total{cache_type="entity",component="ontology"}'
|
|
|
|
assert _extract_metric_label(metric_name, "cache_type") == "entity"
|
|
|
|
|
|
def test_extract_metric_label_returns_none_when_label_missing():
|
|
metric_name = "cache_requests_total{component=ontology}"
|
|
|
|
assert _extract_metric_label(metric_name, "cache_type") is None
|
|
|
|
|
|
def test_performance_report_ignores_counters_without_cache_type_label():
|
|
monitor = PerformanceMonitor({"enabled": False})
|
|
monitor.metrics_collector.increment(
|
|
"cache_requests_total",
|
|
labels={"component": "ontology"},
|
|
)
|
|
monitor.metrics_collector.increment(
|
|
"cache_type=not_a_label",
|
|
labels={"component": "ontology"},
|
|
)
|
|
monitor.metrics_collector.increment(
|
|
"cache_requests_total",
|
|
labels={"cache_type": "entity"},
|
|
)
|
|
monitor.metrics_collector.increment(
|
|
"cache_hits_total",
|
|
labels={"cache_type": "entity"},
|
|
)
|
|
|
|
report = monitor.get_performance_report()
|
|
|
|
assert report["cache_performance"] == {
|
|
"entity": {
|
|
"hit_rate": 1.0,
|
|
"total_requests": 1.0,
|
|
"total_hits": 1.0,
|
|
}
|
|
}
|