use crate::metric_primitive::MetricPrimitive; use crate::timestamp::Timestamp; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; /// A single parsed metric primitive extracted from a regex capture group. #[allow(dead_code)] #[derive(Debug, Clone, Serialize, Deserialize)] pub struct RegexToMetricPrimitiveMatcher { pub param_name: String, pub capture_group: String, pub kind: MetricPrimitiveKind, /// Ticket 022: whether this param contributes to the bucket's `labels` /// (the default) or is the bucket's per-event captured `value` (at most /// one `Value`-role param per metric — `declare_metric` rejects more /// than one). `#[serde(default)]` so profile files saved before this /// field existed still load, with every param defaulting to `Label` — /// i.e. unchanged behavior (the fixed occurrence-count-of-1 value). #[serde(default)] pub role: ParamRole, } /// See [`RegexToMetricPrimitiveMatcher::role`]. #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)] #[serde(rename_all = "lowercase")] pub enum ParamRole { #[default] Label, Value, } /// `rename_all = "lowercase"` matches every other `kind`-style enum exposed /// over the API/settings JSON (`ColorScheme`, `CssEntryKind`, /// `ProfileMetricPrimitiveKind`), so `POST /api/params`/`POST /api/metrics` /// bodies use `"string"`/`"number"`/`"timestamp"`. #[allow(dead_code)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub enum MetricPrimitiveKind { String, Number, Timestamp, /// Ticket 023: milliseconds. On a metric's `Value`-role param, this /// doesn't parse the captured text at all — the value is instead derived /// as the elapsed time since the previous counter event with the same /// label set (see `crate::engine::apply_metric_to_log`). On any other /// param (a `Label`-role metric param, or a standalone `ParamDeclaration`), /// it parses the captured text as a literal `i64` millisecond count. Duration, } /// Value type paired with [`crate::index_key::IndexKey`] in the engine's primary index. #[allow(dead_code)] #[derive(Debug, Clone, Serialize)] pub enum DataValue { /// Paired with `IndexKey::IngestedLog`. LogLiteral { text: String }, /// Paired with `IndexKey::ParamDeclaration`. ParamDeclaration { message_match_regex: String, capture_group: String, kind: MetricPrimitiveKind, }, /// Paired with `IndexKey::MetricDeclaration`. MetricDeclaration { message_match_regex: String, params: Vec, /// See `crate::engine::DeclareMetricRequest::matched_labels` (ticket 025). matched_labels: Option>, /// See `crate::engine::DeclareMetricRequest::unmatched_labels` (ticket 025). unmatched_labels: Option>, }, /// Paired with `IndexKey::Bucket`. BucketValue { values: Vec<(u64, Timestamp, MetricPrimitive)>, }, /// Paired with `IndexKey::LastMetricEvent` (ticket 023). LastEventTimestamp { timestamp: Timestamp, }, }