Skip to content

Commit 65e4b92

Browse files
committed
Add warning logs if config options are not specified; Add sample .env
1 parent 6cb274c commit 65e4b92

File tree

6 files changed

+41
-7
lines changed

6 files changed

+41
-7
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ DATABASE_NAME3=Enter-name-3-here
88

99
GRPC_SERVER_ROOT_PASSWORD=1234
1010
GRPC_SERVER_DIMENSION=3
11+
GRPC_SERVER_STORAGE_TYPE=rocksdb

crates/grpc_server/.env

Lines changed: 0 additions & 1 deletion
This file was deleted.

crates/grpc_server/.sample.env

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
GRPC_SERVER_ROOT_PASSWORD=123 // required
2+
GRPC_SERVER_DIMENSION=3 // required
3+
4+
GRPC_SERVER_HOST=localhost // defaults to 127.0.0.1 aka localhost
5+
GRPC_SERVER_PORT=8080 // defaults to 8080
6+
GRPC_SERVER_STORAGE_TYPE=inmemory // (inmemory/rocksdb) defaults to inmemory
7+
GRPC_SERVER_INDEX_TYPE=flat // defaults to flat
8+
GRPC_SERVER_DATA_PATH=data // defaults to a temporary directory
9+
GRPC_SERVER_LOGGING=true // defaults to true

crates/grpc_server/src/config.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::path::PathBuf;
1111
use std::{env, fs};
1212
use storage;
1313
use tempfile::tempdir;
14+
use tracing::{Level, event};
1415

1516
pub struct GRPCServerConfig {
1617
pub addr: SocketAddr,
@@ -24,10 +25,21 @@ impl GRPCServerConfig {
2425
dotenv().ok();
2526

2627
// fetch server host; default to localhost if not defined
27-
let host = env::var(constants::ENV_HOST).unwrap_or("127.0.0.1".to_string());
28+
let host = env::var(constants::ENV_HOST)
29+
.inspect_err(|_| {
30+
event!(Level::WARN, "Host not defined, defaulting to 'localhost'");
31+
})
32+
.unwrap_or("127.0.0.1".to_string());
2833

2934
// fetch server port; default to 8080 if not defined
3035
let port: u32 = env::var(ENV_PORT)
36+
.inspect_err(|_| {
37+
event!(
38+
Level::WARN,
39+
"Port not defined, defaulting to {}",
40+
DEFAULT_PORT
41+
);
42+
})
3143
.unwrap_or(DEFAULT_PORT.to_string())
3244
.parse()
3345
.unwrap();
@@ -38,7 +50,14 @@ impl GRPCServerConfig {
3850
})?;
3951

4052
// fetch server storage type
41-
let storage_type_str = env::var(ENV_STORAGE_TYPE).unwrap_or_default();
53+
let storage_type_str = env::var(ENV_STORAGE_TYPE)
54+
.inspect_err(|_| {
55+
event!(
56+
Level::WARN,
57+
"Storage Type not defined, defaulting to InMemory"
58+
)
59+
})
60+
.unwrap_or_default();
4261
let storage_type = match storage_type_str.as_str() {
4362
"inmemory" => storage::StorageType::InMemory,
4463
"rocksdb" => storage::StorageType::RocksDb,
@@ -47,6 +66,7 @@ impl GRPCServerConfig {
4766

4867
// fetch server index type
4968
let index_type_str = env::var(ENV_INDEX_TYPE)
69+
.inspect_err(|_| event!(Level::WARN, "Index Type not defined, defaulting to flat"))
5070
.unwrap_or("flat".to_string())
5171
.to_lowercase();
5272
let index_type = match index_type_str.as_str() {
@@ -69,7 +89,12 @@ impl GRPCServerConfig {
6989
fs::create_dir_all(&data_path).map_err(|_| errors::ConfigError::InvalidDataPath)?;
7090
} else {
7191
let tempbuf = tempdir().unwrap().path().to_path_buf().join("vectordb");
72-
fs::create_dir(&tempbuf);
92+
fs::create_dir_all(&tempbuf)?;
93+
event!(
94+
Level::WARN,
95+
"Data Path not specified, using temporary directory: {:?}",
96+
tempbuf.clone()
97+
);
7398
data_path = tempbuf;
7499
}
75100

crates/grpc_server/src/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ pub const ENV_LOGGING: &str = "GRPC_SERVER_LOGGING";
1111

1212
pub const DEFAULT_PORT: &str = "8080";
1313

14-
pub const SIMILARITY_PROTOBUF_MAP: [Similarity; 4] = [Euclidean, Manhattan, Hamming, Cosine];
14+
pub const SIMILARITY_PROTOBUFF_MAP: [Similarity; 4] = [Euclidean, Manhattan, Hamming, Cosine];

crates/grpc_server/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use api;
22
use defs;
33
use grpc_server::config::GRPCServerConfig;
4-
use grpc_server::constants::SIMILARITY_PROTOBUF_MAP;
4+
use grpc_server::constants::SIMILARITY_PROTOBUFF_MAP;
55
use grpc_server::interceptors;
66
use grpc_server::utils::log_rpc;
77
use std::panic;
@@ -93,7 +93,7 @@ impl VectorDb for VectorDBService {
9393

9494
// extract request arguments
9595
let query_vect = search_request.query_vector.unwrap();
96-
let similarity = SIMILARITY_PROTOBUF_MAP[search_request.similarity as usize];
96+
let similarity = SIMILARITY_PROTOBUFF_MAP[search_request.similarity as usize];
9797
let limit = search_request.limit;
9898

9999
let result_point_ids = self

0 commit comments

Comments
 (0)