Privatize fake sources, drop restating docs, remove boxed iterator in capped
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YShymaPrXmc3KYRUg2HMSs
This commit is contained in:
1 parent
8b3f91dcb7
commit
d5a0373a75
9 files changed
+25
-38
No files matched your search
@@ -30,7 +30,6 @@ pub enum TokenCmd {
|
||||
Revoke { name: String },
|
||||
}
|
||||
|
||||
/// A token row without its hash.
|
||||
#[derive(Debug, Clone, sqlx::FromRow)]
|
||||
pub struct TokenInfo {
|
||||
pub name: String,
|
||||
@@ -39,7 +38,6 @@ pub struct TokenInfo {
|
||||
pub last_used_at: Option<String>,
|
||||
}
|
||||
|
||||
/// Hex sha256 of a token string.
|
||||
pub fn hash_token(token: &str) -> String {
|
||||
Sha256::digest(token.as_bytes())
|
||||
.iter()
|
||||
@@ -149,7 +147,6 @@ pub async fn verify(pool: &SqlitePool, token: &str) -> Result<bool> {
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// Execute a token subcommand against the DB at `config.auth.db_path`.
|
||||
pub async fn run(cmd: TokenCmd, config: &Config) -> Result<()> {
|
||||
let pool = crate::db::open(config).await?;
|
||||
match cmd {
|
||||
|
||||
@@ -422,7 +422,6 @@ mod tests {
|
||||
load(None, &CliOverrides::default()),
|
||||
Err(ConfigError::Invalid(_))
|
||||
));
|
||||
// Loopback with auth off is fine.
|
||||
jail.set_env("SKYG_SERVER__BIND", "127.0.0.1");
|
||||
assert!(load(None, &CliOverrides::default()).is_ok());
|
||||
Ok(())
|
||||
|
||||
@@ -9,7 +9,6 @@ use sqlx::SqlitePool;
|
||||
|
||||
use crate::config::Config;
|
||||
|
||||
/// Open (creating if needed) `config.auth.db_path` and migrate.
|
||||
pub async fn open(config: &Config) -> Result<SqlitePool> {
|
||||
let path = &config.auth.db_path;
|
||||
if let Some(dir) = path.parent().filter(|d| !d.as_os_str().is_empty()) {
|
||||
@@ -51,7 +50,6 @@ fn restrict_files(db: &Path) {
|
||||
let _ = db;
|
||||
}
|
||||
|
||||
/// Run the embedded migrations.
|
||||
pub async fn migrate(pool: &SqlitePool) -> Result<()> {
|
||||
sqlx::migrate!("./migrations")
|
||||
.run(pool)
|
||||
|
||||
+12
-12
@@ -147,20 +147,20 @@ fn capped<T: Serialize>(
|
||||
.iter()
|
||||
.map(|i| serde_json::to_string(i).map_or(0, |s| s.len() + 1))
|
||||
.collect();
|
||||
let mut total = 0usize;
|
||||
let mut keep = 0usize;
|
||||
let iter: Box<dyn Iterator<Item = usize>> = if keep_newest {
|
||||
Box::new(sizes.iter().rev().copied())
|
||||
let fit = |sizes: &mut dyn Iterator<Item = &usize>| {
|
||||
let mut total = 0usize;
|
||||
sizes
|
||||
.take_while(|&&sz| {
|
||||
total += sz;
|
||||
total <= MAX_RESULT_BYTES
|
||||
})
|
||||
.count()
|
||||
};
|
||||
let keep = if keep_newest {
|
||||
fit(&mut sizes.iter().rev())
|
||||
} else {
|
||||
Box::new(sizes.iter().copied())
|
||||
fit(&mut sizes.iter())
|
||||
};
|
||||
for sz in iter {
|
||||
if total + sz > MAX_RESULT_BYTES {
|
||||
break;
|
||||
}
|
||||
total += sz;
|
||||
keep += 1;
|
||||
}
|
||||
let truncated = keep < items.len();
|
||||
if truncated {
|
||||
if keep_newest {
|
||||
|
||||
@@ -46,8 +46,7 @@ pub struct BollardDocker {
|
||||
}
|
||||
|
||||
impl BollardDocker {
|
||||
/// Never fails or blocks. Reads `sources.docker_socket` and
|
||||
/// `limits.max_tail` from `config`. Follow tasks stop on `shutdown`.
|
||||
/// Never fails or blocks.
|
||||
pub fn new(config: &Config, shutdown: CancellationToken) -> Self {
|
||||
Self {
|
||||
socket: config.sources.docker_socket.clone(),
|
||||
@@ -67,7 +66,6 @@ impl BollardDocker {
|
||||
.map_err(|e| map_error(&e, &self.socket_name()))
|
||||
}
|
||||
|
||||
/// The cached client, connecting on first successful use.
|
||||
fn client(&self) -> Result<Docker, AppError> {
|
||||
let mut guard = self.client.lock().unwrap_or_else(|p| p.into_inner());
|
||||
if let Some(c) = guard.as_ref() {
|
||||
|
||||
+11
-12
@@ -1,8 +1,7 @@
|
||||
//! Fixture-backed in-memory sources for tests and for developing surfaces
|
||||
//! without systemd, journald or Docker.
|
||||
//!
|
||||
//! `fake_state(config)` returns a ready `AppState`. Each fake exposes its
|
||||
//! fixtures as public fields so tests can replace them.
|
||||
//! `fake_state(config)` returns a ready `AppState`.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -37,9 +36,9 @@ pub fn fake_state(config: Config) -> AppState {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FakeSystemd {
|
||||
pub units: Vec<UnitStatus>,
|
||||
pub timers: Vec<TimerInfo>,
|
||||
struct FakeSystemd {
|
||||
units: Vec<UnitStatus>,
|
||||
timers: Vec<TimerInfo>,
|
||||
}
|
||||
|
||||
impl Default for FakeSystemd {
|
||||
@@ -125,13 +124,13 @@ impl SystemdSource for FakeSystemd {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FakeJournal {
|
||||
pub entries: Vec<JournalEntry>,
|
||||
struct FakeJournal {
|
||||
entries: Vec<JournalEntry>,
|
||||
shutdown: CancellationToken,
|
||||
}
|
||||
|
||||
impl FakeJournal {
|
||||
pub fn new(shutdown: CancellationToken) -> Self {
|
||||
fn new(shutdown: CancellationToken) -> Self {
|
||||
let e = |t: &str, p: Priority, unit: &str, msg: &str| JournalEntry {
|
||||
timestamp: ts(t),
|
||||
priority: Some(p),
|
||||
@@ -215,14 +214,14 @@ impl JournalSource for FakeJournal {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FakeDocker {
|
||||
pub containers: Vec<ContainerStatus>,
|
||||
pub logs: Vec<LogLine>,
|
||||
struct FakeDocker {
|
||||
containers: Vec<ContainerStatus>,
|
||||
logs: Vec<LogLine>,
|
||||
shutdown: CancellationToken,
|
||||
}
|
||||
|
||||
impl FakeDocker {
|
||||
pub fn new(shutdown: CancellationToken) -> Self {
|
||||
fn new(shutdown: CancellationToken) -> Self {
|
||||
let c = |id: &str, name: &str, state: &str, health: Option<&str>| ContainerStatus {
|
||||
summary: ContainerSummary {
|
||||
id: id.into(),
|
||||
|
||||
@@ -32,8 +32,7 @@ pub struct SdJournal {
|
||||
}
|
||||
|
||||
impl SdJournal {
|
||||
/// Must not fail or block. Reads `sources.journal_namespace` and
|
||||
/// `limits.max_lines` from `config`. Follow tasks stop on `shutdown`.
|
||||
/// Must not fail or block.
|
||||
pub fn new(config: &Config, shutdown: CancellationToken) -> Self {
|
||||
let ns = config.sources.journal_namespace.trim();
|
||||
Self {
|
||||
@@ -80,7 +79,6 @@ fn unavailable(e: impl std::fmt::Display) -> AppError {
|
||||
AppError::Unavailable(format!("journal: {e}"))
|
||||
}
|
||||
|
||||
/// Open the journal (inside the blocking thread) and apply unit/priority matches.
|
||||
fn open_filtered(ns: Option<&str>, q: &JournalQuery) -> Result<Journal, AppError> {
|
||||
let opts = OpenOptions::default();
|
||||
let mut j = match ns {
|
||||
|
||||
@@ -108,7 +108,6 @@ fn emit(logger: &SdkLogger, r: LogRec) {
|
||||
logger.emit(rec);
|
||||
}
|
||||
|
||||
/// Start the journal tasks and the docker reconciler.
|
||||
pub fn spawn(state: AppState, provider: &SdkLoggerProvider) -> Vec<JoinHandle<()>> {
|
||||
let logger = provider.logger("skyg-linux-tracker");
|
||||
let mut handles = Vec::new();
|
||||
|
||||
@@ -222,7 +222,6 @@ async fn collect(state: &AppState, prev: &Snapshot) -> Snapshot {
|
||||
snap
|
||||
}
|
||||
|
||||
/// Register the gauges and start the poll loop.
|
||||
pub fn spawn(state: AppState, provider: &SdkMeterProvider) -> Vec<JoinHandle<()>> {
|
||||
// Observations are computed once per poll; callbacks only filter.
|
||||
let current: Arc<RwLock<Arc<Vec<Obs>>>> = Arc::default();
|
||||
|
||||
Reference in new issue
Block a user