1616 *
1717 */
1818
19- use clap:: builder:: ArgPredicate ;
2019use clap:: { Parser , Subcommand } ;
2120use crossterm:: style:: Stylize ;
22- use std:: path:: PathBuf ;
21+ use std:: path:: { Path , PathBuf } ;
2322use std:: sync:: Arc ;
2423
2524use crate :: banner;
@@ -35,29 +34,31 @@ lazy_static::lazy_static! {
3534
3635pub const USERNAME_ENV : & str = "P_USERNAME" ;
3736pub const PASSWORD_ENV : & str = "P_PASSWORD" ;
38- pub const DEFAULT_USERNAME : & str = "parseable" ;
39- pub const DEFAULT_PASSWORD : & str = "parseable" ;
4037
4138pub struct Config {
4239 pub parseable : Server ,
40+ storage : Arc < dyn ObjectStorageProvider + Send + Sync > ,
4341}
4442
4543impl Config {
4644 fn new ( ) -> Self {
47- let Cli :: Server ( args) = match Cli :: try_parse ( ) {
48- Ok ( s) => s,
49- Err ( e) => {
50- e. exit ( ) ;
51- }
52- } ;
53- Config { parseable : args }
45+ let cli = Cli :: parse ( ) ;
46+ match cli. command {
47+ SubCmd :: ServerS3 { server, storage } => Config {
48+ parseable : server,
49+ storage : Arc :: new ( storage) ,
50+ } ,
51+ SubCmd :: ServerDrive { server, storage } => Config {
52+ parseable : server,
53+ storage : Arc :: new ( storage) ,
54+ } ,
55+ }
5456 }
5557
5658 pub fn print ( & self ) {
5759 let scheme = CONFIG . parseable . get_scheme ( ) ;
5860 self . status_info ( & scheme) ;
5961 banner:: version:: print ( ) ;
60- self . demo ( ) ;
6162 self . storage_info ( ) ;
6263 banner:: system_info ( ) ;
6364 println ! ( ) ;
@@ -107,30 +108,23 @@ impl Config {
107108 Local Data Path: {}
108109 Object Storage: {}" ,
109110 "Storage:" . to_string( ) . blue( ) . bold( ) ,
110- self . parseable . local_disk_path . to_string_lossy( ) ,
111- self . parseable . object_store . get_endpoint( ) ,
111+ self . staging_dir ( ) . to_string_lossy( ) ,
112+ self . storage ( ) . get_endpoint( ) ,
112113 )
113114 }
114115
115- fn demo ( & self ) {
116- if self . is_demo ( ) {
117- banner:: warning_line ( ) ;
118- eprintln ! (
119- "
120- {}" ,
121- "Parseable is in demo mode with default credentials and open object store. Please use this for demo purposes only."
122- . to_string( )
123- . red( ) ,
124- )
125- }
116+ pub fn storage ( & self ) -> Arc < dyn ObjectStorageProvider + Send + Sync > {
117+ self . storage . clone ( )
126118 }
127119
128- fn is_demo ( & self ) -> bool {
129- self . parseable . demo
120+ pub fn staging_dir ( & self ) -> & Path {
121+ & self . parseable . local_staging_path
130122 }
123+ }
131124
132- pub fn storage ( & self ) -> & impl ObjectStorageProvider {
133- & self . parseable . object_store
125+ impl Default for Config {
126+ fn default ( ) -> Self {
127+ Self :: new ( )
134128 }
135129}
136130
@@ -141,8 +135,27 @@ impl Config {
141135 about = "Parseable is a log storage and observability platform." ,
142136 version
143137) ]
144- enum Cli {
145- Server ( Server ) ,
138+ struct Cli {
139+ #[ command( subcommand) ]
140+ command : SubCmd ,
141+ }
142+
143+ #[ derive( Subcommand , Clone ) ]
144+ enum SubCmd {
145+ #[ command( name = "--s3" ) ]
146+ ServerS3 {
147+ #[ command( flatten) ]
148+ server : Server ,
149+ #[ command( flatten) ]
150+ storage : S3Config ,
151+ } ,
152+ #[ command( name = "--drive" ) ]
153+ ServerDrive {
154+ #[ command( flatten) ]
155+ server : Server ,
156+ #[ command( flatten) ]
157+ storage : FSConfig ,
158+ } ,
146159}
147160
148161#[ derive( clap:: Args , Debug , Clone ) ]
@@ -175,19 +188,18 @@ pub struct Server {
175188 ) ]
176189 pub address : String ,
177190
178- /// The local storage path is used as temporary landing point
179- /// for incoming events and local cache while querying data pulled
180- /// from object storage backend
191+ /// The local staging path is used as a temporary landing point
192+ /// for incoming events and local cache
181193 #[ arg(
182194 long,
183- env = "P_LOCAL_STORAGE " ,
195+ env = "P_STAGING_DIR " ,
184196 default_value = "./data" ,
185197 value_name = "path"
186198 ) ]
187- pub local_disk_path : PathBuf ,
199+ pub local_staging_path : PathBuf ,
188200
189- /// Optional interval after which server would upload uncommited data to
190- /// remote object storage platform. Defaults to 1min .
201+ /// Interval in seconds after which uncommited data would be
202+ /// uploaded to the storage platform.
191203 #[ arg(
192204 long,
193205 env = "P_STORAGE_UPLOAD_INTERVAL" ,
@@ -196,64 +208,26 @@ pub struct Server {
196208 ) ]
197209 pub upload_interval : u64 ,
198210
199- /// Optional username to enable basic auth on the server
211+ /// Username for the basic authentication on the server
200212 #[ arg(
201213 long,
202214 env = USERNAME_ENV ,
203215 value_name = "username" ,
204- default_value_if( "demo" , ArgPredicate :: IsPresent , DEFAULT_USERNAME )
205216 ) ]
206217 pub username : String ,
207218
208- /// Optional password to enable basic auth on the server
219+ /// Password for the basic authentication on the server
209220 #[ arg(
210221 long,
211222 env = PASSWORD_ENV ,
212223 value_name = "password" ,
213- default_value_if( "demo" , ArgPredicate :: IsPresent , DEFAULT_PASSWORD )
214224 ) ]
215225 pub password : String ,
216-
217- #[ command( subcommand) ]
218- pub object_store : ObjectStore ,
219-
220- /// Run Parseable in demo mode with default credentials and open object store
221- #[ arg( short, long, exclusive = true ) ]
222- pub demo : bool ,
223- }
224-
225- #[ derive( Debug , Clone , Subcommand ) ]
226- pub enum ObjectStore {
227- Drive ( FSConfig ) ,
228- S3 ( S3Config ) ,
229- }
230-
231- impl ObjectStorageProvider for ObjectStore {
232- fn get_datafusion_runtime ( & self ) -> Arc < datafusion:: execution:: runtime_env:: RuntimeEnv > {
233- match self {
234- ObjectStore :: Drive ( x) => x. get_datafusion_runtime ( ) ,
235- ObjectStore :: S3 ( x) => x. get_datafusion_runtime ( ) ,
236- }
237- }
238-
239- fn get_object_store ( & self ) -> Arc < dyn ObjectStorage + Send > {
240- match self {
241- ObjectStore :: Drive ( x) => x. get_object_store ( ) ,
242- ObjectStore :: S3 ( x) => x. get_object_store ( ) ,
243- }
244- }
245-
246- fn get_endpoint ( & self ) -> String {
247- match self {
248- ObjectStore :: Drive ( x) => x. get_endpoint ( ) ,
249- ObjectStore :: S3 ( x) => x. get_endpoint ( ) ,
250- }
251- }
252226}
253227
254228impl Server {
255229 pub fn local_stream_data_path ( & self , stream_name : & str ) -> PathBuf {
256- self . local_disk_path . join ( stream_name)
230+ self . local_staging_path . join ( stream_name)
257231 }
258232
259233 pub fn get_scheme ( & self ) -> String {
0 commit comments