Skip to content

Commit b5d549d

Browse files
nitishtgurjotkaur20
authored andcommitted
fix: clean up storage validation logic further (#633)
Standardise the error message and also use the new logg.ing domain for short URLs.
1 parent 1fce919 commit b5d549d

File tree

7 files changed

+23
-31
lines changed

7 files changed

+23
-31
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<div align="center">
1212

1313
[![Docker Pulls](https://img.shields.io/docker/pulls/parseable/parseable?logo=docker&label=Docker%20Pulls)](https://hub.docker.com/r/parseable/parseable)
14-
[![Slack](https://img.shields.io/badge/slack-brightgreen.svg?logo=slack&label=Community&style=flat&color=%2373DC8C&)](https://launchpass.com/parseable)
15-
[![Docs](https://img.shields.io/badge/stable%20docs-parseable.io%2Fdocs-brightgreen?style=flat&color=%2373DC8C&label=Docs)](https://www.parseable.io/docs)
14+
[![Slack](https://img.shields.io/badge/slack-brightgreen.svg?logo=slack&label=Community&style=flat&color=%2373DC8C&)](https://logg.ing/community)
15+
[![Docs](https://img.shields.io/badge/stable%20docs-parseable.io%2Fdocs-brightgreen?style=flat&color=%2373DC8C&label=Docs)](https://logg.ing/docs)
1616
[![Build](https://img.shields.io/github/checks-status/parseablehq/parseable/main?style=flat&color=%2373DC8C&label=Checks)](https://github.com/parseablehq/parseable/actions)
1717

1818
[Key Concepts](https://www.parseable.io/docs/concepts) | [Features](https://github.com/parseablehq/parseable#rocket-highlights) | [Documentation](https://www.parseable.io/docs) | [Demo](https://demo.parseable.com/login?q=eyJ1c2VybmFtZSI6ImFkbWluIiwicGFzc3dvcmQiOiJhZG1pbiJ9) | [Integrations](https://www.parseable.io/docs/category/integrations) | [FAQ](https://www.parseable.io/docs/faq)

server/src/about.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn print_about(
104104
eprintln!(
105105
"
106106
Commit: \"{commit_hash}\"
107-
Docs: \"https://www.parseable.io/docs\""
107+
Docs: \"https://logg.ing/docs\""
108108
);
109109
}
110110

server/src/option.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ use crate::oidc::{self, OpenidConfig};
3030
use crate::storage::{FSConfig, ObjectStorageError, ObjectStorageProvider, S3Config};
3131

3232
pub const MIN_CACHE_SIZE_BYTES: u64 = 1000u64.pow(3); // 1 GiB
33-
33+
pub const JOIN_COMMUNITY: &str =
34+
"Join us on Parseable Slack community for questions : https://logg.ing/community";
3435
pub static CONFIG: Lazy<Arc<Config>> = Lazy::new(|| Arc::new(Config::new()));
3536

3637
#[derive(Debug)]
@@ -104,30 +105,25 @@ impl Config {
104105

105106
let has_parseable_json = obj_store.get_object(&rel_path).await.is_ok();
106107

107-
let has_dirs = match obj_store.list_dirs_in_storage().await {
108+
// Lists all the directories in the root of the bucket/directory
109+
// can be a stream (if it contains .stream.json file) or not
110+
let has_dirs = match obj_store.list_dirs().await {
108111
Ok(dirs) => !dirs.is_empty(),
109112
Err(_) => false,
110113
};
111114

112115
let has_streams = obj_store.list_streams().await.is_ok();
113116

114-
if !has_dirs || has_parseable_json && has_streams {
115-
Ok(())
116-
} else if has_parseable_json && !has_streams {
117-
Err(ObjectStorageError::Custom(
118-
"Could not start the server because storage contains stale data from previous deployment, please choose an empty storage and restart the server.\nJoin us on Parseable Slack to report this incident : launchpass.com/parseable"
119-
.to_owned(),
120-
))
121-
} else if !has_parseable_json && !has_streams && has_dirs {
122-
Err(ObjectStorageError::Custom(
123-
"Could not start the server because storage contains some stale data, please provide an empty storage and restart the server.\nJoin us on Parseable Slack to report this incident : launchpass.com/parseable".to_owned(),
124-
))
125-
} else {
126-
Err(ObjectStorageError::Custom(
127-
"Could not start the server because storage contains stale data from previous deployment.\nJoin us on Parseable Slack to report this incident : launchpass.com/parseable"
128-
.to_owned()
129-
))
117+
if has_streams || !has_dirs && !has_parseable_json {
118+
return Ok(());
130119
}
120+
121+
if self.mode_string() == "Local drive" {
122+
return Err(ObjectStorageError::Custom(format!("Could not start the server because directory '{}' contains stale data, please use an empty directory, and restart the server.\n{}", self.storage.get_endpoint(), JOIN_COMMUNITY)));
123+
}
124+
125+
// S3 bucket mode
126+
Err(ObjectStorageError::Custom(format!("Could not start the server because bucket '{}' contains stale data, please use an empty bucket and restart the server.\n{}", self.storage.get_endpoint(), JOIN_COMMUNITY)))
131127
}
132128

133129
pub fn storage(&self) -> Arc<dyn ObjectStorageProvider + Send + Sync> {
@@ -185,7 +181,7 @@ fn parseable_cli_command() -> Command {
185181
.next_line_help(false)
186182
.help_template(
187183
r#"
188-
{about} Join the community at https://launchpass.com/parseable.
184+
{about} Join the community at https://logg.ing/community.
189185
190186
{all-args}
191187
"#,

server/src/storage/localfs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl ObjectStorage for LocalFS {
169169
Ok(logstreams)
170170
}
171171

172-
async fn list_dirs_in_storage(&self) -> Result<Vec<String>, ObjectStorageError> {
172+
async fn list_dirs(&self) -> Result<Vec<String>, ObjectStorageError> {
173173
let dirs = ReadDirStream::new(fs::read_dir(&self.root).await?)
174174
.try_collect::<Vec<DirEntry>>()
175175
.await?

server/src/storage/object_storage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub trait ObjectStorage: Sync + 'static {
7575
async fn check(&self) -> Result<(), ObjectStorageError>;
7676
async fn delete_stream(&self, stream_name: &str) -> Result<(), ObjectStorageError>;
7777
async fn list_streams(&self) -> Result<Vec<LogStream>, ObjectStorageError>;
78-
async fn list_dirs_in_storage(&self) -> Result<Vec<String>, ObjectStorageError>;
78+
async fn list_dirs(&self) -> Result<Vec<String>, ObjectStorageError>;
7979
async fn list_dates(&self, stream_name: &str) -> Result<Vec<String>, ObjectStorageError>;
8080
async fn upload_file(&self, key: &str, path: &Path) -> Result<(), ObjectStorageError>;
8181

server/src/storage/s3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ impl ObjectStorage for S3 {
471471
url::Url::parse(&format!("s3://{}", self.bucket)).unwrap()
472472
}
473473

474-
async fn list_dirs_in_storage(&self) -> Result<Vec<String>, ObjectStorageError> {
474+
async fn list_dirs(&self) -> Result<Vec<String>, ObjectStorageError> {
475475
let pre = object_store::path::Path::from("/");
476476
let resp = self.client.list_with_delimiter(Some(&pre)).await?;
477477

server/src/storage/store_metadata.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use once_cell::sync::OnceCell;
2626
use std::io;
2727

2828
use crate::{
29-
option::CONFIG,
29+
option::{CONFIG, JOIN_COMMUNITY},
3030
rbac::{role::model::DefaultPrivilege, user::User},
3131
storage::ObjectStorageError,
3232
utils::uid,
@@ -145,11 +145,7 @@ pub async fn resolve_parseable_metadata() -> Result<StorageMetadata, ObjectStora
145145
};
146146

147147
let metadata = res.map_err(|err| {
148-
let err = format!(
149-
"{}. {}",
150-
err,
151-
"Join us on Parseable Slack to report this incident : https://launchpass.com/parseable"
152-
);
148+
let err = format!("{}. {}", err, JOIN_COMMUNITY);
153149
let err: Box<dyn std::error::Error + Send + Sync + 'static> = err.into();
154150
ObjectStorageError::UnhandledError(err)
155151
})?;

0 commit comments

Comments
 (0)