metrics: remove type ignores that are no longer required

This commit is contained in:
Iain Learmonth 2022-11-02 13:58:54 +00:00
parent 0ff61721d9
commit 0ab9fdebc5
2 changed files with 14 additions and 13 deletions

View file

@ -3,13 +3,14 @@ from typing import Iterator, Optional
from flask import Flask
from prometheus_client.metrics_core import GaugeMetricFamily, CounterMetricFamily, Metric
from prometheus_client.registry import Collector
from sqlalchemy import text
from app.extensions import db
from app.models.automation import Automation, AutomationState
class FlaskCollector:
class FlaskCollector(Collector):
_app: Optional[Flask]
def __init__(self, app: Optional[Flask] = None) -> None:
@ -43,10 +44,10 @@ class DefinedProxiesCollector(FlaskCollector):
"""))
c = GaugeMetricFamily("defined_proxies", "Number of proxies currently defined for deployment",
labels=['group_id', 'group_name', 'provider', 'pool_id',
'pool_name']) # type: ignore[no-untyped-call]
'pool_name'])
for row in result:
c.add_metric([str(row[0]), row[1], row[2], str(row[3]), row[4]],
row[5]) # type: ignore[no-untyped-call]
row[5])
yield c
@ -66,25 +67,25 @@ class BlockedProxiesCollector(FlaskCollector):
c = CounterMetricFamily("deprecated_proxies",
"Number of proxies deprecated",
labels=['group_id', 'group_name', 'provider', 'pool_id', 'pool_name',
'deprecation_reason']) # type: ignore[no-untyped-call]
'deprecation_reason'])
for row in result:
c.add_metric([str(row[0]), row[1], row[2], str(row[3]), row[4], row[5]],
row[6]) # type: ignore[no-untyped-call]
row[6])
yield c
class AutomationCollector(FlaskCollector):
def collect_in_ctx(self, app: Flask) -> Iterator[Metric]:
c = GaugeMetricFamily("automation_state", "The automation state (0: idle, 1: running, 2: error)",
labels=['automation_name']) # type: ignore[no-untyped-call]
labels=['automation_name'])
automations = Automation.query.all()
for automation in automations:
if automation.short_name in app.config['HIDDEN_AUTOMATIONS']:
continue
if automation.state == AutomationState.IDLE:
c.add_metric([automation.short_name], 0) # type: ignore[no-untyped-call]
c.add_metric([automation.short_name], 0)
elif automation.state == AutomationState.RUNNING:
c.add_metric([automation.short_name], 1) # type: ignore[no-untyped-call]
c.add_metric([automation.short_name], 1)
else:
c.add_metric([automation.short_name], 2) # type: ignore[no-untyped-call]
c.add_metric([automation.short_name], 2)
yield c