Skip to content

Commit 0a30994

Browse files
author
Devdutt Shenoi
committed
refactor: separate out metadata loading stage
1 parent 474a5d5 commit 0a30994

File tree

5 files changed

+38
-29
lines changed

5 files changed

+38
-29
lines changed

server/src/handlers/http/modal/ingest_server.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use super::IngestorMetadata;
2323
use super::OpenIdClient;
2424
use super::ParseableServer;
2525
use crate::analytics;
26-
use crate::banner;
2726
use crate::handlers::airplane;
2827
use crate::handlers::http::ingest;
2928
use crate::handlers::http::logstream;
@@ -34,9 +33,7 @@ use crate::localcache::LocalCacheManager;
3433
use crate::metrics;
3534
use crate::migration;
3635
use crate::migration::metadata_migration::migrate_ingester_metadata;
37-
use crate::rbac;
3836
use crate::rbac::role::Action;
39-
use crate::storage;
4037
use crate::storage::object_storage::ingestor_metadata_path;
4138
use crate::storage::object_storage::parseable_json_path;
4239
use crate::storage::staging;
@@ -84,8 +81,8 @@ impl ParseableServer for IngestServer {
8481
.service(Server::get_ingest_otel_factory());
8582
}
8683

87-
/// configure the server and start an instance to ingest data
88-
async fn init(&self) -> anyhow::Result<()> {
84+
async fn load_metadata(&self) -> anyhow::Result<Option<Bytes>> {
85+
// parseable can't use local storage for persistence when running a distributed setup
8986
if CONFIG.get_storage_mode_string() == "Local drive" {
9087
return Err(anyhow::Error::msg(
9188
// Error Message can be better
@@ -97,13 +94,12 @@ impl ParseableServer for IngestServer {
9794
let parseable_json = self.check_querier_state().await?;
9895
// to get the .parseable.json file in staging
9996
self.validate_credentials().await?;
100-
let metadata = storage::resolve_parseable_metadata(&parseable_json).await?;
10197

102-
banner::print(&CONFIG, &metadata).await;
103-
rbac::map::init(&metadata);
104-
// set the info in the global metadata
105-
metadata.set_global();
98+
Ok(parseable_json)
99+
}
106100

101+
/// configure the server and start an instance to ingest data
102+
async fn init(&self) -> anyhow::Result<()> {
107103
// ! Undefined and Untested behaviour
108104
if let Some(cache_manager) = LocalCacheManager::global() {
109105
cache_manager

server/src/handlers/http/modal/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use actix_web::HttpServer;
3333
use actix_web_prometheus::PrometheusMetrics;
3434
use async_trait::async_trait;
3535
use base64::Engine;
36+
use bytes::Bytes;
3637
use openid::Discovered;
3738
use serde::Deserialize;
3839
use serde::Serialize;
@@ -60,6 +61,12 @@ pub trait ParseableServer {
6061
where
6162
Self: Sized;
6263

64+
/// load metadata/configuration from persistence for previous sessions of parseable
65+
async fn load_metadata(&self) -> anyhow::Result<Option<Bytes>>;
66+
67+
/// code that describes starting and setup procedures for each type of server
68+
async fn init(&self) -> anyhow::Result<()>;
69+
6370
/// configure the server
6471
async fn start(
6572
&self,
@@ -165,8 +172,6 @@ pub trait ParseableServer {
165172

166173
Ok(())
167174
}
168-
169-
async fn init(&self) -> anyhow::Result<()>;
170175
}
171176

172177
#[derive(Serialize, Debug, Deserialize, Default, Clone, Eq, PartialEq)]

server/src/handlers/http/modal/query_server.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ use crate::rbac::role::Action;
2828
use crate::sync;
2929
use crate::users::dashboards::DASHBOARDS;
3030
use crate::users::filters::FILTERS;
31-
use crate::{analytics, banner, metrics, migration, rbac, storage};
31+
use crate::{analytics, metrics, migration, storage};
3232
use actix_web::web::{resource, ServiceConfig};
3333
use actix_web::{web, Scope};
3434
use async_trait::async_trait;
35+
use bytes::Bytes;
3536

3637
use crate::option::CONFIG;
3738

@@ -67,8 +68,8 @@ impl ParseableServer for QueryServer {
6768
.service(Server::get_generated());
6869
}
6970

70-
/// initialize the server, run migrations as needed and start an instance
71-
async fn init(&self) -> anyhow::Result<()> {
71+
async fn load_metadata(&self) -> anyhow::Result<Option<Bytes>> {
72+
// parseable can't use local storage for persistence when running a distributed setup
7273
if CONFIG.get_storage_mode_string() == "Local drive" {
7374
return Err(anyhow::anyhow!(
7475
"Query Server cannot be started in local storage mode. Please start the server in a supported storage mode.",
@@ -78,13 +79,12 @@ impl ParseableServer for QueryServer {
7879
migration::run_file_migration(&CONFIG).await?;
7980
let parseable_json = CONFIG.validate_storage().await?;
8081
migration::run_metadata_migration(&CONFIG, &parseable_json).await?;
81-
let metadata = storage::resolve_parseable_metadata(&parseable_json).await?;
82-
banner::print(&CONFIG, &metadata).await;
83-
// initialize the rbac map
84-
rbac::map::init(&metadata);
85-
// keep metadata info in mem
86-
metadata.set_global();
8782

83+
Ok(parseable_json)
84+
}
85+
86+
/// initialize the server, run migrations as needed and start an instance
87+
async fn init(&self) -> anyhow::Result<()> {
8888
let prometheus = metrics::build_metrics_handler();
8989
CONFIG.storage().register_store_metrics(&prometheus);
9090

server/src/handlers/http/modal/server.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919
use crate::analytics;
20-
use crate::banner;
2120
use crate::handlers;
2221
use crate::handlers::http::about;
2322
use crate::handlers::http::base_path;
@@ -31,7 +30,6 @@ use crate::hottier::HotTierManager;
3130
use crate::localcache::LocalCacheManager;
3231
use crate::metrics;
3332
use crate::migration;
34-
use crate::rbac;
3533
use crate::storage;
3634
use crate::sync;
3735
use crate::users::dashboards::DASHBOARDS;
@@ -43,6 +41,7 @@ use actix_web::Resource;
4341
use actix_web::Scope;
4442
use actix_web_static_files::ResourceFiles;
4543
use async_trait::async_trait;
44+
use bytes::Bytes;
4645

4746
use crate::{
4847
handlers::http::{
@@ -88,16 +87,16 @@ impl ParseableServer for Server {
8887
.service(Self::get_generated());
8988
}
9089

91-
/// configure the server and start an instance of the single server setup
92-
async fn init(&self) -> anyhow::Result<()> {
90+
async fn load_metadata(&self) -> anyhow::Result<Option<Bytes>> {
9391
migration::run_file_migration(&CONFIG).await?;
9492
let parseable_json = CONFIG.validate_storage().await?;
9593
migration::run_metadata_migration(&CONFIG, &parseable_json).await?;
96-
let metadata = storage::resolve_parseable_metadata(&parseable_json).await?;
97-
banner::print(&CONFIG, &metadata).await;
98-
rbac::map::init(&metadata);
99-
metadata.set_global();
10094

95+
Ok(parseable_json)
96+
}
97+
98+
// configure the server and start an instance of the single server setup
99+
async fn init(&self) -> anyhow::Result<()> {
101100
if let Some(cache_manager) = LocalCacheManager::global() {
102101
cache_manager
103102
.validate(CONFIG.parseable.local_cache_size)

server/src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,14 @@ async fn main() -> anyhow::Result<()> {
6363
Mode::All => Box::new(Server),
6464
};
6565

66+
// load metadata from persistence
67+
let parseable_json = server.load_metadata().await?;
68+
let metadata = storage::resolve_parseable_metadata(&parseable_json).await?;
69+
banner::print(&CONFIG, &metadata).await;
70+
// initialize the rbac map
71+
rbac::map::init(&metadata);
72+
// keep metadata info in mem
73+
metadata.set_global();
74+
6675
server.init().await
6776
}

0 commit comments

Comments
 (0)