Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instr(projects): Log fetch failure #4142

Merged
merged 6 commits into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions relay-server/src/services/projects/cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::{BTreeMap, BTreeSet};
use std::convert::Infallible;
use std::error::Error;
use std::sync::Arc;
use std::time::Duration;
Expand Down Expand Up @@ -493,12 +494,11 @@ impl ProjectSource {
project_key: ProjectKey,
no_cache: bool,
cached_state: ProjectFetchState,
) -> Result<ProjectFetchState, ()> {
) -> Result<ProjectFetchState, ProjectSourceError> {
let state_opt = self
.local_source
.send(FetchOptionalProjectState { project_key })
.await
.map_err(|_| ())?;
.await?;

if let Some(state) = state_opt {
return Ok(ProjectFetchState::new(state));
Expand All @@ -516,12 +516,11 @@ impl ProjectSource {
if let Some(redis_source) = self.redis_source {
let current_revision = current_revision.clone();

let redis_permit = self.redis_semaphore.acquire().await.map_err(|_| ())?;
let redis_permit = self.redis_semaphore.acquire().await?;
let state_fetch_result = tokio::task::spawn_blocking(move || {
redis_source.get_config_if_changed(project_key, current_revision.as_deref())
})
.await
.map_err(|_| ())?;
.await?;
drop(redis_permit);

match state_fetch_result {
Expand Down Expand Up @@ -553,8 +552,7 @@ impl ProjectSource {
current_revision,
no_cache,
})
.await
.map_err(|_| ())?;
.await?;

match state {
UpstreamProjectState::New(state) => Ok(ProjectFetchState::new(state.sanitized())),
Expand All @@ -563,6 +561,22 @@ impl ProjectSource {
}
}

#[derive(Debug, thiserror::Error)]
enum ProjectSourceError {
#[error("redis permit error {0}")]
RedisPermit(#[from] tokio::sync::AcquireError),
#[error("redis join error {0}")]
RedisJoin(#[from] tokio::task::JoinError),
#[error("upstream error {0}")]
Upstream(#[from] relay_system::SendError),
}

impl From<Infallible> for ProjectSourceError {
fn from(value: Infallible) -> Self {
match value {}
}
}

/// Updates the cache with new project state information.
struct UpdateProjectState {
/// The public key to fetch the project by.
Expand Down Expand Up @@ -777,7 +791,16 @@ impl ProjectCacheBroker {
let state = source
.fetch(project_key, no_cache, cached_state)
.await
.unwrap_or_else(|()| ProjectFetchState::disabled());
.unwrap_or_else(|e| {
relay_log::error!(
error = &e as &dyn Error,
tags.project_key = %project_key,
"Failed to fetch project from source"
);
// TODO: change this to ProjectFetchState::pending() once we consider it safe to do so.
// see https://github.com/getsentry/relay/pull/4140.
ProjectFetchState::disabled()
});

let message = UpdateProjectState {
project_key,
Expand Down
Loading