#[derive(Debug, Clone, PartialEq)]
pub struct LogQuery {
pub selector: StreamSelector,
pub pipeline: Vec<PipelineStage>,
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct StreamSelector {
pub matchers: Vec<LabelMatcher>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct LabelMatcher {
pub name: String,
pub op: MatchOp,
pub value: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum MatchOp {
Eq,
Neq,
Re,
Nre,
}
impl std::fmt::Display for MatchOp {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
MatchOp::Eq => "=",
MatchOp::Neq => "!=",
MatchOp::Re => "=~",
MatchOp::Nre => "!~",
})
}
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum PipelineStage {
LineFilter(LineFilter),
Json(Vec<LabelExtraction>),
Logfmt(LogfmtStage),
Regexp(String),
Pattern(String),
Unpack,
Decolorize,
LabelFilter(LabelFilterExpr),
LineFormat(String),
LabelFormat(Vec<LabelFormat>),
Drop(Vec<LabelPredicate>),
Keep(Vec<LabelPredicate>),
Distinct(Vec<String>),
Unwrap(Unwrap),
}
#[derive(Debug, Clone, PartialEq)]
pub struct LineFilter {
pub op: LineFilterOp,
pub value: String,
pub is_ip: bool,
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct LogfmtStage {
pub flags: Vec<String>,
pub extractions: Vec<LabelExtraction>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct LabelPredicate {
pub name: String,
pub matcher: Option<(MatchOp, String)>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum LineFilterOp {
Contains,
NotContains,
Regex,
NotRegex,
}
#[derive(Debug, Clone, PartialEq)]
pub struct LabelExtraction {
pub name: String,
pub expr: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct LabelFormat {
pub dst: String,
pub value: LabelFormatValue,
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum LabelFormatValue {
Rename(String),
Template(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Grouping {
pub without: bool,
pub labels: Vec<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Unwrap {
pub label: String,
pub conversion: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum LabelFilterExpr {
Pred(LabelFilterPred),
And(Box<LabelFilterExpr>, Box<LabelFilterExpr>),
Or(Box<LabelFilterExpr>, Box<LabelFilterExpr>),
}
#[derive(Debug, Clone, PartialEq)]
pub struct LabelFilterPred {
pub name: String,
pub op: FilterOp,
pub value: FilterValue,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum FilterOp {
Eq,
Neq,
Re,
Nre,
CmpEq,
Gt,
Gte,
Lt,
Lte,
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum FilterValue {
String(String),
Number(f64),
Duration(std::time::Duration),
Bytes(u64),
Ip(String),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn match_ops_display_as_their_operators() {
assert_eq!(MatchOp::Eq.to_string(), "=");
assert_eq!(MatchOp::Neq.to_string(), "!=");
assert_eq!(MatchOp::Re.to_string(), "=~");
assert_eq!(MatchOp::Nre.to_string(), "!~");
}
}