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

fix(projects): Treat fetch failures as pending #4140

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jjbayer
Copy link
Member

@jjbayer jjbayer commented Oct 15, 2024

When we fail to fetch a project state for any reason (max retries exceeded, redis error), we should not mark the project as invalid.

Currently we treat the project as if the DSN was invalid, and respond to clients with a 403 response. This might have made sense as a defensive measure in a pre-spooling world where envelopes could not be buffered for a longer period of time, but with spooling and time-based envelope eviction, we can now safely buffer them.

ref: INC-888

blocked by: https://github.com/getsentry/team-ingest/issues/345

@jjbayer jjbayer self-assigned this Oct 15, 2024
time.sleep(1) # Wait for project to be cached

# Relay still accepts events for this project
next_response = relay.send_event(42)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the old version, this call raises a 403 error.

@jjbayer jjbayer marked this pull request as ready for review October 15, 2024 08:39
@jjbayer jjbayer requested a review from a team as a code owner October 15, 2024 08:39
Copy link
Member

@Dav1dde Dav1dde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does have the downside of potentially exhausting buffers if a project consistently cannot be computed. Do we need more alerts for this case?

@@ -777,7 +791,13 @@ impl ProjectCacheBroker {
let state = source
.fetch(project_key, no_cache, cached_state)
.await
.unwrap_or_else(|()| ProjectFetchState::disabled());
.unwrap_or_else(|e| {
Copy link
Member

@Dav1dde Dav1dde Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly a bit nicer to read with:

    .inspect_err(|e| relay_log::error!(..))
    .unwrap_or(ProjectFetchState::pending())

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how unwrap_or_else only creates a ProjectFetchState in the error case. ProjectFetchState::pending() calls Instant::now(), so it's not entirely free.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That part could be fixed by using unwrap_or_else, but I think the current version is fine as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went overboard with my example, I mainly meant the split of logging into the inspect_err, keep the side effect separate from the conversion. But either way it's fine and possibly worse with the how rustfmt wants to format it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That part could be fixed by using unwrap_or_else

Yes, but then you need to ignore the argument passed to unwrap_or_else(the error), that you previously inspected with inspect_err. Is that better?

                .inspect_err(|e| {
                    relay_log::error!(
                        error = e as &dyn Error,
                        "Failed to fetch project from source"
                    );
                })
                .unwrap_or_else(|_| ProjectFetchState::pending());
                
                // vs
                
                .unwrap_or_else(|e| {
                    relay_log::error!(
                        error = &e as &dyn Error,
                        "Failed to fetch project from source"
                    );
                    ProjectFetchState::pending()
                });

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think the current version is superior.

@jjbayer
Copy link
Member Author

jjbayer commented Oct 15, 2024

This does have the downside of potentially exhausting buffers if a project consistently cannot be computed. Do we need more alerts for this case?

Good point, we should alert when the buffer gets close to its total capacity, or implement @iambriccardo 's automatic eviction policy. I added a task to the epic.

@@ -777,7 +791,13 @@ impl ProjectCacheBroker {
let state = source
.fetch(project_key, no_cache, cached_state)
.await
.unwrap_or_else(|()| ProjectFetchState::disabled());
.unwrap_or_else(|e| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That part could be fixed by using unwrap_or_else, but I think the current version is fine as well.

@jjbayer
Copy link
Member Author

jjbayer commented Oct 15, 2024

Note: not merging this until https://github.com/getsentry/team-ingest/issues/345 is mature.

jjbayer added a commit that referenced this pull request Oct 15, 2024
Measure impact before we merge
#4140.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants