Skip to content

Commit a3f9ccb

Browse files
authored
fix: help messages for environment variables / flags (#588)
This PR also adds * fix startup check for cache size and improve the error message * gRPC port number in startup banner. Fixes #586
1 parent 631c8f4 commit a3f9ccb

File tree

9 files changed

+105
-65
lines changed

9 files changed

+105
-65
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ env-file
1313
parseable
1414
parseable_*
1515
parseable-env-secret
16+
cache

server/src/banner.rs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,17 @@ fn print_ascii_art() {
4545
"#;
4646

4747
eprint!("{ascii_name}");
48-
eprintln!(
49-
"
50-
Welcome to Parseable Server!"
51-
);
5248
}
5349

5450
fn status_info(config: &Config, scheme: &str, id: Uid) {
55-
let url = format!("\"{}://{}\"", scheme, config.parseable.address).underlined();
51+
let address = format!(
52+
"\"{}://{}\" ({}), \":{}\" (gRPC)",
53+
scheme,
54+
config.parseable.address,
55+
scheme.to_ascii_uppercase(),
56+
config.parseable.grpc_port
57+
);
58+
5659
let mut credentials =
5760
String::from("\"As set in P_USERNAME and P_PASSWORD environment variables\"");
5861

@@ -65,15 +68,21 @@ fn status_info(config: &Config, scheme: &str, id: Uid) {
6568
None => "Not Configured".grey(),
6669
};
6770

71+
eprintln!(
72+
"
73+
Welcome to Parseable Server! Deployment UID: \"{}\"",
74+
id.to_string(),
75+
);
76+
6877
eprintln!(
6978
"
7079
{}
71-
URL: {}
80+
Address: {}
7281
Credentials: {}
7382
Deployment UID: \"{}\"
7483
LLM Status: \"{}\"",
7584
"Server:".to_string().bold(),
76-
url,
85+
address,
7786
credentials,
7887
id.to_string(),
7988
llm_status
@@ -83,8 +92,8 @@ fn status_info(config: &Config, scheme: &str, id: Uid) {
8392
/// Prints information about the `ObjectStorage`.
8493
/// - Mode (`Local drive`, `S3 bucket`)
8594
/// - Staging (temporary landing point for incoming events)
86-
/// - Store (path where the data is stored)
87-
/// - Latency
95+
/// - Cache (local cache of data)
96+
/// - Store (path where the data is stored and its latency)
8897
async fn storage_info(config: &Config) {
8998
let storage = config.storage();
9099
let latency = storage.get_object_store().get_latency().await;
@@ -93,29 +102,32 @@ async fn storage_info(config: &Config) {
93102
"
94103
{}
95104
Mode: \"{}\"
96-
Staging: \"{}\"
97-
Store: \"{}\"
98-
Latency: \"{:?}\"",
105+
Staging: \"{}\"",
99106
"Storage:".to_string().bold(),
100107
config.mode_string(),
101108
config.staging_dir().to_string_lossy(),
102-
storage.get_endpoint(),
103-
latency
104109
);
105110

106111
if let Some(path) = &config.parseable.local_cache_path {
107-
let size: SpecificSize<human_size::Gigabyte> =
112+
let size: SpecificSize<human_size::Gigibyte> =
108113
SpecificSize::new(config.parseable.local_cache_size as f64, human_size::Byte)
109114
.unwrap()
110115
.into();
111116

112117
eprintln!(
113118
"\
114-
{:8}Cache: \"{}\"
115-
Cache Size: \"{}\"",
119+
{:8}Cache: \"{}\", (size: {})",
116120
"",
117121
path.display(),
118122
size
119123
);
120124
}
125+
126+
eprintln!(
127+
"\
128+
{:8}Store: \"{}\", (latency: {:?})",
129+
"",
130+
storage.get_endpoint(),
131+
latency
132+
);
121133
}

server/src/catalog/manifest.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub enum SortOrder {
4343
}
4444

4545
pub type SortInfo = (String, SortOrder);
46+
pub const CURRENT_MANIFEST_VERSION: &str = "v1";
4647

4748
/// An entry in a manifest which points to a single file.
4849
/// Additionally, it is meant to store the statistics for the file it
@@ -67,7 +68,7 @@ pub struct Manifest {
6768
impl Default for Manifest {
6869
fn default() -> Self {
6970
Self {
70-
version: "v1".to_string(),
71+
version: CURRENT_MANIFEST_VERSION.to_string(),
7172
files: Vec::default(),
7273
}
7374
}

server/src/catalog/snapshot.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use chrono::{DateTime, Utc};
2222

2323
use crate::query::PartialTimeFilter;
2424

25+
pub const CURRENT_SNAPSHOT_VERSION: &str = "v1";
2526
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
2627
pub struct Snapshot {
2728
pub version: String,
@@ -31,7 +32,7 @@ pub struct Snapshot {
3132
impl Default for Snapshot {
3233
fn default() -> Self {
3334
Self {
34-
version: "v1".to_string(),
35+
version: CURRENT_SNAPSHOT_VERSION.to_string(),
3536
manifest_list: Vec::default(),
3637
}
3738
}

server/src/localcache.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::{io, path::PathBuf};
2121
use fs_extra::file::CopyOptions;
2222
use futures_util::TryFutureExt;
2323
use hashlru::Cache;
24+
use human_size::{Byte, Gigibyte, SpecificSize};
2425
use itertools::{Either, Itertools};
2526
use object_store::{local::LocalFileSystem, ObjectStore};
2627
use once_cell::sync::OnceCell;
@@ -30,6 +31,7 @@ use crate::option::CONFIG;
3031

3132
pub const STREAM_CACHE_FILENAME: &str = ".cache.json";
3233
pub const CACHE_META_FILENAME: &str = ".cache_meta.json";
34+
pub const CURRENT_CACHE_VERSION: &str = "v1";
3335

3436
#[derive(Debug, serde::Deserialize, serde::Serialize)]
3537
pub struct LocalCache {
@@ -42,7 +44,7 @@ pub struct LocalCache {
4244
impl LocalCache {
4345
fn new() -> Self {
4446
Self {
45-
version: "v1".to_string(),
47+
version: CURRENT_CACHE_VERSION.to_string(),
4648
current_size: 0,
4749
files: Cache::new(100),
4850
}
@@ -58,7 +60,7 @@ pub struct CacheMeta {
5860
impl CacheMeta {
5961
fn new() -> Self {
6062
Self {
61-
version: "v1".to_string(),
63+
version: CURRENT_CACHE_VERSION.to_string(),
6264
size_capacity: 0,
6365
}
6466
}
@@ -97,7 +99,8 @@ impl LocalCacheManager {
9799

98100
pub async fn validate(&self, config_capacity: u64) -> Result<(), CacheError> {
99101
fs::create_dir_all(&self.cache_path).await?;
100-
let path = cache_meta_path(&self.cache_path).unwrap();
102+
let path = cache_meta_path(&self.cache_path)
103+
.map_err(|err| CacheError::ObjectStoreError(err.into()))?;
101104
let resp = self
102105
.filesystem
103106
.get(&path)
@@ -107,7 +110,21 @@ impl LocalCacheManager {
107110
let updated_cache = match resp {
108111
Ok(bytes) => {
109112
let mut meta: CacheMeta = serde_json::from_slice(&bytes)?;
110-
if !meta.size_capacity == config_capacity {
113+
if meta.size_capacity != config_capacity {
114+
// log the change in cache size
115+
let configured_size_human: SpecificSize<Gigibyte> =
116+
SpecificSize::new(config_capacity as f64, Byte)
117+
.unwrap()
118+
.into();
119+
let current_size_human: SpecificSize<Gigibyte> =
120+
SpecificSize::new(meta.size_capacity as f64, Byte)
121+
.unwrap()
122+
.into();
123+
log::warn!(
124+
"Cache size is updated from {} to {}",
125+
current_size_human,
126+
configured_size_human
127+
);
111128
meta.size_capacity = config_capacity;
112129
Some(meta)
113130
} else {
@@ -123,10 +140,6 @@ impl LocalCacheManager {
123140
};
124141

125142
if let Some(updated_cache) = updated_cache {
126-
log::info!(
127-
"Cache is updated to new size of {} Bytes",
128-
&updated_cache.size_capacity
129-
);
130143
self.filesystem
131144
.put(&path, serde_json::to_vec(&updated_cache)?.into())
132145
.await?

server/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ use crate::localcache::LocalCacheManager;
5454
#[actix_web::main]
5555
async fn main() -> anyhow::Result<()> {
5656
env_logger::init();
57-
CONFIG.validate();
5857
let storage = CONFIG.storage().get_object_store();
5958
CONFIG.validate_staging()?;
6059
migration::run_metadata_migration(&CONFIG).await?;

0 commit comments

Comments
 (0)