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
68 changes: 59 additions & 9 deletions .github/actions/setup-self-hosted/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ runs:
add_pkg() {
local pkg="$1"
local existing
if [[ "$(dpkg-query -W -f='${Status}' "${pkg}" 2>/dev/null || true)" == "install ok installed" ]]; then
return
fi
if ((${#packages[@]} > 0)); then
for existing in "${packages[@]}"; do
if [[ "${existing}" == "${pkg}" ]]; then
Expand Down Expand Up @@ -109,9 +112,56 @@ runs:
add_pkg unzip
fi

apt_tmp=""
trap '[[ -z "${apt_tmp}" ]] || sudo rm -rf "${apt_tmp}"' EXIT
prepare_apt() {
if [[ -n "${apt_tmp}" ]]; then return; fi
apt_tmp="$(mktemp -d)"
chmod 755 "${apt_tmp}"
mkdir -p "${apt_tmp}/lists/partial"
. /etc/os-release
case "${ID}" in
ubuntu)
case "$(dpkg --print-architecture)" in
amd64)
apt_archive="http://archive.ubuntu.com/ubuntu"
apt_security="http://security.ubuntu.com/ubuntu"
;;
arm64)
apt_archive="http://ports.ubuntu.com/ubuntu-ports"
apt_security="${apt_archive}"
;;
*) echo "Unsupported Ubuntu architecture" >&2; exit 1 ;;
esac
apt_keyring="/usr/share/keyrings/ubuntu-archive-keyring.gpg"
apt_components="main universe"
;;
debian)
apt_archive="http://deb.debian.org/debian"
apt_security="http://security.debian.org/debian-security"
apt_keyring="/usr/share/keyrings/debian-archive-keyring.gpg"
apt_components="main"
;;
*) echo "Unsupported APT distribution: ${ID}" >&2; exit 1 ;;
esac
: "${VERSION_CODENAME:?Distribution codename is required}"
[[ -f "${apt_keyring}" ]] || { echo "Distribution signing keyring is missing" >&2; exit 1; }
{
echo "deb [signed-by=${apt_keyring}] ${apt_archive} ${VERSION_CODENAME} ${apt_components}"
echo "deb [signed-by=${apt_keyring}] ${apt_archive} ${VERSION_CODENAME}-updates ${apt_components}"
echo "deb [signed-by=${apt_keyring}] ${apt_security} ${VERSION_CODENAME}-security ${apt_components}"
} > "${apt_tmp}/sources.list"
# The runner's unrelated PPAs must not gate basic build tools or
# contribute higher-priority packages to this installation.
apt_options=(-o "Dir::Etc::sourcelist=${apt_tmp}/sources.list"
-o Dir::Etc::sourceparts=- -o "Dir::State::lists=${apt_tmp}/lists"
-o APT::Update::Error-Mode=any -o Acquire::Retries=3)
}

