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

storage: add mirror health checking support #800

Merged
merged 3 commits into from
Nov 4, 2022
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
31 changes: 31 additions & 0 deletions api/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ impl Default for ProxyConfig {

/// Configuration for mirror.
#[derive(Clone, Deserialize, Serialize, Debug)]
#[serde(default)]
pub struct MirrorConfig {
/// Mirror server URL, for example http://127.0.0.1:65001.
pub host: String,
Expand All @@ -412,6 +413,28 @@ pub struct MirrorConfig {
/// e.g. when using Dragonfly server as mirror, authorization through it will affect performance.
#[serde(default)]
pub auth_through: bool,
/// Interval of mirror health checking, in seconds.
#[serde(default = "default_check_interval")]
pub health_check_interval: u64,
/// Failure count for which mirror is considered unavailable.
#[serde(default = "default_failure_limit")]
pub failure_limit: u8,
/// Ping URL to check mirror server health.
#[serde(default)]
pub ping_url: String,
}

impl Default for MirrorConfig {
fn default() -> Self {
Self {
host: String::new(),
headers: HashMap::new(),
auth_through: false,
health_check_interval: 5,
failure_limit: 5,
ping_url: String::new(),
}
}
}

#[derive(Debug)]
Expand Down Expand Up @@ -623,6 +646,14 @@ fn default_http_timeout() -> u32 {
5
}

fn default_check_interval() -> u64 {
5
}

fn default_failure_limit() -> u8 {
5
}

fn default_work_dir() -> String {
".".to_string()
}
Expand Down
12 changes: 10 additions & 2 deletions docs/nydusd.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,21 @@ Currently, the mirror mode is only tested in the registry backend, and in theory
// When Dragonfly does not cache data, nydusd will pull it from "X-Dragonfly-Registry".
// If not set "X-Dragonfly-Registry", Dragonfly will pull data from proxy.registryMirror.url.
"X-Dragonfly-Registry": "https://index.docker.io"
}
},
// This URL endpoint is used to check the health of mirror server, and if the mirror is unhealthy,
// the request will fallback to the next mirror or the original registry server.
// Use $host/v2 as default if left empty.
"ping_url": "http://127.0.0.1:40901/server/ping",
sctb512 marked this conversation as resolved.
Show resolved Hide resolved
// Interval time (s) to check and recover unavailable mirror. Use 5 as default if left empty.
"health_check_interval": 5,
// Failure counts before disabling this mirror. Use 5 as default if left empty.
"failure_limit": 5,
},
{
"host": "http://dragonfly2.io:65001",
"headers": {
"X-Dragonfly-Registry": "https://index.docker.io"
}
},
}
],
...
Expand Down
Loading