diff --git a/authentik/events/apps.py b/authentik/events/apps.py index 3d939d568..17f795ea4 100644 --- a/authentik/events/apps.py +++ b/authentik/events/apps.py @@ -7,7 +7,7 @@ from authentik.lib.config import CONFIG, ENV_PREFIX GAUGE_TASKS = Gauge( "authentik_system_tasks", "System tasks and their status", - ["task_name", "task_uid", "status"], + ["tenant", "task_name", "task_uid", "status"], ) diff --git a/authentik/events/monitored_tasks.py b/authentik/events/monitored_tasks.py index f25b583a0..efb598be3 100644 --- a/authentik/events/monitored_tasks.py +++ b/authentik/events/monitored_tasks.py @@ -13,6 +13,7 @@ from tenant_schemas_celery.task import TenantTask from authentik.events.apps import GAUGE_TASKS from authentik.events.models import Event, EventAction from authentik.lib.utils.errors import exception_to_string +from authentik.tenants.utils import get_current_tenant LOGGER = get_logger() CACHE_KEY_PREFIX = "goauthentik.io/events/tasks/" @@ -101,6 +102,7 @@ class TaskInfo: except TypeError: duration = 0 GAUGE_TASKS.labels( + tenant=get_current_tenant().tenant_uuid, task_name=self.task_name.split(":")[0], task_uid=self.result.uid or "", status=self.result.status.name.lower(), diff --git a/authentik/flows/apps.py b/authentik/flows/apps.py index 45ebb8489..ae8b716b5 100644 --- a/authentik/flows/apps.py +++ b/authentik/flows/apps.py @@ -7,6 +7,7 @@ from authentik.lib.utils.reflection import all_subclasses GAUGE_FLOWS_CACHED = Gauge( "authentik_flows_cached", "Cached flows", + ["tenant"], ) HIST_FLOW_EXECUTION_STAGE_TIME = Histogram( "authentik_flows_execution_stage_time", diff --git a/authentik/flows/signals.py b/authentik/flows/signals.py index f28bab1e4..fa07a7c35 100644 --- a/authentik/flows/signals.py +++ b/authentik/flows/signals.py @@ -7,6 +7,7 @@ from structlog.stdlib import get_logger from authentik.flows.apps import GAUGE_FLOWS_CACHED from authentik.flows.planner import CACHE_PREFIX from authentik.root.monitoring import monitoring_set +from authentik.tenants.utils import get_current_tenant LOGGER = get_logger() @@ -21,7 +22,9 @@ def delete_cache_prefix(prefix: str) -> int: @receiver(monitoring_set) def monitoring_set_flows(sender, **kwargs): """set flow gauges""" - GAUGE_FLOWS_CACHED.set(len(cache.keys(f"{CACHE_PREFIX}*") or [])) + GAUGE_FLOWS_CACHED.labels(tenant=get_current_tenant().tenant_uuid).set( + len(cache.keys(f"{CACHE_PREFIX}*") or []) + ) @receiver(post_save) diff --git a/authentik/outposts/apps.py b/authentik/outposts/apps.py index 94a5bb788..3efce8294 100644 --- a/authentik/outposts/apps.py +++ b/authentik/outposts/apps.py @@ -8,12 +8,14 @@ from authentik.lib.config import CONFIG LOGGER = get_logger() GAUGE_OUTPOSTS_CONNECTED = Gauge( - "authentik_outposts_connected", "Currently connected outposts", ["outpost", "uid", "expected"] + "authentik_outposts_connected", + "Currently connected outposts", + ["tenant", "outpost", "uid", "expected"], ) GAUGE_OUTPOSTS_LAST_UPDATE = Gauge( "authentik_outposts_last_update", "Last update from any outpost", - ["outpost", "uid", "version"], + ["tenant", "outpost", "uid", "version"], ) MANAGED_OUTPOST = "goauthentik.io/outposts/embedded" diff --git a/authentik/outposts/consumer.py b/authentik/outposts/consumer.py index dda3feed0..95a822be2 100644 --- a/authentik/outposts/consumer.py +++ b/authentik/outposts/consumer.py @@ -14,6 +14,7 @@ from structlog.stdlib import BoundLogger, get_logger from authentik.core.channels import AuthJsonConsumer from authentik.outposts.apps import GAUGE_OUTPOSTS_CONNECTED, GAUGE_OUTPOSTS_LAST_UPDATE from authentik.outposts.models import OUTPOST_HELLO_INTERVAL, Outpost, OutpostState +from authentik.tenants.utils import get_current_tenant OUTPOST_GROUP = "group_outpost_%(outpost_pk)s" @@ -76,6 +77,7 @@ class OutpostConsumer(AuthJsonConsumer): OUTPOST_GROUP % {"outpost_pk": str(self.outpost.pk)}, self.channel_name ) GAUGE_OUTPOSTS_CONNECTED.labels( + tenant=get_current_tenant().tenant_uuid, outpost=self.outpost.name, uid=self.last_uid, expected=self.outpost.config.kubernetes_replicas, @@ -88,6 +90,7 @@ class OutpostConsumer(AuthJsonConsumer): ) if self.outpost and self.last_uid: GAUGE_OUTPOSTS_CONNECTED.labels( + tenant=get_current_tenant().tenant_uuid, outpost=self.outpost.name, uid=self.last_uid, expected=self.outpost.config.kubernetes_replicas, @@ -112,6 +115,7 @@ class OutpostConsumer(AuthJsonConsumer): elif msg.instruction == WebsocketMessageInstruction.ACK: return GAUGE_OUTPOSTS_LAST_UPDATE.labels( + tenant=get_current_tenant().tenant_uuid, outpost=self.outpost.name, uid=self.last_uid or "", version=state.version or "", diff --git a/authentik/policies/apps.py b/authentik/policies/apps.py index d66b77487..329b53c6e 100644 --- a/authentik/policies/apps.py +++ b/authentik/policies/apps.py @@ -6,6 +6,7 @@ from authentik.blueprints.apps import ManagedAppConfig GAUGE_POLICIES_CACHED = Gauge( "authentik_policies_cached", "Cached Policies", + ["tenant"], ) HIST_POLICIES_ENGINE_TOTAL_TIME = Histogram( "authentik_policies_engine_time_total_seconds", diff --git a/authentik/policies/signals.py b/authentik/policies/signals.py index d7949330f..69468cb84 100644 --- a/authentik/policies/signals.py +++ b/authentik/policies/signals.py @@ -10,6 +10,7 @@ from authentik.policies.apps import GAUGE_POLICIES_CACHED from authentik.policies.models import Policy, PolicyBinding, PolicyBindingModel from authentik.policies.types import CACHE_PREFIX from authentik.root.monitoring import monitoring_set +from authentik.tenants.utils import get_current_tenant LOGGER = get_logger() @@ -17,7 +18,9 @@ LOGGER = get_logger() @receiver(monitoring_set) def monitoring_set_policies(sender, **kwargs): """set policy gauges""" - GAUGE_POLICIES_CACHED.set(len(cache.keys(f"{CACHE_PREFIX}*") or [])) + GAUGE_POLICIES_CACHED.labels(tenant=get_current_tenant().tenant_uuid).set( + len(cache.keys(f"{CACHE_PREFIX}*") or []) + ) @receiver(post_save, sender=Policy)