if ((${#packages[@]} > 0)); then
sudo DEBIAN_FRONTEND=noninteractive apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y "${packages[@]}"
prepare_apt
sudo DEBIAN_FRONTEND=noninteractive apt-get "${apt_options[@]}" update
sudo DEBIAN_FRONTEND=noninteractive apt-get "${apt_options[@]}" install --no-upgrade -y "${packages[@]}"
fi

if has awscli && ! command -v aws >/dev/null 2>&1; then
Expand All @@ -133,12 +183,12 @@ runs:
if has github-cli && ! command -v gh >/dev/null 2>&1; then
# Ubuntu's own gh package is not always present on the minimal
# runner image. Use the upstream GitHub CLI apt repository.
sudo mkdir -p -m 755 /etc/apt/keyrings
prepare_apt
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \
| sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg >/dev/null
sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
| sudo tee /etc/apt/sources.list.d/github-cli.list >/dev/null
sudo DEBIAN_FRONTEND=noninteractive apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y gh
> "${apt_tmp}/githubcli-archive-keyring.gpg"
chmod go+r "${apt_tmp}/githubcli-archive-keyring.gpg"
echo "deb [arch=$(dpkg --print-architecture) signed-by=${apt_tmp}/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
>> "${apt_tmp}/sources.list"
sudo DEBIAN_FRONTEND=noninteractive apt-get "${apt_options[@]}" update
sudo DEBIAN_FRONTEND=noninteractive apt-get "${apt_options[@]}" install --no-upgrade -y gh
fi
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:

- name: Validate RustFS compatibility contract
run: |
python3 -m unittest scripts/tests/test_rustfs_compatibility.py
python3 -m unittest scripts/tests/test_rustfs_compatibility.py scripts/tests/test_setup_self_hosted.py
python3 scripts/rustfs_compatibility.py --check-repository

smoke-compatibility:
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jiff = { version = "0.2", features = ["serde"] }
humansize = "2.1"
fundu = { version = "2.1.1", default-features = false, features = ["custom"] }
bytes = "1.11"
url = "2.5"
url = "2.5.9"
futures = "0.3"
async-trait = "0.1"
mime_guess = "2.0"
Expand Down
89 changes: 88 additions & 1 deletion crates/cli/src/commands/du.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ struct UsageSuccessOutput {

#[derive(Debug, Serialize, PartialEq, Eq)]
struct UsageData {
#[serde(skip_serializing_if = "std::collections::BTreeMap::is_empty")]
bucket_snapshot_at: std::collections::BTreeMap<String, Timestamp>,
#[serde(skip_serializing_if = "std::collections::BTreeMap::is_empty")]
initial_statistics: std::collections::BTreeMap<String, Timestamp>,
#[serde(skip_serializing_if = "Vec::is_empty")]
unmeasured_buckets: Vec<String>,
scope: &'static str,
path: Option<String>,
source: &'static str,
Expand Down Expand Up @@ -276,7 +282,13 @@ fn emit_report(

if report.partial {
if !formatter.is_json() {
formatter.warning("Usage scan is partial; one or more buckets could not be read.");
formatter.warning(if !report.initial_statistics.is_empty() {
"Initial statistics are incomplete."
} else if !report.unmeasured_buckets.is_empty() {
"Server statistics are unavailable for one or more buckets."
} else {
"Usage scan is partial; one or more buckets could not be read."
});
}
ExitCode::NetworkError
} else {
Expand Down Expand Up @@ -310,6 +322,11 @@ fn scope_snapshot(
report.scope = request.scope();
report.path = request.path(alias);
let Some(bucket_name) = request.bucket.as_deref() else {
if report.buckets.is_empty() && !report.unmeasured_buckets.is_empty() {
return Err(Error::UnsupportedFeature(
"Server usage statistics are pending or unavailable".into(),
));
}
return Ok(report);
};

Expand All @@ -319,11 +336,30 @@ fn scope_snapshot(
.find(|bucket| bucket.name == bucket_name)
.cloned()
.ok_or_else(|| {
if report.unmeasured_buckets.iter().any(|bucket| bucket == bucket_name) {
return Error::UnsupportedFeature(format!("Usage statistics for existing bucket '{alias}/{bucket_name}' are pending or unavailable"));
}
Error::NotFound(format!(
"Bucket '{alias}/{bucket_name}' is absent from the server usage snapshot"
))
})?;
report.buckets = vec![bucket];
report
.bucket_snapshot_at
.retain(|bucket, _| bucket == bucket_name);
if let Some(timestamp) = report.bucket_snapshot_at.get(bucket_name) {
report.snapshot_at = Some(*timestamp);
}
report
.initial_statistics
.retain(|bucket, _| bucket == bucket_name);
report.unmeasured_buckets.clear();
report.partial = !report.initial_statistics.is_empty();
if let Some(timestamp) = report.initial_statistics.get(bucket_name) {
report.snapshot_at = Some(*timestamp);
report.version_count = None;
report.delete_marker_count = None;
}
report.finish();
Ok(report)
}
Expand All @@ -341,6 +377,9 @@ fn success_output(
output_type: USAGE_FAMILY,
status: "success",
data: UsageData {
bucket_snapshot_at: report.bucket_snapshot_at.clone(),
initial_statistics: report.initial_statistics.clone(),
unmeasured_buckets: report.unmeasured_buckets.clone(),
scope: report.scope.as_str(),
path: report.path.clone(),
source: report.source.as_str(),
Expand Down Expand Up @@ -387,6 +426,9 @@ fn age_seconds(now: Timestamp, snapshot: Timestamp) -> u64 {
fn print_human(report: &UsageReport, now: Timestamp, formatter: &Formatter) {
formatter.println(&format!("Source: {}", report.source.as_str()));
formatter.println(&format!("Scope: {}", report.scope.as_str()));
if !report.initial_statistics.is_empty() {
formatter.println("State: initial statistics (partial)");
}
if let Some(path) = &report.path {
formatter.println(&format!("Path: {}", formatter.sanitize_text(path)));
}
Expand Down Expand Up @@ -572,6 +614,9 @@ mod tests {

fn snapshot(timestamp: i64) -> UsageReport {
UsageReport {
bucket_snapshot_at: Default::default(),
initial_statistics: Default::default(),
unmeasured_buckets: Vec::new(),
source: UsageSource::ServerSnapshot,
scope: UsageScope::Cluster,
path: None,
Expand All @@ -596,6 +641,48 @@ mod tests {
}
}

#[test]
fn scoping_a_snapshot_keeps_full_measurements_separate_from_initial_rows() {
let mut report = snapshot(100);
let first = report.buckets[0].name.clone();
report.initial_statistics.insert(
"initial".into(),
Timestamp::from_second(200).expect("checkpoint time"),
);
report.push_bucket(UsageBucket {
name: "initial".into(),
total_bytes: 71,
object_count: 7,
version_count: None,
delete_marker_count: None,
incomplete_upload_count: None,
incomplete_upload_bytes: None,
});
let request = |bucket| UsageScanRequest {
bucket: Some(bucket),
prefix: None,
include_versions: false,
include_incomplete_uploads: false,
};
let complete =
scope_snapshot(report.clone(), "alias", &request(first)).expect("full bucket");
assert!(!complete.partial);
assert!(complete.initial_statistics.is_empty());
assert_eq!(
complete.snapshot_at,
Some(Timestamp::from_second(100).expect("full time"))
);
let initial =
scope_snapshot(report, "alias", &request("initial".into())).expect("initial bucket");
assert!(initial.partial);
assert_eq!(
initial.snapshot_at,
Some(Timestamp::from_second(200).expect("initial time"))
);
assert_eq!(initial.version_count, None);
assert_eq!(initial.object_count, 7);
}

#[tokio::test]
async fn du_uses_advertised_server_snapshot_without_scanning() {
let target = parse_target("local").expect("valid target");
Expand Down
10 changes: 9 additions & 1 deletion crates/cli/tests/admin_recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,15 @@ impl DiscardFaultServer {
let stream = acceptor.accept(stream).await.unwrap();
assert_eq!(stream.get_ref().1.alpn_protocol(), Some(b"h2".as_slice()));
let mut connection = h2::server::handshake(stream).await.unwrap();
let mut fault_injected = false;
while let Some(request) = connection.accept().await {
let (request, mut response) = request.unwrap();
let (request, mut response) = match request {
Ok(request) => request,
Err(error) if fault_injected && error.get_io().is_some_and(|error| matches!(
error.kind(), std::io::ErrorKind::BrokenPipe | std::io::ErrorKind::ConnectionReset
)) => return,
Err(error) => panic!("fault server request failed before an expected client disconnect: {error}"),
};
assert_eq!(request.method(), "POST");
assert_eq!(request.uri().path(), "/rustfs/admin/v4/heal/delete-residue/discard");
assert!(request.headers()["authorization"].to_str().unwrap().starts_with("AWS4-HMAC-SHA256 "));
Expand All @@ -748,6 +755,7 @@ impl DiscardFaultServer {
extra = connection.accept() => panic!("unexpected stream before fault injection: {extra:?}"),
};
requests.lock().unwrap().push(serde_json::from_slice(&bytes).unwrap());
fault_injected = true;
match fault {
DiscardFault::RefusedStream => response.send_reset(h2::Reason::REFUSED_STREAM),
DiscardFault::LostResponse => return,
Expand Down
13 changes: 13 additions & 0 deletions crates/core/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ pub struct UsageFailure {
/// Complete or partial usage result.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct UsageReport {
/// Original complete measurement times, independent of owner fencing.
#[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")]
pub bucket_snapshot_at: std::collections::BTreeMap<String, Timestamp>,
/// Initial measurements, keyed by bucket and original checkpoint time.
/// These rows are partial and never replace complete server measurements.
#[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")]
pub initial_statistics: std::collections::BTreeMap<String, Timestamp>,
/// Existing buckets for which no usable server measurement is available.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub unmeasured_buckets: Vec<String>,
/// Data source used for the report.
pub source: UsageSource,
/// Scope represented by the report.
Expand Down Expand Up @@ -172,6 +182,9 @@ impl UsageReport {
/// Create an empty report that can be populated with bucket rows.
pub fn empty(source: UsageSource, scope: UsageScope, path: Option<String>) -> Self {
Self {
initial_statistics: Default::default(),
bucket_snapshot_at: Default::default(),
unmeasured_buckets: Vec::new(),
source,
scope,
path,
Expand Down
Loading