Skip to content

Commit

Permalink
Merge pull request #839 from imeoer/stable/v2.1-cherry-pick
Browse files Browse the repository at this point in the history
[backport to stable/v2.1] storage: add mirror health checking support
  • Loading branch information
imeoer authored Nov 4, 2022
2 parents 29a9af4 + a514f66 commit 2fd7070
Show file tree
Hide file tree
Showing 4 changed files with 285 additions and 113 deletions.
31 changes: 31 additions & 0 deletions api/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,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 @@ -435,6 +436,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 @@ -951,6 +974,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, it will pull them 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",
// 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

0 comments on commit 2fd7070

Please sign in to comment.