Skip to main content

rlqt_lib/rel_db/
presets.rs

1// Copyright (C) 2025-2026 Michael S. Klishin and Contributors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14use crate::entry_metadata::labels::LogEntryLabels;
15use crate::rel_db::node_log_entry::QueryContext;
16use serde::{Deserialize, Serialize};
17use std::fmt;
18use std::str::FromStr;
19
20#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
21#[serde(rename_all = "snake_case")]
22pub enum QueryPreset {
23    ErrorsOrCrashes,
24}
25
26impl fmt::Display for QueryPreset {
27    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28        match self {
29            QueryPreset::ErrorsOrCrashes => write!(f, "errors_or_crashes"),
30        }
31    }
32}
33
34impl FromStr for QueryPreset {
35    type Err = String;
36
37    fn from_str(s: &str) -> Result<Self, Self::Err> {
38        match s {
39            "errors_or_crashes" => Ok(QueryPreset::ErrorsOrCrashes),
40            _ => Err(format!("Unknown preset: {}", s)),
41        }
42    }
43}
44
45impl QueryPreset {
46    pub fn severity(&self) -> Option<&'static str> {
47        match self {
48            QueryPreset::ErrorsOrCrashes => Some("error"),
49        }
50    }
51
52    pub fn labels(&self) -> LogEntryLabels {
53        match self {
54            QueryPreset::ErrorsOrCrashes => {
55                LogEntryLabels::ERL_PROCESS_CRASH | LogEntryLabels::EXCEPTIONS
56            }
57        }
58    }
59}
60
61impl From<QueryPreset> for QueryContext {
62    fn from(preset: QueryPreset) -> Self {
63        QueryContext {
64            preset: Some(preset),
65            ..Default::default()
66        }
67    }
68}