Browse Source

config(last_seen updater): do proper sampling (#35257)

Oliver Newland 2 years ago
parent
commit
fa485c808c
1 changed files with 7 additions and 3 deletions
  1. 7 3
      src/sentry/sentry_metrics/last_seen_updater.py

+ 7 - 3
src/sentry/sentry_metrics/last_seen_updater.py

@@ -39,9 +39,13 @@ class LastSeenUpdaterMessageFilter(StreamMessageFilter[Message[KafkaPayload]]):
     def should_drop(self, message: Message[KafkaPayload]) -> bool:
         feature_enabled: float = options.get("sentry-metrics.last-seen-updater.accept-rate")
         bypass_for_user = random.random() > feature_enabled
-        self.__metrics.incr(
-            "last_seen_updater.accept_rate", sample_rate=0.001, tags={"bypass": bypass_for_user}
-        )
+        sample_rate = 0.001
+        if random.random() < sample_rate:
+            self.__metrics.incr(
+                "last_seen_updater.accept_rate",
+                tags={"bypass": bypass_for_user},
+                amount=1.0 / sample_rate,
+            )
 
         if bypass_for_user:
             return True