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

feat(globalconfig): Only report upstream errors after elapsed interval #2628

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Update Docker Debian image from 10 to 12. ([#2622](https://github.com/getsentry/relay/pull/2622))

**Internal**:

- Report global config fetch errors after interval of constant failures elapsed. ([#2628](https://github.com/getsentry/relay/pull/2628))

## 23.10.0

**Features**:
Expand Down
21 changes: 17 additions & 4 deletions relay-server/src/actors/global_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use std::borrow::Cow;
use std::sync::Arc;
use std::time::Duration;

use relay_config::Config;
use relay_config::RelayMode;
Expand All @@ -20,6 +21,7 @@ use relay_system::{Addr, AsyncResponse, Controller, FromMessage, Interface, Serv
use reqwest::Method;
use serde::{Deserialize, Serialize};
use tokio::sync::{mpsc, watch};
use tokio::time::Instant;

use crate::actors::upstream::{
RequestPriority, SendQuery, UpstreamQuery, UpstreamRelay, UpstreamRequestError,
Expand Down Expand Up @@ -147,6 +149,10 @@ pub struct GlobalConfigService {
upstream: Addr<UpstreamRelay>,
/// Handle to avoid multiple outgoing requests.
fetch_handle: SleepHandle,
/// Last instant the global config was successfully fetched in.
last_fetched: Instant,
/// Interval of upstream fetching failures before reporting such errors.
upstream_failure_interval: Duration,
/// Disables the upstream fetch loop.
shutdown: bool,
}
Expand All @@ -164,6 +170,8 @@ impl GlobalConfigService {
internal_rx,
upstream,
fetch_handle: SleepHandle::idle(),
last_fetched: Instant::now(),
upstream_failure_interval: Duration::from_secs(35),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

35 is arbitrary, but should have time for 3 requests (after 10s each).

Copy link
Member

Choose a reason for hiding this comment

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

Should this be in Config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We may not need it for now, but I'll keep this in mind to address it in the future.

shutdown: false,
}
}
Expand Down Expand Up @@ -227,6 +235,7 @@ impl GlobalConfigService {
// subscribers.
self.global_config_watch.send(Arc::new(global_config)).ok();
success = true;
self.last_fetched = Instant::now();
}
None => relay_log::error!("global config missing in upstream response"),
}
Expand All @@ -235,10 +244,14 @@ impl GlobalConfigService {
success = if success { "true" } else { "false" },
);
}
Ok(Err(e)) => relay_log::error!(
error = &e as &dyn std::error::Error,
"failed to fetch global config from upstream"
),
Ok(Err(e)) => {
if self.last_fetched.elapsed() >= self.upstream_failure_interval {
relay_log::error!(
error = &e as &dyn std::error::Error,
"failed to fetch global config from upstream"
);
}
}
Err(e) => relay_log::error!(
error = &e as &dyn std::error::Error,
"failed to send request to upstream"
Expand Down
Loading