@@ -21,6 +21,10 @@ use std::{
21
21
} ,
22
22
} ;
23
23
24
+ use :: log_streaming:: {
25
+ LogManager ,
26
+ LogManagerClient ,
27
+ } ;
24
28
use airbyte_import:: {
25
29
AirbyteRecord ,
26
30
PrimaryKey ,
@@ -74,7 +78,10 @@ use common::{
74
78
report_error,
75
79
JsError ,
76
80
} ,
77
- http:: RequestDestination ,
81
+ http:: {
82
+ fetch:: FetchClient ,
83
+ RequestDestination ,
84
+ } ,
78
85
knobs:: {
79
86
APPLICATION_MAX_CONCURRENT_UPLOADS ,
80
87
MAX_JOBS_CANCEL_BATCH ,
@@ -191,6 +198,7 @@ use keybroker::{
191
198
Identity ,
192
199
KeyBroker ,
193
200
} ;
201
+ use log_streaming:: add_local_log_sink_on_startup;
194
202
use maplit:: {
195
203
btreemap,
196
204
btreeset,
@@ -201,6 +209,7 @@ use model::{
201
209
AIRBYTE_PRIMARY_KEY_INDEX_DESCRIPTOR ,
202
210
} ,
203
211
auth:: AuthInfoModel ,
212
+ backend_info:: BackendInfoModel ,
204
213
backend_state:: BackendStateModel ,
205
214
canonical_urls:: {
206
215
types:: CanonicalUrl ,
@@ -389,6 +398,7 @@ pub mod cron_jobs;
389
398
pub mod deploy_config;
390
399
mod exports;
391
400
pub mod function_log;
401
+ mod log_streaming;
392
402
pub mod log_visibility;
393
403
mod metrics;
394
404
mod module_cache;
@@ -548,11 +558,11 @@ pub struct Application<RT: Runtime> {
548
558
export_worker : Arc < Mutex < Box < dyn SpawnHandle > > > ,
549
559
system_table_cleanup_worker : Arc < Mutex < Box < dyn SpawnHandle > > > ,
550
560
migration_worker : Arc < Mutex < Option < Box < dyn SpawnHandle > > > > ,
551
- log_sender : Arc < dyn LogSender > ,
552
561
log_visibility : Arc < dyn LogVisibility < RT > > ,
553
562
module_cache : ModuleCache < RT > ,
554
563
system_env_var_names : HashSet < EnvVarName > ,
555
564
app_auth : Arc < ApplicationAuth > ,
565
+ log_manager_client : LogManagerClient ,
556
566
}
557
567
558
568
impl < RT : Runtime > Clone for Application < RT > {
@@ -579,11 +589,11 @@ impl<RT: Runtime> Clone for Application<RT> {
579
589
export_worker : self . export_worker . clone ( ) ,
580
590
system_table_cleanup_worker : self . system_table_cleanup_worker . clone ( ) ,
581
591
migration_worker : self . migration_worker . clone ( ) ,
582
- log_sender : self . log_sender . clone ( ) ,
583
592
log_visibility : self . log_visibility . clone ( ) ,
584
593
module_cache : self . module_cache . clone ( ) ,
585
594
system_env_var_names : self . system_env_var_names . clone ( ) ,
586
595
app_auth : self . app_auth . clone ( ) ,
596
+ log_manager_client : self . log_manager_client . clone ( ) ,
587
597
}
588
598
}
589
599
}
@@ -671,10 +681,11 @@ impl<RT: Runtime> Application<RT> {
671
681
segment_term_metadata_fetcher : Arc < dyn SegmentTermMetadataFetcher > ,
672
682
persistence : Arc < dyn Persistence > ,
673
683
node_actions : Actions < RT > ,
674
- log_sender : Arc < dyn LogSender > ,
675
684
log_visibility : Arc < dyn LogVisibility < RT > > ,
676
685
app_auth : Arc < ApplicationAuth > ,
677
686
cache : QueryCache ,
687
+ fetch_client : Arc < dyn FetchClient > ,
688
+ local_log_sink : Option < String > ,
678
689
) -> anyhow:: Result < Self > {
679
690
let module_cache =
680
691
ModuleCache :: new ( runtime. clone ( ) , application_storage. modules_storage . clone ( ) ) . await ;
@@ -724,10 +735,32 @@ impl<RT: Runtime> Application<RT> {
724
735
runtime. spawn ( "system_table_cleanup_worker" , system_table_cleanup_worker) ,
725
736
) ) ;
726
737
738
+ // If local_log_sink is passed in, this is a local instance, so we enable log
739
+ // streaming by default. Otherwise, it's hard to grant the
740
+ // entitlement in testing and in load generator. If not local, we
741
+ // read the entitlement from the database.
742
+ let mut tx = database. begin ( Identity :: system ( ) ) . await ?;
743
+ let log_streaming_allowed = if let Some ( path) = local_log_sink {
744
+ add_local_log_sink_on_startup ( database. clone ( ) , path) . await ?;
745
+ true
746
+ } else {
747
+ let mut bi = BackendInfoModel :: new ( & mut tx) ;
748
+ bi. is_log_streaming_allowed ( ) . await ?
749
+ } ;
750
+
751
+ let log_manager_client = LogManager :: start (
752
+ runtime. clone ( ) ,
753
+ database. clone ( ) ,
754
+ fetch_client. clone ( ) ,
755
+ instance_name. clone ( ) ,
756
+ log_streaming_allowed,
757
+ )
758
+ . await ;
759
+
727
760
let function_log = FunctionExecutionLog :: new (
728
761
runtime. clone ( ) ,
729
762
database. usage_counter ( ) ,
730
- log_sender . clone ( ) ,
763
+ Arc :: new ( log_manager_client . clone ( ) ) ,
731
764
) ;
732
765
let runner = Arc :: new ( ApplicationFunctionRunner :: new (
733
766
runtime. clone ( ) ,
@@ -816,11 +849,11 @@ impl<RT: Runtime> Application<RT> {
816
849
snapshot_import_worker,
817
850
system_table_cleanup_worker,
818
851
migration_worker,
819
- log_sender,
820
852
log_visibility,
821
853
module_cache,
822
854
system_env_var_names : default_system_env_vars. into_keys ( ) . collect ( ) ,
823
855
app_auth,
856
+ log_manager_client,
824
857
} )
825
858
}
826
859
@@ -848,6 +881,10 @@ impl<RT: Runtime> Application<RT> {
848
881
self . function_log . clone ( )
849
882
}
850
883
884
+ pub fn log_manager_client ( & self ) -> & LogManagerClient {
885
+ & self . log_manager_client
886
+ }
887
+
851
888
pub fn now_ts_for_reads ( & self ) -> RepeatableTimestamp {
852
889
self . database . now_ts_for_reads ( )
853
890
}
@@ -2990,7 +3027,7 @@ impl<RT: Runtime> Application<RT> {
2990
3027
} )
2991
3028
. try_collect ( ) ?;
2992
3029
2993
- self . log_sender . send_logs ( logs) ;
3030
+ self . log_manager_client . send_logs ( logs) ;
2994
3031
Ok ( ts)
2995
3032
}
2996
3033
@@ -3088,7 +3125,7 @@ impl<RT: Runtime> Application<RT> {
3088
3125
} )
3089
3126
. try_collect ( ) ?;
3090
3127
3091
- self . log_sender . send_logs ( logs) ;
3128
+ self . log_manager_client . send_logs ( logs) ;
3092
3129
Ok ( ( t, stats) )
3093
3130
}
3094
3131
@@ -3439,7 +3476,7 @@ impl<RT: Runtime> Application<RT> {
3439
3476
}
3440
3477
3441
3478
pub async fn shutdown ( & self ) -> anyhow:: Result < ( ) > {
3442
- self . log_sender . shutdown ( ) ?;
3479
+ self . log_manager_client . shutdown ( ) ?;
3443
3480
self . table_summary_worker . shutdown ( ) . await ?;
3444
3481
self . system_table_cleanup_worker . lock ( ) . shutdown ( ) ;
3445
3482
self . schema_worker . lock ( ) . shutdown ( ) ;
0 commit comments