Skip to content
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
12 changes: 6 additions & 6 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ impl Api {
.request(Method::Post, url, None)?
.with_form_data(form)?
.with_retry(
self.config.get_max_retry_count(),
self.config.max_retries(),
&[
http::HTTP_STATUS_502_BAD_GATEWAY,
http::HTTP_STATUS_503_SERVICE_UNAVAILABLE,
Expand Down Expand Up @@ -968,7 +968,7 @@ impl<'a> AuthenticatedApi<'a> {
self.request(Method::Post, &url)?
.with_json_body(request)?
.with_retry(
self.api.config.get_max_retry_count(),
self.api.config.max_retries(),
&[
http::HTTP_STATUS_502_BAD_GATEWAY,
http::HTTP_STATUS_503_SERVICE_UNAVAILABLE,
Expand Down Expand Up @@ -1001,7 +1001,7 @@ impl<'a> AuthenticatedApi<'a> {
dist: None,
})?
.with_retry(
self.api.config.get_max_retry_count(),
self.api.config.max_retries(),
&[
http::HTTP_STATUS_502_BAD_GATEWAY,
http::HTTP_STATUS_503_SERVICE_UNAVAILABLE,
Expand Down Expand Up @@ -1032,7 +1032,7 @@ impl<'a> AuthenticatedApi<'a> {
dist,
})?
.with_retry(
self.api.config.get_max_retry_count(),
self.api.config.max_retries(),
&[
http::HTTP_STATUS_502_BAD_GATEWAY,
http::HTTP_STATUS_503_SERVICE_UNAVAILABLE,
Expand Down Expand Up @@ -1408,7 +1408,7 @@ impl RegionSpecificApi<'_> {
self.request(Method::Post, &path)?
.with_form_data(form)?
.with_retry(
self.api.api.config.get_max_retry_count(),
self.api.api.config.max_retries(),
&[http::HTTP_STATUS_507_INSUFFICIENT_STORAGE],
)
.progress_bar_mode(ProgressBarMode::Request)
Expand Down Expand Up @@ -1467,7 +1467,7 @@ impl RegionSpecificApi<'_> {
.request(Method::Post, &path)?
.with_form_data(form)?
.with_retry(
self.api.api.config.get_max_retry_count(),
self.api.api.config.max_retries(),
&[
http::HTTP_STATUS_502_BAD_GATEWAY,
http::HTTP_STATUS_503_SERVICE_UNAVAILABLE,
Expand Down
53 changes: 32 additions & 21 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub struct Config {
cached_log_level: log::LevelFilter,
cached_vcs_remote: String,
cached_token_data: Option<AuthTokenPayload>,
max_retries: u32,
}

impl Config {
Expand Down Expand Up @@ -91,6 +92,7 @@ impl Config {
cached_headers: get_default_headers(&ini),
cached_log_level: get_default_log_level(&ini),
cached_vcs_remote: get_default_vcs_remote(&ini),
max_retries: get_max_retries(&ini),
ini,
cached_token_data: token_embedded_data,
}
Expand Down Expand Up @@ -468,27 +470,8 @@ impl Config {
}

/// Returns the configured maximum number of retries for failed HTTP requests.
pub fn get_max_retry_count(&self) -> u32 {
match max_retries_from_env() {
Ok(Some(val)) => return val,
Ok(None) => (),
Err(e) => {
warn!(
"Ignoring invalid {MAX_RETRIES_ENV_VAR} environment variable: {}",
e
);
}
};

match max_retries_from_ini(&self.ini) {
Ok(Some(val)) => return val,
Ok(None) => (),
Err(e) => {
warn!("Ignoring invalid {MAX_RETRIES_INI_KEY} ini key: {}", e);
}
};

DEFAULT_RETRIES
pub fn max_retries(&self) -> u32 {
self.max_retries
}

/// Return the DSN
Expand Down Expand Up @@ -539,6 +522,32 @@ impl Config {
}
}

/// Obtains the maximum number of retries from the environment or the ini file.
/// Environment variable takes precedence over the ini file. If neither is set,
/// the default value is returned.
fn get_max_retries(ini: &Ini) -> u32 {
match max_retries_from_env() {
Ok(Some(val)) => return val,
Ok(None) => (),
Err(e) => {
warn!(
"Ignoring invalid {MAX_RETRIES_ENV_VAR} environment variable: {}",
e
);
}
};

match max_retries_from_ini(ini) {
Ok(Some(val)) => return val,
Ok(None) => (),
Err(e) => {
warn!("Ignoring invalid {MAX_RETRIES_INI_KEY} ini key: {}", e);
}
};

DEFAULT_RETRIES
}

/// Computes the maximum number of retries from the `SENTRY_HTTP_MAX_RETRIES` environment variable.
/// Returns `Ok(None)` if the environment variable is not set, other errors are returned as is.
fn max_retries_from_env() -> Result<Option<u32>> {
Expand Down Expand Up @@ -709,6 +718,7 @@ impl Clone for Config {
cached_log_level: self.cached_log_level,
cached_vcs_remote: self.cached_vcs_remote.clone(),
cached_token_data: self.cached_token_data.clone(),
max_retries: self.max_retries,
}
}
}
Expand Down Expand Up @@ -794,6 +804,7 @@ mod tests {
cached_log_level: LevelFilter::Off,
cached_vcs_remote: String::new(),
cached_token_data: None,
max_retries: 0,
};

assert_eq!(
Expand Down