-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
elastic: automatically try to update field limit on startup
- Loading branch information
Showing
6 changed files
with
109 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
// SPDX-FileCopyrightText: (C) 2020 Jason Ish <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
|
||
use serde::{Deserialize, Serialize}; | ||
use serde_json::json; | ||
use thiserror::Error; | ||
|
||
use crate::datetime::DateTime; | ||
use crate::eventrepo::DatastoreError; | ||
|
||
pub(crate) use client::Version; | ||
pub(crate) use client::{Client, ClientBuilder}; | ||
pub(crate) use eventrepo::ElasticEventRepo; | ||
pub(crate) use importer::ElasticEventSink; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::json; | ||
use thiserror::Error; | ||
|
||
pub mod client; | ||
pub mod eventrepo; | ||
pub mod importer; | ||
pub mod request; | ||
pub(crate) mod client; | ||
pub(crate) mod eventrepo; | ||
pub(crate) mod importer; | ||
pub(crate) mod request; | ||
pub(crate) mod util; | ||
|
||
pub(crate) const TAG_ESCALATED: &str = "evebox.escalated"; | ||
pub(crate) const TAGS_ESCALATED: [&str; 1] = [TAG_ESCALATED]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// SPDX-FileCopyrightText: (C) 2024 Jason Ish <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
|
||
use tracing::{error, info}; | ||
|
||
use super::Client; | ||
|
||
pub(crate) async fn check_and_set_field_limit(client: &Client, template_name: &str) { | ||
match client.get_template(template_name).await { | ||
Ok(template) => { | ||
let field_limit = &template["settings"]["index"]["mapping"]["total_fields"]["limit"]; | ||
let limit: Option<i64> = match field_limit { | ||
serde_json::Value::Number(n) => n.as_i64(), | ||
serde_json::Value::String(s) => s.parse::<i64>().ok(), | ||
_ => None, | ||
}; | ||
if let Some(limit) = limit { | ||
if limit >= 5000 { | ||
info!("Field limit of {} OK, will not increase", limit); | ||
return; | ||
} | ||
} | ||
} | ||
Err(err) => { | ||
info!( | ||
"Failed to find template for index {}: {:?}", | ||
template_name, err | ||
); | ||
} | ||
} | ||
|
||
info!("Attempting to increase Elasticsearch field limit to 5000"); | ||
match update_template_field_limit(client, template_name, 5000).await { | ||
Ok(_ok) => { | ||
info!("Successfully updated Elasticsearch template field limit"); | ||
} | ||
Err(err) => { | ||
error!( | ||
"Failed to update Elasticsearch template field limit: {:?}", | ||
err | ||
); | ||
} | ||
} | ||
} | ||
|
||
pub(crate) async fn update_template_field_limit( | ||
client: &Client, | ||
index: &str, | ||
limit: usize, | ||
) -> anyhow::Result<()> { | ||
#[rustfmt::skip] | ||
let request = json!({ | ||
"index_patterns": [ | ||
format!("{}*", index), | ||
], | ||
"settings": { | ||
"index": { | ||
"mapping": { | ||
"total_fields": { | ||
"limit": limit, | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
|
||
let response = client | ||
.put(&format!("_template/{index}"))? | ||
.json(&request) | ||
.send() | ||
.await?; | ||
let status = response.status(); | ||
let body = response.text().await?; | ||
info!("Template {}: status: {}, body: {}", index, status, body); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters