Skip to main content

dol/
lib.rs

1//! # DOL — Docker Observability Language
2//!
3//! A SQL-like query language for Docker infrastructure. Query containers,
4//! stream events, set up alerts, analyze anomalies, and inspect historical
5//! data — all from a single CLI.
6//!
7//! ## Quick start
8//!
9//! ```ignore
10//! use dol::{Cli, cli};
11//! let cli = Cli::parse_from(["dol", "observe containers"]);
12//! cli::run(cli).await?;
13//! ```
14//!
15//! ## Crate structure
16//!
17//! | Module | Purpose |
18//! |--------|---------|
19//! | [`parser`] | DOL query parser (tokenizer → AST) |
20//! | [`ast`]    | Abstract syntax tree types |
21//! | [`semantic`] | Type-checking and field validation |
22//! | [`planner`]  | Logical query plan generation |
23//! | [`executor`] | Batch query execution |
24//! | [`eval`]    | Expression evaluation engine |
25//! | [`docker`]  | Docker client abstraction (bollard) |
26//! | [`metrics`] | Metrics collection |
27//! | [`events`]  | Event streaming |
28//! | [`alerts`]  | Alert rule evaluation |
29//! | [`storage`] / [`sqlite_store`] | Telemetry persistence |
30//! | [`cli`]     | CLI argument parsing and dispatch |
31//! | [`repl`]    | Interactive REPL |
32//! | [`dashboard`] | TUI dashboard and top |
33//! | [`config`]  | Configuration management |
34//! | [`export`]  | InfluxDB / Loki / Prometheus output |
35//! | [`analyze`] | Anomaly detection and diagnostics |
36//! | [`collector`] | Background telemetry collection |
37
38#![doc(
39    html_logo_url = "https://genc-murat.github.io/DockQL/logo.svg",
40    html_favicon_url = "https://genc-murat.github.io/DockQL/logo.svg"
41)]
42#![allow(
43    clippy::cast_possible_truncation,
44    clippy::cast_precision_loss,
45    clippy::cast_sign_loss,
46    clippy::cast_possible_wrap,
47    clippy::too_many_lines,
48    clippy::future_not_send,
49    clippy::missing_errors_doc,
50    clippy::missing_panics_doc
51)]
52
53pub mod alerts;
54pub mod analyze;
55pub mod ast;
56pub mod cli;
57pub mod collector;
58pub mod config;
59pub mod dashboard;
60pub mod docker;
61pub mod eval;
62pub mod events;
63pub mod executor;
64pub mod export;
65pub mod metrics;
66pub mod parser;
67pub mod planner;
68pub mod repl;
69pub mod semantic;
70pub mod sqlite_store;
71pub mod storage;
72
73pub use cli::Cli;
74pub use cli::OutputFormat;
75pub use export::ExportFormat;
76
77/// Shared helper: wrap a `String` (or `&str`) into a `serde_json::Value::String`.
78pub(crate) fn json_string(value: impl Into<String>) -> serde_json::Value {
79    serde_json::Value::String(value.into())
80}
81
82/// Map a `CollectionTarget` to its single-letter prefix alias used in join queries.
83pub(crate) const fn target_alias(target: ast::CollectionTarget) -> &'static str {
84    match target {
85        ast::CollectionTarget::Containers => "c",
86        ast::CollectionTarget::Images => "i",
87        ast::CollectionTarget::Networks => "n",
88        ast::CollectionTarget::Volumes => "v",
89    }
90}
91
92// ═══════════════════════════════════════════════════════════════════
93// ANSI escape code constants
94// ═══════════════════════════════════════════════════════════════════
95
96/// ANSI reset — clears all formatting.
97pub const ANSI_RESET: &str = "\x1b[0m";
98
99/// ANSI style modifiers.
100pub const ANSI_BOLD: &str = "\x1b[1m";
101pub const ANSI_DIM: &str = "\x1b[2m";
102pub const ANSI_ITALIC: &str = "\x1b[3m";
103pub const ANSI_UNDERLINE: &str = "\x1b[4m";
104
105/// ANSI foreground (text) colors — standard 3/4-bit palette.
106pub const ANSI_FG_BLACK: &str = "\x1b[30m";
107pub const ANSI_FG_RED: &str = "\x1b[31m";
108pub const ANSI_FG_GREEN: &str = "\x1b[32m";
109pub const ANSI_FG_YELLOW: &str = "\x1b[33m";
110pub const ANSI_FG_BLUE: &str = "\x1b[34m";
111pub const ANSI_FG_MAGENTA: &str = "\x1b[35m";
112pub const ANSI_FG_CYAN: &str = "\x1b[36m";
113pub const ANSI_FG_WHITE: &str = "\x1b[37m";
114
115/// ANSI foreground colors — bright (90–97) palette.
116pub const ANSI_FG_DARK_GRAY: &str = "\x1b[90m";
117pub const ANSI_FG_LIGHT_RED: &str = "\x1b[91m";
118pub const ANSI_FG_LIGHT_GREEN: &str = "\x1b[92m";
119pub const ANSI_FG_LIGHT_YELLOW: &str = "\x1b[93m";
120pub const ANSI_FG_LIGHT_BLUE: &str = "\x1b[94m";
121pub const ANSI_FG_LIGHT_MAGENTA: &str = "\x1b[95m";
122pub const ANSI_FG_LIGHT_CYAN: &str = "\x1b[96m";
123
124/// ANSI background colors — standard 3/4-bit palette.
125pub(crate) const ANSI_BG_BLACK: &str = "\x1b[40m";
126pub(crate) const ANSI_BG_RED: &str = "\x1b[41m";
127pub(crate) const ANSI_BG_GREEN: &str = "\x1b[42m";
128pub(crate) const ANSI_BG_YELLOW: &str = "\x1b[43m";
129pub(crate) const ANSI_BG_BLUE: &str = "\x1b[44m";
130pub(crate) const ANSI_BG_MAGENTA: &str = "\x1b[45m";
131pub(crate) const ANSI_BG_CYAN: &str = "\x1b[46m";
132pub(crate) const ANSI_BG_WHITE: &str = "\x1b[47m";
133
134/// ANSI background colors — bright (100–107) palette.
135pub(crate) const ANSI_BG_DARK_GRAY: &str = "\x1b[100m";
136pub(crate) const ANSI_BG_LIGHT_RED: &str = "\x1b[101m";
137pub(crate) const ANSI_BG_LIGHT_GREEN: &str = "\x1b[102m";
138pub(crate) const ANSI_BG_LIGHT_YELLOW: &str = "\x1b[103m";
139pub(crate) const ANSI_BG_LIGHT_BLUE: &str = "\x1b[104m";
140pub(crate) const ANSI_BG_LIGHT_MAGENTA: &str = "\x1b[105m";
141pub(crate) const ANSI_BG_LIGHT_CYAN: &str = "\x1b[106m";
142
143/// Bold red — used for critical/error states.
144pub(crate) const ANSI_BOLD_RED: &str = "\x1b[31;1m";
145
146/// Compound: bold + cyan — dark-theme title.
147pub(crate) const ANSI_TITLE_DARK: &str = "\x1b[1;36m";
148/// Compound: bold + underline + white — dark-theme header.
149pub(crate) const ANSI_HEADER_DARK: &str = "\x1b[1;4;37m";
150/// Compound: bold + blue — light-theme title.
151pub(crate) const ANSI_TITLE_LIGHT: &str = "\x1b[1;34m";
152/// Compound: bold + underline + black — light-theme header.
153pub(crate) const ANSI_HEADER_LIGHT: &str = "\x1b[1;4;30m";
154
155// ═══════════════════════════════════════════════════════════════════
156// Threshold / byte-size constants
157// ═══════════════════════════════════════════════════════════════════
158
159/// 1 GB expressed in bytes — used for memory thresholding and byte formatting.
160pub const ONE_GB: u64 = 1_073_741_824;
161
162/// 512 MB expressed in bytes — used for memory thresholding.
163pub const HALF_GB: u64 = 536_870_912;
164
165/// CPU percentage above which the value is coloured red (>80%).
166pub const CPU_RED_THRESHOLD: f64 = 80.0;
167
168/// CPU percentage above which the value is coloured yellow (>50%).
169pub const CPU_YELLOW_THRESHOLD: f64 = 50.0;
170
171/// Alert evaluation loop interval in seconds.
172pub(crate) const ALERT_EVAL_INTERVAL: u64 = 5;
173
174/// Default metrics collection interval in seconds (used with --collect).
175pub(crate) const DEFAULT_METRICS_INTERVAL: u64 = 30;
176
177/// Default snapshot collection interval in seconds (used with --collect).
178pub(crate) const DEFAULT_SNAPSHOT_INTERVAL: u64 = 300;