Skip to content

Commit 05de709

Browse files
authored
Report latency at server startup (#551) (#562)
- Measure the `[time]` taken to get the `.parseable.json` object from the store at server startup - Print `[time]` on the banner This is useful to display current latency at server startup time and will help the user decide if latency is higher than expected in their deployment.
1 parent 3aefb9b commit 05de709

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

server/src/banner.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub async fn print(config: &Config, meta: &StorageMetadata) {
2727
print_ascii_art();
2828
let scheme = config.parseable.get_scheme();
2929
status_info(config, &scheme, meta.deployment_id);
30-
storage_info(config);
30+
storage_info(config).await;
3131
about::print(config, meta).await;
3232
println!();
3333
}
@@ -79,16 +79,26 @@ fn status_info(config: &Config, scheme: &str, id: Uid) {
7979
);
8080
}
8181

82-
fn storage_info(config: &Config) {
82+
/// Prints information about the `ObjectStorage`.
83+
/// - Mode (`Local drive`, `S3 bucket`)
84+
/// - Staging (temporary landing point for incoming events)
85+
/// - Store (path where the data is stored)
86+
/// - Latency
87+
async fn storage_info(config: &Config) {
88+
let storage = config.storage();
89+
let latency = storage.get_object_store().get_latency().await;
90+
8391
eprintln!(
8492
"
8593
{}
8694
Mode: \"{}\"
8795
Staging: \"{}\"
88-
Store: \"{}\"",
96+
Store: \"{}\"
97+
Latency: \"{:?}\"",
8998
"Storage:".to_string().bold(),
9099
config.mode_string(),
91100
config.staging_dir().to_string_lossy(),
92-
config.storage().get_endpoint(),
101+
storage.get_endpoint(),
102+
latency
93103
)
94104
}

server/src/storage/object_storage.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ use relative_path::RelativePath;
3838
use relative_path::RelativePathBuf;
3939
use serde_json::Value;
4040

41-
use std::{collections::HashMap, fs, path::Path, sync::Arc};
41+
use std::{
42+
collections::HashMap,
43+
fs,
44+
path::Path,
45+
sync::Arc,
46+
time::{Duration, Instant},
47+
};
4248

4349
// metadata file names in a Stream prefix
4450
pub(super) const STREAM_METADATA_FILE_NAME: &str = ".stream.json";
@@ -67,6 +73,19 @@ pub trait ObjectStorage: Sync + 'static {
6773
async fn list_streams(&self) -> Result<Vec<LogStream>, ObjectStorageError>;
6874
async fn list_dates(&self, stream_name: &str) -> Result<Vec<String>, ObjectStorageError>;
6975
async fn upload_file(&self, key: &str, path: &Path) -> Result<(), ObjectStorageError>;
76+
77+
/// Returns the amount of time taken by the `ObjectStore` to perform a get
78+
/// call.
79+
async fn get_latency(&self) -> Duration {
80+
// It's Ok to `unwrap` here. The hardcoded value will always Result in
81+
// an `Ok`.
82+
let path = RelativePathBuf::from_path(".parseable.json").unwrap();
83+
84+
let start = Instant::now();
85+
let _ = self.get_object(&path).await;
86+
start.elapsed()
87+
}
88+
7089
fn normalize_prefixes(&self, prefixes: Vec<String>) -> Vec<String>;
7190
fn query_prefixes(&self, prefixes: Vec<String>) -> Vec<ListingTableUrl>;
7291
fn store_url(&self) -> url::Url;

0 commit comments

Comments
 (0)