Code import - branch main
This commit is contained in:
215
tests/unit/test_metrics.py
Normal file
215
tests/unit/test_metrics.py
Normal file
@@ -0,0 +1,215 @@
|
||||
# tests/unit/test_metrics.py
|
||||
|
||||
from prometheus_client import Counter, Gauge, Histogram
|
||||
|
||||
import ingestor.metrics as metrics
|
||||
|
||||
# --- Test Functions for Each Metric (Corrected for v0.22.0 _name behavior) ---
|
||||
|
||||
|
||||
def test_ingestor_tag_written_count():
|
||||
"""Verify the definition of INGESTOR_TAG_WRITTEN_COUNT."""
|
||||
assert metrics.TAG_WRITTEN_COUNT is not None
|
||||
assert isinstance(metrics.TAG_WRITTEN_COUNT, Counter)
|
||||
assert metrics.TAG_WRITTEN_COUNT._name == 'ingestor_tag_written_count'
|
||||
assert set(metrics.TAG_WRITTEN_COUNT._labelnames) == {'pod_id', 'tag_name', 'collection_name'}
|
||||
|
||||
|
||||
def test_app_loop_count():
|
||||
"""Verify the definition of APP_LOOP_COUNT."""
|
||||
assert metrics.APP_LOOP_COUNT is not None
|
||||
assert isinstance(metrics.APP_LOOP_COUNT, Counter)
|
||||
assert metrics.APP_LOOP_COUNT._name == 'app_main_loop' # REMOVED _total
|
||||
assert set(metrics.APP_LOOP_COUNT._labelnames) == {'pod_id'}
|
||||
|
||||
|
||||
def test_app_loop_duration():
|
||||
"""Verify the definition of APP_LOOP_DURATION."""
|
||||
assert metrics.APP_LOOP_DURATION is not None
|
||||
assert isinstance(metrics.APP_LOOP_DURATION, Histogram)
|
||||
assert (
|
||||
metrics.APP_LOOP_DURATION._name == 'app_main_loop_duration_seconds'
|
||||
) # Histograms don't have _total
|
||||
assert set(metrics.APP_LOOP_DURATION._labelnames) == {'pod_id'}
|
||||
|
||||
|
||||
def test_app_errors_total():
|
||||
"""Verify the definition of APP_ERRORS_TOTAL."""
|
||||
assert metrics.APP_ERRORS_TOTAL is not None
|
||||
assert isinstance(metrics.APP_ERRORS_TOTAL, Counter)
|
||||
assert metrics.APP_ERRORS_TOTAL._name == 'app_errors' # REMOVED _total
|
||||
assert set(metrics.APP_ERRORS_TOTAL._labelnames) == {'pod_id'}
|
||||
|
||||
|
||||
def test_app_up():
|
||||
"""Verify the definition of APP_UP."""
|
||||
assert metrics.APP_UP is not None
|
||||
assert isinstance(metrics.APP_UP, Gauge)
|
||||
assert metrics.APP_UP._name == 'app_up' # Gauges don't have _total
|
||||
assert set(metrics.APP_UP._labelnames) == {'pod_id'}
|
||||
|
||||
|
||||
def test_active_ingestors():
|
||||
"""Verify the definition of ACTIVE_INGESTORS."""
|
||||
assert metrics.ACTIVE_INGESTORS is not None
|
||||
assert isinstance(metrics.ACTIVE_INGESTORS, Gauge)
|
||||
assert metrics.ACTIVE_INGESTORS._name == 'ingestor_active_total'
|
||||
assert set(metrics.ACTIVE_INGESTORS._labelnames) == {'pod_id'}
|
||||
|
||||
|
||||
def test_slots_total():
|
||||
"""Verify the definition of SLOTS_TOTAL."""
|
||||
assert metrics.SLOTS_TOTAL is not None
|
||||
assert isinstance(metrics.SLOTS_TOTAL, Gauge)
|
||||
assert metrics.SLOTS_TOTAL._name == 'ingestor_slots_total'
|
||||
assert set(metrics.SLOTS_TOTAL._labelnames) == {'pod_id'}
|
||||
|
||||
|
||||
def test_leases_total():
|
||||
"""Verify the definition of LEASES_TOTAL."""
|
||||
assert metrics.LEASES_TOTAL is not None
|
||||
assert isinstance(metrics.LEASES_TOTAL, Gauge)
|
||||
assert metrics.LEASES_TOTAL._name == 'ingestor_leases_total'
|
||||
assert set(metrics.LEASES_TOTAL._labelnames) == {'pod_id'}
|
||||
|
||||
|
||||
def test_slots_managed():
|
||||
"""Verify the definition of SLOTS_MANAGED."""
|
||||
assert metrics.SLOTS_MANAGED is not None
|
||||
assert isinstance(metrics.SLOTS_MANAGED, Gauge)
|
||||
assert metrics.SLOTS_MANAGED._name == 'ingestor_slots_managed_current'
|
||||
assert set(metrics.SLOTS_MANAGED._labelnames) == {'pod_id'}
|
||||
|
||||
|
||||
def test_slots_acquired():
|
||||
"""Verify the definition of SLOTS_ACQUIRED."""
|
||||
assert metrics.SLOTS_ACQUIRED is not None
|
||||
assert isinstance(metrics.SLOTS_ACQUIRED, Counter)
|
||||
assert metrics.SLOTS_ACQUIRED._name == 'ingestor_slots_acquired' # REMOVED _total
|
||||
assert set(metrics.SLOTS_ACQUIRED._labelnames) == {'pod_id'}
|
||||
|
||||
|
||||
def test_slots_released():
|
||||
"""Verify the definition of SLOTS_RELEASED."""
|
||||
assert metrics.SLOTS_RELEASED is not None
|
||||
assert isinstance(metrics.SLOTS_RELEASED, Counter)
|
||||
assert metrics.SLOTS_RELEASED._name == 'ingestor_slots_released' # REMOVED _total
|
||||
assert set(metrics.SLOTS_RELEASED._labelnames) == {'pod_id'}
|
||||
|
||||
|
||||
def test_opc_managers_active():
|
||||
"""Verify the definition of OPC_MANAGERS_ACTIVE."""
|
||||
assert metrics.OPC_MANAGERS_ACTIVE is not None
|
||||
assert isinstance(metrics.OPC_MANAGERS_ACTIVE, Gauge)
|
||||
assert metrics.OPC_MANAGERS_ACTIVE._name == 'ingestor_opc_managers_active'
|
||||
assert set(metrics.OPC_MANAGERS_ACTIVE._labelnames) == {'pod_id'}
|
||||
|
||||
|
||||
def test_opc_subscription_errors():
|
||||
"""Verify the definition of OPC_SUBSCRIPTION_ERRORS."""
|
||||
assert metrics.OPC_SUBSCRIPTION_ERRORS is not None
|
||||
assert isinstance(metrics.OPC_SUBSCRIPTION_ERRORS, Counter)
|
||||
assert (
|
||||
metrics.OPC_SUBSCRIPTION_ERRORS._name == 'ingestor_opc_subscription_errors'
|
||||
) # REMOVED _total
|
||||
assert set(metrics.OPC_SUBSCRIPTION_ERRORS._labelnames) == {
|
||||
'pod_id',
|
||||
'server',
|
||||
'slot',
|
||||
}
|
||||
|
||||
|
||||
def test_opc_connections_total():
|
||||
"""Verify the definition of OPC_CONNECTIONS_TOTAL."""
|
||||
assert metrics.OPC_CONNECTIONS_TOTAL is not None
|
||||
assert isinstance(metrics.OPC_CONNECTIONS_TOTAL, Counter)
|
||||
assert metrics.OPC_CONNECTIONS_TOTAL._name == 'opc_connections_initiated' # REMOVED _total
|
||||
assert set(metrics.OPC_CONNECTIONS_TOTAL._labelnames) == {'pod_id', 'server_name'}
|
||||
|
||||
|
||||
def test_opc_connections_failed():
|
||||
"""Verify the definition of OPC_CONNECTIONS_FAILED."""
|
||||
assert metrics.OPC_CONNECTIONS_FAILED is not None
|
||||
assert isinstance(metrics.OPC_CONNECTIONS_FAILED, Counter)
|
||||
assert metrics.OPC_CONNECTIONS_FAILED._name == 'opc_connections_failed' # REMOVED _total
|
||||
assert set(metrics.OPC_CONNECTIONS_FAILED._labelnames) == {'pod_id', 'server_name'}
|
||||
|
||||
|
||||
def test_opc_connection_status():
|
||||
"""Verify the definition of OPC_CONNECTION_STATUS."""
|
||||
assert metrics.OPC_CONNECTION_STATUS is not None
|
||||
assert isinstance(metrics.OPC_CONNECTION_STATUS, Gauge)
|
||||
assert metrics.OPC_CONNECTION_STATUS._name == 'opc_connection_status'
|
||||
assert set(metrics.OPC_CONNECTION_STATUS._labelnames) == {
|
||||
'pod_id',
|
||||
'server_name',
|
||||
'server_url',
|
||||
}
|
||||
|
||||
|
||||
def test_opc_subscriptions_created():
|
||||
"""Verify the definition of OPC_SUBSCRIPTIONS_CREATED."""
|
||||
assert metrics.OPC_SUBSCRIPTIONS_CREATED is not None
|
||||
assert isinstance(metrics.OPC_SUBSCRIPTIONS_CREATED, Counter)
|
||||
assert metrics.OPC_SUBSCRIPTIONS_CREATED._name == 'opc_subscriptions_created' # REMOVED _total
|
||||
assert set(metrics.OPC_SUBSCRIPTIONS_CREATED._labelnames) == {
|
||||
'pod_id',
|
||||
'server_name',
|
||||
'slot_name',
|
||||
}
|
||||
|
||||
|
||||
def test_opc_tags_subscribed():
|
||||
"""Verify the definition of OPC_TAGS_SUBSCRIBED."""
|
||||
assert metrics.OPC_TAGS_SUBSCRIBED is not None
|
||||
assert isinstance(metrics.OPC_TAGS_SUBSCRIBED, Gauge)
|
||||
assert metrics.OPC_TAGS_SUBSCRIBED._name == 'opc_tags_subscribed_current'
|
||||
assert set(metrics.OPC_TAGS_SUBSCRIBED._labelnames) == {'pod_id', 'server_name'}
|
||||
|
||||
|
||||
def test_opc_cycles_without_data():
|
||||
"""Verify the definition of OPC_CYCLES_WITHOUT_DATA."""
|
||||
assert metrics.OPC_CYCLES_WITHOUT_DATA is not None
|
||||
assert isinstance(metrics.OPC_CYCLES_WITHOUT_DATA, Gauge)
|
||||
assert metrics.OPC_CYCLES_WITHOUT_DATA._name == 'opc_cycles_without_data'
|
||||
assert set(metrics.OPC_CYCLES_WITHOUT_DATA._labelnames) == {'pod_id', 'server_name'}
|
||||
|
||||
|
||||
def test_opc_reconnections_total():
|
||||
"""Verify the definition of OPC_RECONNECTIONS_TOTAL."""
|
||||
assert metrics.OPC_RECONNECTIONS_TOTAL is not None
|
||||
assert isinstance(metrics.OPC_RECONNECTIONS_TOTAL, Counter)
|
||||
assert metrics.OPC_RECONNECTIONS_TOTAL._name == 'opc_reconnections_tried' # REMOVED _total
|
||||
assert set(metrics.OPC_RECONNECTIONS_TOTAL._labelnames) == {'pod_id', 'server_name'}
|
||||
|
||||
|
||||
def test_kafka_messages_sent():
|
||||
"""Verify the definition of KAFKA_MESSAGES_SENT."""
|
||||
assert metrics.KAFKA_MESSAGES_SENT is not None
|
||||
assert isinstance(metrics.KAFKA_MESSAGES_SENT, Counter)
|
||||
assert metrics.KAFKA_MESSAGES_SENT._name == 'kafka_messages_sent' # REMOVED _total
|
||||
assert set(metrics.KAFKA_MESSAGES_SENT._labelnames) == {'pod_id', 'topic'}
|
||||
|
||||
|
||||
def test_kafka_messages_errors():
|
||||
"""Verify the definition of KAFKA_MESSAGES_ERRORS."""
|
||||
assert metrics.KAFKA_MESSAGES_ERRORS is not None
|
||||
assert isinstance(metrics.KAFKA_MESSAGES_ERRORS, Counter)
|
||||
assert metrics.KAFKA_MESSAGES_ERRORS._name == 'kafka_messages_errors' # REMOVED _total
|
||||
assert set(metrics.KAFKA_MESSAGES_ERRORS._labelnames) == {'pod_id', 'topic'}
|
||||
|
||||
|
||||
def test_kafka_connection_status():
|
||||
"""Verify the definition of KAFKA_CONNECTION_STATUS."""
|
||||
assert metrics.KAFKA_CONNECTION_STATUS is not None
|
||||
assert isinstance(metrics.KAFKA_CONNECTION_STATUS, Gauge)
|
||||
assert metrics.KAFKA_CONNECTION_STATUS._name == 'kafka_connection_status'
|
||||
assert set(metrics.KAFKA_CONNECTION_STATUS._labelnames) == {'pod_id'}
|
||||
|
||||
|
||||
def test_notifications_sent():
|
||||
"""Verify the definition of NOTIFICATIONS_SENT."""
|
||||
assert metrics.NOTIFICATIONS_SENT is not None
|
||||
assert isinstance(metrics.NOTIFICATIONS_SENT, Counter)
|
||||
assert metrics.NOTIFICATIONS_SENT._name == 'notifications_sent' # REMOVED _total
|
||||
assert set(metrics.NOTIFICATIONS_SENT._labelnames) == {'pod_id', 'level', 'block'}
|
||||
Reference in New Issue
Block a user