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