Skip to content

Commit

Permalink
check revision after loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Dav1dde committed Aug 6, 2024
1 parent a585e72 commit 9d81609
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
42 changes: 25 additions & 17 deletions relay-server/src/services/project_redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,33 @@ impl RedisProjectSource {
.query(&mut connection)
.map_err(RedisError::Redis)?;

let response = match raw_response_opt {
Some(response) => {
metric!(
counter(RelayCounters::ProjectStateRedis) += 1,
hit = "project_config"
);
let parsed = parse_redis_response(response.as_slice())?;
ProjectState::from(parsed)
}
None => {
metric!(
counter(RelayCounters::ProjectStateRedis) += 1,
hit = "false"
);
ProjectState::Pending
}
let Some(response) = raw_response_opt else {
metric!(
counter(RelayCounters::ProjectStateRedis) += 1,
hit = "false"
);
return Ok(Some(ProjectState::Pending));
};

Ok(Some(response))
let response = ProjectState::from(parse_redis_response(response.as_slice())?);

// If we were passed a revision, check if we just loaded the same revision from Redis.
//
// We always want to keep the old revision alive if possible, since the already loaded
// version has a few caches already initialized.
if revision.is_some() && response.revision() == revision {
metric!(
counter(RelayCounters::ProjectStateRedis) += 1,
hit = "project_config_revision"
);
Ok(None)
} else {
metric!(
counter(RelayCounters::ProjectStateRedis) += 1,
hit = "project_config"
);
Ok(Some(response))
}
}

fn get_redis_project_config_key(&self, key: ProjectKey) -> String {
Expand Down
2 changes: 2 additions & 0 deletions relay-server/src/statsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,8 @@ pub enum RelayCounters {
/// - `hit`: One of:
/// - `revision`: the cached version was validated to be up to date using its revision.
/// - `project_config`: the request was handled by the cache.
/// - `project_config_revision`: the request was handled by the cache and the revision did
/// not change.
/// - `false`: the request will be sent to the sentry endpoint.
#[cfg(feature = "processing")]
ProjectStateRedis,
Expand Down

0 comments on commit 9d81609

Please sign in to comment.