Compress impls

This commit is contained in:
Hugh Kaznowski
2026-09-07 02:04:36 +01:00
parent 55820982b1
commit f96de8f38d
3 changed files with 22 additions and 92 deletions
+2 -59
View File
@@ -1,8 +1,8 @@
use crate::engine::alerts::AlertCondition;
use crate::engine::data_value::MetricPrimitiveKind;
use crate::engine::metric_primitive::MetricPrimitive;
use crate::config::profile::{ChartType, Dashboard, Panel, Profile};
use crate::config::Settings;
use crate::config::profile::{Panel, Profile};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
@@ -192,63 +192,6 @@ 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,
@@ -258,5 +201,5 @@ pub struct CreateDashboardRequest {
pub struct SaveDashboardRequest {
pub name: String,
#[serde(default)]
pub panels: Vec<PanelDto>,
pub panels: Vec<Panel>,
}
+6 -9
View File
@@ -7,7 +7,7 @@ use std::sync::Arc;
use crate::api::dto::{
BucketValuesParams, CreateAlertRuleRequest, CreateDashboardRequest, CreateProfileRequest,
DashboardDto, ErrorDto, MetricDeclarationDto,
ErrorDto, MetricDeclarationDto,
ParamDeclarationDto, LogsParams, ProfileSummaryDto, PromqlParams, SaveDashboardRequest,
SettingsDto, TestAlertNotificationRequest, TimelineParams, UpdateAlertRuleRequest, UpdateSettingsRequest,
};
@@ -773,10 +773,7 @@ async fn list_dashboards(
) -> impl IntoResponse {
let settings = state.settings.lock().unwrap();
match settings.list_dashboards(&name) {
Ok(dashboards) => {
let dtos: Vec<DashboardDto> = dashboards.iter().map(DashboardDto::from).collect();
Json(dtos).into_response()
}
Ok(dashboards) => Json(dashboards).into_response(),
Err(err) => err.into_response(),
}
}
@@ -788,7 +785,7 @@ async fn create_dashboard(
) -> impl IntoResponse {
let mut settings = state.settings.lock().unwrap();
match settings.create_dashboard(&state.settings_path, &name, body.name) {
Ok(dashboard) => (StatusCode::CREATED, Json(DashboardDto::from(&dashboard))).into_response(),
Ok(dashboard) => (StatusCode::CREATED, Json(dashboard)).into_response(),
Err(err) => err.into_response(),
}
}
@@ -800,7 +797,7 @@ async fn get_dashboard(
let settings = state.settings.lock().unwrap();
match settings.list_dashboards(&name) {
Ok(dashboards) => match dashboards.iter().find(|d| d.id == dashboard_id) {
Some(dashboard) => Json(DashboardDto::from(dashboard)).into_response(),
Some(dashboard) => Json(dashboard).into_response(),
None => ProfileError::NotFound.into_response(),
},
Err(err) => err.into_response(),
@@ -816,10 +813,10 @@ async fn save_dashboard(
let dashboard = Dashboard {
id: dashboard_id.clone(),
name: body.name,
panels: body.panels.iter().map(|p| p.into()).collect(),
panels: body.panels,
};
match settings.save_dashboard(&state.settings_path, &name, &dashboard_id, dashboard) {
Ok(dashboard) => Json(DashboardDto::from(&dashboard)).into_response(),
Ok(dashboard) => Json(dashboard).into_response(),
Err(err) => err.into_response(),
}
}
+14 -24
View File
@@ -54,6 +54,7 @@ pub(crate) struct EngineSnapshot {
pub(crate) ingest_lag_high_watermark_ms: i64,
}
// --- core: snapshot construction and log range access ---
impl EngineSnapshot {
pub(crate) fn metric_declarations_range(
&self,
@@ -218,16 +219,7 @@ impl EngineSnapshot {
}
}
impl EngineSnapshot {
pub(crate) fn handle_query_ro(&self, query: EngineQuery) -> EngineResponse {
handle_query_inner(self, query, SortHelperAccess::Immutable(&self.sort_helper_indexes))
}
pub(crate) fn has_sort_helper_index(&self, sort_by: &str) -> bool {
self.sort_helper_indexes.contains_key(sort_by)
}
}
// --- filter: compiling search-bar filter expressions ---
impl EngineSnapshot {
pub(in crate::engine::snapshot) fn compile_filter_query(&self, filter: &str, now: Timestamp) -> Result<CompiledFilter, String> {
let expr = filter_parser::parse(filter).map_err(|err| err.to_string())?;
@@ -308,6 +300,7 @@ impl EngineSnapshot {
}
}
// --- metrics: declaring, applying, and querying metric buckets ---
impl EngineSnapshot {
pub(crate) fn validate_metric_request(&self, request: &DeclareMetricRequest) -> Result<Regex, String> {
let re = Regex::new(&request.message_match_regex)
@@ -424,9 +417,7 @@ impl EngineSnapshot {
self.clear_metric_data(name);
existed
}
}
impl EngineSnapshot {
#[allow(clippy::too_many_arguments)]
fn apply_metric_to_log(
&mut self,
@@ -597,9 +588,7 @@ impl EngineSnapshot {
})
.flatten()
}
}
impl EngineSnapshot {
pub(crate) fn declared_value_kind(&self, metric_name: &str) -> Option<MetricPrimitiveKind> {
match self.index.get(&IndexKey::MetricDeclaration { name: metric_name.to_string() }) {
Some(DataValue::MetricDeclaration { value_param, .. }) => Some(
@@ -619,6 +608,7 @@ impl EngineSnapshot {
}
}
// --- params: declaring and resolving param values ---
impl EngineSnapshot {
pub(crate) fn validate_param_declaration(&self, request: &DeclareParamRequest) -> Result<(), String> {
if OTTYL_RESERVED_PARAM_NAMES.contains(&request.name.as_str()) {
@@ -666,9 +656,7 @@ impl EngineSnapshot {
DataValue::ParamDeclaration(ParamDeclaration { auto_derived: false, ..request }),
);
}
}
impl EngineSnapshot {
fn auto_derived_param_count(&self) -> usize {
self.param_declarations_range().filter(|declaration| declaration.6).count()
}
@@ -734,9 +722,7 @@ impl EngineSnapshot {
total += 1;
}
}
}
impl EngineSnapshot {
pub(crate) fn derive_log_stream_params_from_row(
&mut self,
header: &crate::engine::logfmt::LogStreamHeader,
@@ -795,9 +781,7 @@ impl EngineSnapshot {
}
}
}
}
impl EngineSnapshot {
pub(crate) fn clear_all_param_declarations(&mut self) -> usize {
let names: Vec<String> =
self.param_declarations_range().map(|(name, ..)| name.to_string()).collect();
@@ -818,9 +802,7 @@ impl EngineSnapshot {
let reextracted = self.param_declarations_range().count();
(reextracted, logs_considered)
}
}
impl EngineSnapshot {
pub(in crate::engine::snapshot) fn resolved_param_declarations(&self) -> HashMap<String, ResolvedParam> {
self.param_declarations_range()
.filter_map(|(name, _, capture_group, json_field_path, kind, elapsed_since_last, _, log_stream_gated)| {
@@ -840,9 +822,7 @@ impl EngineSnapshot {
})
.collect()
}
}
impl EngineSnapshot {
pub(in crate::engine::snapshot) fn resolve_param_value(
&mut self,
metric_name: &str,
@@ -876,7 +856,16 @@ impl EngineSnapshot {
}
}
// --- query: EngineQuery/PromQL evaluation ---
impl EngineSnapshot {
pub(crate) fn handle_query_ro(&self, query: EngineQuery) -> EngineResponse {
handle_query_inner(self, query, SortHelperAccess::Immutable(&self.sort_helper_indexes))
}
pub(crate) fn has_sort_helper_index(&self, sort_by: &str) -> bool {
self.sort_helper_indexes.contains_key(sort_by)
}
pub(crate) fn evaluate_promql(
&self,
parsed: &PromqlQuery,
@@ -1050,6 +1039,7 @@ impl EngineSnapshot {
}
}
// --- sort: sort-helper index maintenance ---
impl EngineSnapshot {
pub(super) fn build_sort_helper_index(&self, sort_by: &str) -> BTreeMap<SortHelperKey, Timestamp> {
let compiled_params = self.compiled_param_declarations();