Skip to content

Commit

Permalink
export gauge
Browse files Browse the repository at this point in the history
  • Loading branch information
xvello committed Mar 18, 2024
1 parent 3e18d1a commit 9af7434
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion posthog/api/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}

0 comments on commit 9af7434

Please sign in to comment.