feat(server): add tracing spans and caching to archive and blame services
- Add tracing spans with repo labels for archive and blame operations - Implement caching for archive list entries when using OID selectors - Implement caching for blame operations when using OID selectors - Add detailed
This commit is contained in:
+49
-12
@@ -10,19 +10,32 @@ pub(crate) fn maintenance_response(out: std::process::Output) -> RepositoryMaint
|
||||
}
|
||||
}
|
||||
|
||||
fn dir_size(path: &std::path::Path) -> u64 {
|
||||
let mut total = 0u64;
|
||||
if let Ok(entries) = std::fs::read_dir(path) {
|
||||
for entry in entries.flatten() {
|
||||
let p = entry.path();
|
||||
if p.is_file() {
|
||||
total += entry.metadata().map(|m| m.len()).unwrap_or(0);
|
||||
} else if p.is_dir() {
|
||||
total += dir_size(&p);
|
||||
}
|
||||
/// Get approximate repository size using git count-objects instead of
|
||||
/// recursively scanning the filesystem (which is O(n) and very slow for large repos).
|
||||
fn dir_size(gb: &crate::bare::GitBare) -> u64 {
|
||||
let out = git_cmd(gb, &["count-objects", "-v"]).ok();
|
||||
let text = out
|
||||
.as_ref()
|
||||
.map(|o| String::from_utf8_lossy(&o.stdout).into_owned())
|
||||
.unwrap_or_default();
|
||||
|
||||
let mut loose_size_kb = 0u64;
|
||||
let mut pack_size_kb = 0u64;
|
||||
let mut garbage_size_kb = 0u64;
|
||||
|
||||
for line in text.lines() {
|
||||
let line = line.trim();
|
||||
if let Some(val) = line.strip_prefix("size: ") {
|
||||
loose_size_kb = val.trim().parse().unwrap_or(0);
|
||||
} else if let Some(val) = line.strip_prefix("size-pack: ") {
|
||||
pack_size_kb = val.trim().parse().unwrap_or(0);
|
||||
} else if let Some(val) = line.strip_prefix("size-garbage: ") {
|
||||
garbage_size_kb = val.trim().parse().unwrap_or(0);
|
||||
}
|
||||
}
|
||||
total
|
||||
|
||||
// count-objects reports sizes in KiB; convert to bytes
|
||||
(loose_size_kb + pack_size_kb + garbage_size_kb) * 1024
|
||||
}
|
||||
|
||||
fn count_refs(gb: &crate::bare::GitBare) -> u64 {
|
||||
@@ -44,7 +57,7 @@ fn file_len(path: &std::path::Path) -> u64 {
|
||||
}
|
||||
|
||||
pub(crate) fn get_statistics(gb: &crate::bare::GitBare) -> RepositoryStatistics {
|
||||
let size_bytes = dir_size(&gb.bare_dir);
|
||||
let size_bytes = dir_size(gb);
|
||||
|
||||
let mut loose_object_count: u64 = 0;
|
||||
let mut packed_object_count: u64 = 0;
|
||||
@@ -81,6 +94,11 @@ pub(crate) fn check_health(
|
||||
gb: &crate::bare::GitBare,
|
||||
connectivity_only: bool,
|
||||
) -> Result<RepositoryHealthResponse, tonic::Status> {
|
||||
tracing::info!(
|
||||
repo = %gb.bare_dir.display(),
|
||||
connectivity_only = connectivity_only,
|
||||
"running health check"
|
||||
);
|
||||
let mut args: Vec<&str> = vec!["fsck"];
|
||||
if connectivity_only {
|
||||
args.push("--connectivity-only");
|
||||
@@ -109,6 +127,12 @@ pub(crate) fn run_gc(
|
||||
prune: bool,
|
||||
aggressive: bool,
|
||||
) -> Result<RepositoryMaintenanceResponse, tonic::Status> {
|
||||
tracing::info!(
|
||||
repo = %gb.bare_dir.display(),
|
||||
prune = prune,
|
||||
aggressive = aggressive,
|
||||
"running garbage collection"
|
||||
);
|
||||
let mut args: Vec<&str> = vec!["gc"];
|
||||
if prune {
|
||||
args.push("--prune=now");
|
||||
@@ -126,6 +150,13 @@ pub(crate) fn run_repack(
|
||||
write_bitmaps: bool,
|
||||
write_multi_pack_index: bool,
|
||||
) -> Result<RepositoryMaintenanceResponse, tonic::Status> {
|
||||
tracing::info!(
|
||||
repo = %gb.bare_dir.display(),
|
||||
full = full,
|
||||
write_bitmaps = write_bitmaps,
|
||||
write_multi_pack_index = write_multi_pack_index,
|
||||
"running repack"
|
||||
);
|
||||
let mut args: Vec<&str> = vec!["repack", "-d"];
|
||||
if full {
|
||||
args.push("-a");
|
||||
@@ -145,6 +176,12 @@ pub(crate) fn run_commit_graph_write(
|
||||
split: bool,
|
||||
replace: bool,
|
||||
) -> Result<RepositoryMaintenanceResponse, tonic::Status> {
|
||||
tracing::info!(
|
||||
repo = %gb.bare_dir.display(),
|
||||
split = split,
|
||||
replace = replace,
|
||||
"writing commit-graph"
|
||||
);
|
||||
let mut args: Vec<&str> = vec!["commit-graph", "write"];
|
||||
if split {
|
||||
args.push("--split");
|
||||
|
||||
Reference in New Issue
Block a user