Skip to content

Commit

Permalink
fix: fix redis key for session replay overflow (#24916)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankh authored Sep 12, 2024
1 parent 3e7f785 commit e6a76ee
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions rust/capture/src/limiters/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ pub const OVERFLOW_LIMITER_CACHE_KEY: &str = "@posthog/capture-overflow/";
#[derive(Debug)]
pub enum QuotaResource {
Events,
// due to historical reasons we use different suffixes for quota limits and overflow
// hopefully we can unify these in the future
Recordings,
Replay,
}

impl QuotaResource {
pub fn as_str(&self) -> &'static str {
match self {
Self::Events => "events",
Self::Recordings => "recordings",
Self::Replay => "replay",
}
}
}
Expand Down Expand Up @@ -153,7 +157,7 @@ mod tests {
#[tokio::test]
async fn test_dynamic_limited() {
let client = MockRedisClient::new().zrangebyscore_ret(
"@posthog/capture-overflow/recordings",
"@posthog/capture-overflow/replay",
vec![String::from("banana")],
);
let client = Arc::new(client);
Expand All @@ -163,7 +167,7 @@ mod tests {
client,
OVERFLOW_LIMITER_CACHE_KEY.to_string(),
None,
QuotaResource::Recordings,
QuotaResource::Replay,
)
.expect("Failed to create billing limiter");
tokio::time::sleep(std::time::Duration::from_millis(30)).await;
Expand Down
2 changes: 1 addition & 1 deletion rust/capture/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ where
redis_client.clone(),
OVERFLOW_LIMITER_CACHE_KEY.to_string(),
config.redis_key_prefix.clone(),
QuotaResource::Recordings,
QuotaResource::Replay,
)
.expect("failed to start replay overflow limiter"),
),
Expand Down
4 changes: 2 additions & 2 deletions rust/capture/tests/recordings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ async fn it_applies_overflow_limits() -> Result<()> {
// - session2 limit is active -> send to overflow
// - session3 is not in redis -> accept by default
let redis = PrefixedRedis::new().await;
redis.add_overflow_limit(QuotaResource::Recordings, &session1, Duration::seconds(-60));
redis.add_overflow_limit(QuotaResource::Recordings, &session2, Duration::seconds(60));
redis.add_overflow_limit(QuotaResource::Replay, &session1, Duration::seconds(-60));
redis.add_overflow_limit(QuotaResource::Replay, &session2, Duration::seconds(60));

let mut config = DEFAULT_CONFIG.clone();
config.redis_key_prefix = redis.key_prefix();
Expand Down

0 comments on commit e6a76ee

Please sign in to comment.