Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 34 additions & 81 deletions src/alerts/alert_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl From<&str> for AlertVersion {
}

#[derive(
derive_more::Display,
Debug,
serde::Serialize,
serde::Deserialize,
Expand All @@ -71,101 +72,72 @@ pub enum Severity {
Low,
}

impl Display for Severity {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Severity::Critical => write!(f, "Critical"),
Severity::High => write!(f, "High"),
Severity::Medium => write!(f, "Medium"),
Severity::Low => write!(f, "Low"),
}
}
}

#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
#[derive(derive_more::Display, Debug, serde::Serialize, serde::Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub enum LogicalOperator {
#[display("AND")]
And,
#[display("OR")]
Or,
}

impl Display for LogicalOperator {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
LogicalOperator::And => write!(f, "AND"),
LogicalOperator::Or => write!(f, "OR"),
}
}
}

#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq)]
#[derive(derive_more::Display, Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum AlertType {
#[display("threshold")]
Threshold,
#[display("anomaly")]
Anomaly(AnomalyConfig),
#[display("forecast")]
Forecast(ForecastConfig),
}

impl Display for AlertType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
AlertType::Threshold => write!(f, "threshold"),
AlertType::Anomaly(_) => write!(f, "anomaly"),
AlertType::Forecast(_) => write!(f, "forecast"),
}
}
}

#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Copy, PartialEq, Eq, Default)]
#[derive(
derive_more::Display,
Debug,
serde::Serialize,
serde::Deserialize,
Clone,
Copy,
PartialEq,
Eq,
Default,
)]
#[serde(rename_all = "camelCase")]
pub enum AlertQueryType {
#[default]
#[display("builder")]
Builder,
#[serde(alias = "sql")]
#[display("code")]
Code,
#[display("promql")]
Promql,
}

impl Display for AlertQueryType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
AlertQueryType::Builder => write!(f, "builder"),
AlertQueryType::Code => write!(f, "code"),
AlertQueryType::Promql => write!(f, "promql"),
}
}
}

#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
#[derive(derive_more::Display, Debug, serde::Serialize, serde::Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub enum AlertOperator {
#[serde(rename = ">")]
#[display(">")]
GreaterThan,
#[serde(rename = "<")]
#[display("<")]
LessThan,
#[serde(rename = "=")]
#[display("=")]
Equal,
#[serde(rename = "!=")]
#[display("!=")]
NotEqual,
#[serde(rename = ">=")]
#[display(">=")]
GreaterThanOrEqual,
#[serde(rename = "<=")]
#[display("<=")]
LessThanOrEqual,
}

impl Display for AlertOperator {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
AlertOperator::GreaterThan => write!(f, ">"),
AlertOperator::LessThan => write!(f, "<"),
AlertOperator::Equal => write!(f, "="),
AlertOperator::NotEqual => write!(f, "!="),
AlertOperator::GreaterThanOrEqual => write!(f, ">="),
AlertOperator::LessThanOrEqual => write!(f, "<="),
}
}
}

#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, FromStr, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum WhereConfigOperator {
Expand Down Expand Up @@ -292,7 +264,7 @@ mod tests {
}
}

#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
#[derive(derive_more::Display, Debug, serde::Serialize, serde::Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub enum AggregateFunction {
Avg,
Expand All @@ -303,26 +275,14 @@ pub enum AggregateFunction {
Sum,
}

impl Display for AggregateFunction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
AggregateFunction::Avg => write!(f, "Avg"),
AggregateFunction::Count => write!(f, "Count"),
AggregateFunction::CountDistinct => write!(f, "CountDistinct"),
AggregateFunction::Min => write!(f, "Min"),
AggregateFunction::Max => write!(f, "Max"),
AggregateFunction::Sum => write!(f, "Sum"),
}
}
}

#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub enum EvalConfig {
RollingWindow(RollingWindow),
}

#[derive(
derive_more::Display,
Debug,
serde::Serialize,
serde::Deserialize,
Expand All @@ -337,23 +297,16 @@ pub enum EvalConfig {
)]
#[serde(rename_all = "camelCase")]
pub enum AlertState {
#[display("triggered")]
Triggered,
#[default]
#[serde(rename = "not-triggered")]
#[display("not-triggered")]
NotTriggered,
#[display("disabled")]
Disabled,
}

impl Display for AlertState {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
AlertState::Triggered => write!(f, "triggered"),
AlertState::Disabled => write!(f, "disabled"),
AlertState::NotTriggered => write!(f, "not-triggered"),
}
}
}

