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
146 changes: 123 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ parquet = "57.1.0"

# Web server and HTTP-related
actix-cors = "0.7.0"
actix-web-lab = "0.24.3"
actix-web = { version = "4.9.0", features = ["rustls-0_22"] }
actix-web-httpauth = "0.8"
actix-web-prometheus = { version = "0.1" }
Expand Down Expand Up @@ -83,7 +84,7 @@ tokio = { version = "^1.43", default-features = false, features = [
"fs",
"rt-multi-thread",
] }
tokio-stream = { version = "0.1", features = ["fs"] }
tokio-stream = { version = "0.1.17", features = ["fs"] }
tokio-util = { version = "0.7" }

# # Logging and Metrics
Expand Down
26 changes: 24 additions & 2 deletions src/alerts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ use crate::metastore::MetastoreError;
// use crate::option::Mode;
use crate::parseable::{PARSEABLE, StreamNotFound};
use crate::query::{QUERY_SESSION, resolve_stream_names};
use crate::rbac::map::SessionKey;
use crate::rbac::map::{SessionKey, sessions};
use crate::sse::{SSE_HANDLER, SSEAlertInfo};
use crate::storage;
use crate::storage::ObjectStorageError;
use crate::sync::alert_runtime;
Expand Down Expand Up @@ -606,12 +607,33 @@ impl AlertConfig {

pub async fn trigger_notifications(&self, message: String) -> Result<(), AlertError> {
let mut context = self.get_context();
context.message = message;
context.message.clone_from(&message);

for target_id in &self.targets {
let target = TARGETS.get_target_by_id(target_id).await?;
trace!("Target (trigger_notifications)-\n{target:?}");
target.call(context.clone());
}

// get active sessions
let active_sessions = sessions().get_active_sessions();
let mut broadcast_to = vec![];
for session in active_sessions {
if user_auth_for_query(&session, &self.query).await.is_ok()
&& let SessionKey::SessionId(id) = &session
{
broadcast_to.push(*id);
}
}

if let Ok(msg) = &serde_json::to_string(&SSEAlertInfo {
id: self.id,
state: self.state,
message,
}) {
SSE_HANDLER.broadcast(msg, Some(&broadcast_to)).await;
}

Ok(())
}

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub mod prism;
pub mod query;
pub mod rbac;
mod response;
pub mod sse;
mod static_schema;
mod stats;
pub mod storage;
Expand Down
5 changes: 5 additions & 0 deletions src/rbac/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use super::{
user,
};
use chrono::{DateTime, Utc};
use itertools::Itertools;
use once_cell::sync::{Lazy, OnceCell};
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard};
Expand Down Expand Up @@ -168,6 +169,10 @@ pub struct Sessions {
}

impl Sessions {
pub fn get_active_sessions(&self) -> Vec<SessionKey> {
self.active_sessions.keys().cloned().collect_vec()
}

// only checks if the session is expired or not
pub fn is_session_expired(&self, key: &SessionKey) -> bool {
// fetch userid from session key
Expand Down
Loading
Loading