From 9af7434774a4bda7260ed358aa9f6a21cb32fd80 Mon Sep 17 00:00:00 2001 From: Xavier Vello Date: Thu, 7 Mar 2024 13:59:15 +0100 Subject: [PATCH] export gauge --- posthog/api/capture.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/posthog/api/capture.py b/posthog/api/capture.py index eaaa0bea2bf97..6271ebd783fc3 100644 --- a/posthog/api/capture.py +++ b/posthog/api/capture.py @@ -12,7 +12,7 @@ from enum import Enum from kafka.errors import KafkaError, MessageSizeTooLargeError from kafka.producer.future import FutureRecordMetadata -from prometheus_client import Counter +from prometheus_client import Counter, Gauge from rest_framework import status from sentry_sdk import configure_scope from sentry_sdk.api import capture_exception, start_span @@ -88,6 +88,12 @@ labelnames=["reason"], ) +OVERFLOWING_KEYS_LOADED_GAUGE = Gauge( + "capture_overflowing_keys_loaded", + "Number of keys loaded for the overflow redirection, per resource_type.", + labelnames=[LABEL_RESOURCE_TYPE], +) + # This is a heuristic of ids we have seen used as anonymous. As they frequently # have significantly more traffic than non-anonymous distinct_ids, and likely # don't refer to the same underlying person we prefer to partition them randomly @@ -669,4 +675,5 @@ def _list_overflowing_keys(input_type: InputType) -> Set[str]: now = timezone.now() redis_client = get_client() results = redis_client.zrangebyscore(f"{OVERFLOWING_REDIS_KEY}{input_type.value}", min=now.timestamp(), max="+inf") + OVERFLOWING_KEYS_LOADED_GAUGE.labels(input_type.value).set(len(results)) return {x.decode("utf-8") for x in results}