Skip to content

chore: server side improvements #1396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use crate::{
pub const DEFAULT_USERNAME: &str = "admin";
pub const DEFAULT_PASSWORD: &str = "admin";

pub const DATASET_FIELD_COUNT_LIMIT: usize = 250;
pub const DATASET_FIELD_COUNT_LIMIT: usize = 1000;
#[derive(Parser)]
#[command(
name = "parseable",
Expand Down
34 changes: 33 additions & 1 deletion src/handlers/http/alerts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,42 @@ pub async fn list(req: HttpRequest) -> Result<impl Responder, AlertError> {
};

let alerts = alerts.list_alerts_for_user(session_key, tags_list).await?;
let alerts_summary = alerts
let mut alerts_summary = alerts
.iter()
.map(|alert| alert.to_summary())
.collect::<Vec<_>>();

// Sort by state priority (Triggered > Silenced > Resolved) then by severity (Critical > High > Medium > Low)
alerts_summary.sort_by(|a, b| {
// Helper function to convert state to priority number (lower number = higher priority)
let state_priority = |state: &str| match state {
"Triggered" => 0,
"Silenced" => 1,
"Resolved" => 2,
_ => 3, // Unknown state gets lowest priority
};

// Helper function to convert severity to priority number (lower number = higher priority)
let severity_priority = |severity: &str| match severity {
"Critical" => 0,
"High" => 1,
"Medium" => 2,
"Low" => 3,
_ => 4, // Unknown severity gets lowest priority
};

let state_a = a.get("state").and_then(|v| v.as_str()).unwrap_or("");
let state_b = b.get("state").and_then(|v| v.as_str()).unwrap_or("");

let severity_a = a.get("severity").and_then(|v| v.as_str()).unwrap_or("");
let severity_b = b.get("severity").and_then(|v| v.as_str()).unwrap_or("");

// First sort by state, then by severity
state_priority(state_a)
.cmp(&state_priority(state_b))
.then_with(|| severity_priority(severity_a).cmp(&severity_priority(severity_b)))
});

Ok(web::Json(alerts_summary))
}

Expand Down
11 changes: 10 additions & 1 deletion src/parseable/streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use parquet::{
use relative_path::RelativePathBuf;
use tokio::task::JoinSet;
use tracing::{error, info, trace, warn};
use ulid::Ulid;

use crate::{
LOCK_EXPECT, OBJECT_STORE_DATA_GRANULARITY,
Expand Down Expand Up @@ -185,7 +186,15 @@ impl Stream {
parsed_timestamp: NaiveDateTime,
custom_partition_values: &HashMap<String, String>,
) -> String {
let mut hostname = hostname::get().unwrap().into_string().unwrap();
let mut hostname = hostname::get()
.unwrap_or_else(|_| std::ffi::OsString::from(&Ulid::new().to_string()))
.into_string()
.unwrap_or_else(|_| Ulid::new().to_string())
.chars()
.filter(|c| c.is_alphanumeric() || *c == '-' || *c == '_')
.collect::<String>()
.chars()
.collect::<String>();
if let Some(id) = &self.ingestor_id {
hostname.push_str(id);
}
Expand Down
18 changes: 16 additions & 2 deletions src/storage/object_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,15 +1011,29 @@ pub fn target_json_path(target_id: &Ulid) -> RelativePathBuf {

#[inline(always)]
pub fn manifest_path(prefix: &str) -> RelativePathBuf {
let hostname = hostname::get()
.unwrap_or_else(|_| std::ffi::OsString::from(&Ulid::new().to_string()))
.into_string()
.unwrap_or_else(|_| Ulid::new().to_string())
.chars()
.filter(|c| c.is_alphanumeric() || *c == '-' || *c == '_')
.collect::<String>()
.chars()
.collect::<String>();

match &PARSEABLE.options.mode {
Mode::Ingest => {
let id = INGESTOR_META
.get()
.unwrap_or_else(|| panic!("{}", INGESTOR_EXPECT))
.get_node_id();
let manifest_file_name = format!("ingestor.{id}.{MANIFEST_FILE}");

let manifest_file_name = format!("ingestor.{hostname}.{id}.{MANIFEST_FILE}");
RelativePathBuf::from_iter([prefix, &manifest_file_name])
}
_ => {
let manifest_file_name = format!("{hostname}.{MANIFEST_FILE}");
RelativePathBuf::from_iter([prefix, &manifest_file_name])
}
_ => RelativePathBuf::from_iter([prefix, MANIFEST_FILE]),
}
}
Loading