Removes doc comments, module comments, and inline comments across the backend so the only comments left in the codebase are the brief ones on the constants they document. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A1ZJ3SrayzLzVndhVq9BmS
312 lines
8.0 KiB
Rust
312 lines
8.0 KiB
Rust
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<String, MetricPrimitive>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize)]
|
|
pub struct ParamDeclarationDto {
|
|
pub name: String,
|
|
pub message_match_regex: String,
|
|
pub capture_group: String,
|
|
pub json_field_path: Option<String>,
|
|
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<String>,
|
|
pub value_param: Option<String>,
|
|
pub matched_labels: Option<BTreeMap<String, String>>,
|
|
pub unmatched_labels: Option<BTreeMap<String, String>>,
|
|
}
|
|
|
|
#[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<u64>,
|
|
pub last_sequence: Option<u64>,
|
|
pub first_timestamp_ms: Option<i64>,
|
|
pub last_timestamp_ms: Option<i64>,
|
|
pub approx_bytes_total: u64,
|
|
pub ingest_lag_high_watermark_ms: i64,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct LogsParams {
|
|
pub since_sequence: Option<u64>,
|
|
pub start_ms: Option<i64>,
|
|
pub end_ms: Option<i64>,
|
|
pub limit: Option<usize>,
|
|
pub filter: Option<String>,
|
|
pub sort_by: Option<String>,
|
|
pub sort_missing_fallback: Option<bool>,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct TimelineParams {
|
|
pub start_ms: Option<i64>,
|
|
pub end_ms: Option<i64>,
|
|
pub bucket_ms: Option<i64>,
|
|
pub filter: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize)]
|
|
pub struct BucketValueDto {
|
|
pub labels: BTreeMap<String, MetricPrimitive>,
|
|
pub sequence: u64,
|
|
pub timestamp_ms: i64,
|
|
pub value: MetricPrimitive,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct BucketValuesParams {
|
|
pub labels: Option<String>,
|
|
pub since_sequence: Option<u64>,
|
|
pub start_ms: Option<i64>,
|
|
pub end_ms: Option<i64>,
|
|
pub limit: Option<usize>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, PartialEq)]
|
|
pub struct PromqlSeriesDto {
|
|
pub labels: BTreeMap<String, String>,
|
|
pub points: Vec<(i64, f64)>,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct PromqlParams {
|
|
pub promql: String,
|
|
pub start_ms: Option<i64>,
|
|
pub end_ms: Option<i64>,
|
|
}
|
|
|
|
#[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<String>,
|
|
pub path_or_url: Option<String>,
|
|
}
|
|
|
|
#[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<String>,
|
|
pub max_logs: Option<usize>,
|
|
pub custom_theme_id: Option<String>,
|
|
pub ntfy_topic: Option<String>,
|
|
pub ntfy_server: Option<String>,
|
|
}
|
|
|
|
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<ColorScheme>,
|
|
#[serde(default, deserialize_with = "deserialize_double_option")]
|
|
pub max_logs: Option<Option<usize>>,
|
|
#[serde(default, deserialize_with = "deserialize_double_option")]
|
|
pub custom_theme_id: Option<Option<String>>,
|
|
#[serde(default, deserialize_with = "deserialize_double_option")]
|
|
pub ntfy_topic: Option<Option<String>>,
|
|
#[serde(default, deserialize_with = "deserialize_double_option")]
|
|
pub ntfy_server: Option<Option<String>>,
|
|
}
|
|
|
|
fn deserialize_double_option<'de, D, T>(deserializer: D) -> Result<Option<Option<T>>, D::Error>
|
|
where
|
|
D: serde::Deserializer<'de>,
|
|
T: Deserialize<'de>,
|
|
{
|
|
Option::<T>::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<String>,
|
|
}
|
|
|
|
#[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<PanelDto>,
|
|
}
|
|
|
|
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<PanelDto>,
|
|
}
|