use crate::alerts::AlertCondition; use crate::data_value::MetricPrimitiveKind; use crate::metric_primitive::MetricPrimitive; use crate::profile::{ChartType, Dashboard, Panel, Profile}; use crate::settings::{ColorScheme, CssEntry, Settings}; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; #[derive(Debug, Clone, Serialize)] pub struct LogEntryDto { pub sequence: u64, pub timestamp_ms: i64, pub text: String, pub params: BTreeMap, } #[derive(Debug, Clone, Serialize)] pub struct ParamDeclarationDto { pub name: String, pub message_match_regex: String, pub capture_group: String, pub json_field_path: Option, pub kind: MetricPrimitiveKind, pub elapsed_since_last: bool, pub auto_derived: bool, #[serde(default)] pub reserved: bool, } #[derive(Debug, Clone, Serialize)] pub struct MetricDeclarationDto { pub name: String, pub message_match_regex: String, pub label_params: Vec, pub value_param: Option, pub matched_labels: Option>, pub unmatched_labels: Option>, } #[derive(Debug, Clone, Serialize)] pub struct TimelineBucketDto { pub start_ms: i64, pub count: u64, } #[derive(Debug, Clone, Serialize)] pub struct StatsDto { pub log_count: u64, pub first_sequence: Option, pub last_sequence: Option, pub first_timestamp_ms: Option, pub last_timestamp_ms: Option, pub approx_bytes_total: u64, pub ingest_lag_high_watermark_ms: i64, } #[derive(Debug, Deserialize)] pub struct LogsParams { pub since_sequence: Option, pub start_ms: Option, pub end_ms: Option, pub limit: Option, pub filter: Option, pub sort_by: Option, pub sort_missing_fallback: Option, } #[derive(Debug, Deserialize)] pub struct TimelineParams { pub start_ms: Option, pub end_ms: Option, pub bucket_ms: Option, pub filter: Option, } #[derive(Debug, Clone, Serialize)] pub struct BucketValueDto { pub labels: BTreeMap, pub sequence: u64, pub timestamp_ms: i64, pub value: MetricPrimitive, } #[derive(Debug, Deserialize)] pub struct BucketValuesParams { pub labels: Option, pub since_sequence: Option, pub start_ms: Option, pub end_ms: Option, pub limit: Option, } #[derive(Debug, Clone, Serialize, PartialEq)] pub struct PromqlSeriesDto { pub labels: BTreeMap, pub points: Vec<(i64, f64)>, } #[derive(Debug, Deserialize)] pub struct PromqlParams { pub promql: String, pub start_ms: Option, pub end_ms: Option, } #[derive(Debug, Serialize)] pub struct ErrorDto { pub error: String, } #[derive(Debug, Deserialize)] pub struct ImportCssRequest { pub filename: String, pub content: String, } #[derive(Debug, Deserialize)] pub struct LinkCssRequest { pub path_or_url: String, } #[derive(Debug, Clone, Serialize)] pub struct CssEntryDto { pub id: String, pub kind: CssEntryKind, pub filename: Option, pub path_or_url: Option, } #[derive(Debug, Clone, Copy, Serialize)] #[serde(rename_all = "lowercase")] pub enum CssEntryKind { Imported, Linked, } impl From<&CssEntry> for CssEntryDto { fn from(entry: &CssEntry) -> Self { match entry { CssEntry::Imported { id, filename } => CssEntryDto { id: id.clone(), kind: CssEntryKind::Imported, filename: Some(filename.clone()), path_or_url: None, }, CssEntry::Linked { path_or_url } => CssEntryDto { id: crate::settings::css_entry_id(entry), kind: CssEntryKind::Linked, filename: None, path_or_url: Some(path_or_url.clone()), }, } } } #[derive(Debug, Clone, Serialize)] pub struct SettingsDto { pub color_scheme: ColorScheme, pub active_profile: Option, pub max_logs: Option, pub custom_theme_id: Option, pub ntfy_topic: Option, pub ntfy_server: Option, } impl From<&Settings> for SettingsDto { fn from(settings: &Settings) -> Self { SettingsDto { color_scheme: settings.color_scheme, active_profile: settings.active_profile.clone(), max_logs: settings.max_logs, custom_theme_id: settings.custom_theme_id.clone(), ntfy_topic: settings.ntfy_topic.clone(), ntfy_server: settings.ntfy_server.clone(), } } } #[derive(Debug, Deserialize)] pub struct UpdateSettingsRequest { pub color_scheme: Option, #[serde(default, deserialize_with = "deserialize_double_option")] pub max_logs: Option>, #[serde(default, deserialize_with = "deserialize_double_option")] pub custom_theme_id: Option>, #[serde(default, deserialize_with = "deserialize_double_option")] pub ntfy_topic: Option>, #[serde(default, deserialize_with = "deserialize_double_option")] pub ntfy_server: Option>, } fn deserialize_double_option<'de, D, T>(deserializer: D) -> Result>, D::Error> where D: serde::Deserializer<'de>, T: Deserialize<'de>, { Option::::deserialize(deserializer).map(Some) } #[derive(Debug, Deserialize)] pub struct CreateAlertRuleRequest { pub name: String, pub enabled: bool, pub condition: AlertCondition, } #[derive(Debug, Deserialize)] pub struct UpdateAlertRuleRequest { pub name: String, pub enabled: bool, pub condition: AlertCondition, } #[derive(Debug, Deserialize)] pub struct TestAlertNotificationRequest { pub topic: String, pub server: Option, } #[derive(Debug, Clone, Serialize)] pub struct ProfileSummaryDto { pub name: String, pub param_count: usize, pub metric_count: usize, pub dashboard_count: usize, } impl From<&Profile> for ProfileSummaryDto { fn from(profile: &Profile) -> Self { ProfileSummaryDto { name: profile.name.clone(), param_count: profile.params.len(), metric_count: profile.metrics.len(), dashboard_count: profile.dashboards.len(), } } } #[derive(Debug, Deserialize)] pub struct CreateProfileRequest { pub name: String, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PanelDto { pub id: String, pub title: String, pub promql: String, pub chart_type: ChartType, } impl From<&Panel> for PanelDto { fn from(panel: &Panel) -> Self { PanelDto { id: panel.id.clone(), title: panel.title.clone(), promql: panel.promql.clone(), chart_type: panel.chart_type, } } } impl From<&PanelDto> for Panel { fn from(dto: &PanelDto) -> Self { Panel { id: dto.id.clone(), title: dto.title.clone(), promql: dto.promql.clone(), chart_type: dto.chart_type, } } } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct DashboardDto { pub id: String, pub name: String, pub panels: Vec, } impl From<&Dashboard> for DashboardDto { fn from(dashboard: &Dashboard) -> Self { DashboardDto { id: dashboard.id.clone(), name: dashboard.name.clone(), panels: dashboard.panels.iter().map(PanelDto::from).collect(), } } } impl From<&DashboardDto> for Dashboard { fn from(dto: &DashboardDto) -> Self { Dashboard { id: dto.id.clone(), name: dto.name.clone(), panels: dto.panels.iter().map(Panel::from).collect(), } } } #[derive(Debug, Deserialize)] pub struct CreateDashboardRequest { pub name: String, } #[derive(Debug, Deserialize)] pub struct SaveDashboardRequest { pub name: String, #[serde(default)] pub panels: Vec, }