#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq, Default)]
#[serde(rename_all = "camelCase")]
pub enum NotificationState {
Expand Down
15 changes: 1 addition & 14 deletions src/alerts/alert_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ pub struct NotificationStateRequest {
}

/// MTTR (Mean Time To Recovery) statistics
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct MTTRStats {
/// Total number of incidents (triggered -> not-triggered cycles)
Expand Down Expand Up @@ -709,19 +709,6 @@ impl MTTRStats {
}
}

impl Default for MTTRStats {
fn default() -> Self {
Self {
total_incidents: 0,
mean_seconds: 0.0,
median_seconds: 0.0,
min_seconds: 0.0,
max_seconds: 0.0,
recovery_times_seconds: Vec::new(),
}
}
}

/// Aggregated MTTR statistics across multiple alerts
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down
24 changes: 2 additions & 22 deletions src/handlers/http/oidc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use serde::Deserialize;
use ulid::Ulid;
use url::Url;

use crate::handlers::http::modal::utils::rbac_utils::{get_metadata, put_metadata};
use crate::{
handlers::{
COOKIE_AGE_DAYS, SESSION_COOKIE_NAME, USER_COOKIE_NAME, USER_ID_COOKIE_NAME,
Expand All @@ -52,7 +53,7 @@ use crate::{
map::{DEFAULT_ROLE, SessionKey},
user::{self, GroupUser, User, UserType},
},
storage::{self, ObjectStorageError, StorageMetadata},
storage::{ObjectStorageError, StorageMetadata},
utils::{
actix::extract_session_key_from_req, get_tenant_id_from_key, get_tenant_id_from_request,
},
Expand Down Expand Up @@ -615,27 +616,6 @@ pub async fn update_user_if_changed(
Ok(user)
}

async fn get_metadata(
tenant_id: &Option<String>,
) -> Result<crate::storage::StorageMetadata, ObjectStorageError> {
let metadata = PARSEABLE
.metastore
.get_parseable_metadata(tenant_id)
.await
.map_err(|e| ObjectStorageError::MetastoreError(Box::new(e.to_detail())))?
.ok_or_else(|| ObjectStorageError::Custom("parseable metadata not initialized".into()))?;
Ok(serde_json::from_slice::<StorageMetadata>(&metadata)?)
}

async fn put_metadata(
metadata: &StorageMetadata,
tenant_id: &Option<String>,
) -> Result<(), ObjectStorageError> {
storage::put_remote_metadata(metadata, tenant_id).await?;
storage::put_staging_metadata(metadata, tenant_id)?;
Ok(())
}

#[derive(Debug, thiserror::Error)]
pub enum OIDCError {
#[error("Failed to connect to storage: {0}")]
Expand Down
26 changes: 3 additions & 23 deletions src/handlers/http/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ use actix_web::{
web::{self, Json},
};

use crate::handlers::http::modal::utils::rbac_utils::{get_metadata, put_metadata};
use crate::rbac::map::roles;
use crate::rbac::role::model::{Role, RoleType, RoleUI};
use crate::{
parseable::{DEFAULT_TENANT, PARSEABLE},
parseable::DEFAULT_TENANT,
rbac::map::{DEFAULT_ROLE, mut_roles, mut_sessions, read_user_groups, users},
storage::{self, ObjectStorageError, StorageMetadata},
storage::ObjectStorageError,
utils::get_tenant_id_from_request,
validator::{self, error::UsernameValidationError},
};
Expand Down Expand Up @@ -228,27 +229,6 @@ pub fn get_default_internal(tenant_id: &Option<String>) -> serde_json::Value {
res
}

async fn get_metadata(
tenant_id: &Option<String>,
) -> Result<crate::storage::StorageMetadata, ObjectStorageError> {
let metadata = PARSEABLE
.metastore
.get_parseable_metadata(tenant_id)
.await
.map_err(|e| ObjectStorageError::MetastoreError(Box::new(e.to_detail())))?
.ok_or_else(|| ObjectStorageError::Custom("parseable metadata not initialized".into()))?;
Ok(serde_json::from_slice::<StorageMetadata>(&metadata)?)
}

async fn put_metadata(
metadata: &StorageMetadata,
tenant_id: &Option<String>,
) -> Result<(), ObjectStorageError> {
storage::put_remote_metadata(metadata, tenant_id).await?;
storage::put_staging_metadata(metadata, tenant_id)?;
Ok(())
}

#[derive(Debug, thiserror::Error)]
pub enum RoleError {
#[error("Failed to connect to storage: {0}")]
Expand Down
9 changes: 1 addition & 8 deletions src/livetail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub static LIVETAIL: Lazy<LiveTail> = Lazy::new(LiveTail::default);

pub type LiveTailRegistry = RwLock<HashMap<String, Vec<SenderPipe>>>;

#[derive(Default)]
pub struct LiveTail {
pipes: Arc<LiveTailRegistry>,
}
Expand Down Expand Up @@ -61,14 +62,6 @@ impl LiveTail {
}
}

impl Default for LiveTail {
fn default() -> Self {
Self {
pipes: Arc::new(RwLock::default()),
}
}
}

#[derive(Debug, PartialEq)]
pub enum Message {
Record(RecordBatch),
Expand Down
Loading
Loading