events: fix missing labels on prometheus metrics (#8309)

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L
2024-01-25 14:37:49 +01:00
committed by GitHub
parent 45a3310320
commit b43341cfef
2 changed files with 8 additions and 3 deletions

View File

@ -14,11 +14,12 @@ GAUGE_TASKS = Gauge(
SYSTEM_TASK_TIME = Histogram( SYSTEM_TASK_TIME = Histogram(
"authentik_system_tasks_time_seconds", "authentik_system_tasks_time_seconds",
"Runtime of system tasks", "Runtime of system tasks",
["tenant"],
) )
SYSTEM_TASK_STATUS = Gauge( SYSTEM_TASK_STATUS = Gauge(
"authentik_system_tasks_status", "authentik_system_tasks_status",
"System task status", "System task status",
["task_name", "task_uid", "status"], ["tenant", "task_name", "task_uid", "status"],
) )

View File

@ -10,7 +10,7 @@ from typing import Optional
from uuid import uuid4 from uuid import uuid4
from django.apps import apps from django.apps import apps
from django.db import models from django.db import connection, models
from django.db.models import Count, ExpressionWrapper, F from django.db.models import Count, ExpressionWrapper, F
from django.db.models.fields import DurationField from django.db.models.fields import DurationField
from django.db.models.functions import Extract from django.db.models.functions import Extract
@ -642,12 +642,16 @@ class SystemTask(SerializerModel, ExpiringModel):
duration = max(self.finish_timestamp - self.start_timestamp, 0) duration = max(self.finish_timestamp - self.start_timestamp, 0)
# TODO: Deprecated metric - remove in 2024.2 or later # TODO: Deprecated metric - remove in 2024.2 or later
GAUGE_TASKS.labels( GAUGE_TASKS.labels(
tenant=connection.schema_name,
task_name=self.name, task_name=self.name,
task_uid=self.uid or "", task_uid=self.uid or "",
status=self.status.lower(), status=self.status.lower(),
).set(duration) ).set(duration)
SYSTEM_TASK_TIME.observe(duration) SYSTEM_TASK_TIME.labels(
tenant=connection.schema_name,
).observe(duration)
SYSTEM_TASK_STATUS.labels( SYSTEM_TASK_STATUS.labels(
tenant=connection.schema_name,
task_name=self.name, task_name=self.name,
task_uid=self.uid or "", task_uid=self.uid or "",
status=self.status.lower(), status=self.status.lower(),