@@ -26,7 +26,7 @@ use super::modal::utils::logstream_utils::{
2626use super :: query:: update_schema_when_distributed;
2727use crate :: alerts:: Alerts ;
2828use crate :: catalog:: get_first_event;
29- use crate :: event:: format:: override_data_type;
29+ use crate :: event:: format:: { override_data_type, LogSource } ;
3030use crate :: handlers:: STREAM_TYPE_KEY ;
3131use crate :: hottier:: { HotTierManager , StreamHotTier , CURRENT_HOT_TIER_VERSION } ;
3232use crate :: metadata:: { SchemaVersion , STREAM_INFO } ;
@@ -35,8 +35,8 @@ use crate::option::{Mode, CONFIG};
3535use crate :: rbac:: role:: Action ;
3636use crate :: rbac:: Users ;
3737use crate :: stats:: { event_labels_date, storage_size_labels_date, Stats } ;
38- use crate :: storage:: StreamType ;
39- use crate :: storage:: { retention :: Retention , StorageDir , StreamInfo } ;
38+ use crate :: storage:: { retention :: Retention , StorageDir } ;
39+ use crate :: storage:: { StreamInfo , StreamType } ;
4040use crate :: utils:: actix:: extract_session_key_from_req;
4141use crate :: { event, stats} ;
4242
@@ -484,6 +484,7 @@ fn remove_id_from_alerts(value: &mut Value) {
484484 }
485485}
486486
487+ #[ allow( clippy:: too_many_arguments) ]
487488pub async fn create_stream (
488489 stream_name : String ,
489490 time_partition : & str ,
@@ -492,6 +493,7 @@ pub async fn create_stream(
492493 static_schema_flag : bool ,
493494 schema : Arc < Schema > ,
494495 stream_type : & str ,
496+ log_source : LogSource ,
495497) -> Result < ( ) , CreateStreamError > {
496498 // fail to proceed if invalid stream name
497499 if stream_type != StreamType :: Internal . to_string ( ) {
@@ -509,6 +511,7 @@ pub async fn create_stream(
509511 static_schema_flag,
510512 schema. clone ( ) ,
511513 stream_type,
514+ log_source. clone ( ) ,
512515 )
513516 . await
514517 {
@@ -533,6 +536,7 @@ pub async fn create_stream(
533536 static_schema,
534537 stream_type,
535538 SchemaVersion :: V1 , // New stream
539+ log_source,
536540 ) ;
537541 }
538542 Err ( err) => {
@@ -583,6 +587,7 @@ pub async fn get_stream_info(req: HttpRequest) -> Result<impl Responder, StreamE
583587 . map ( |limit| limit. to_string ( ) ) ,
584588 custom_partition : stream_meta. custom_partition . clone ( ) ,
585589 static_schema_flag : stream_meta. static_schema_flag ,
590+ log_source : stream_meta. log_source . clone ( ) ,
586591 } ;
587592
588593 // get the other info from
@@ -725,8 +730,12 @@ pub async fn delete_stream_hot_tier(req: HttpRequest) -> Result<impl Responder,
725730}
726731
727732pub async fn create_internal_stream_if_not_exists ( ) -> Result < ( ) , StreamError > {
728- if let Ok ( stream_exists) =
729- create_stream_if_not_exists ( INTERNAL_STREAM_NAME , & StreamType :: Internal . to_string ( ) ) . await
733+ if let Ok ( stream_exists) = create_stream_if_not_exists (
734+ INTERNAL_STREAM_NAME ,
735+ & StreamType :: Internal . to_string ( ) ,
736+ LogSource :: Pmeta ,
737+ )
738+ . await
730739 {
731740 if stream_exists {
732741 return Ok ( ( ) ) ;
@@ -894,9 +903,9 @@ pub mod error {
894903mod tests {
895904 use crate :: handlers:: http:: logstream:: error:: StreamError ;
896905 use crate :: handlers:: http:: logstream:: get_stats;
906+ use crate :: handlers:: http:: modal:: utils:: logstream_utils:: fetch_headers_from_put_stream_request;
897907 use actix_web:: test:: TestRequest ;
898908 use anyhow:: bail;
899-
900909 #[ actix_web:: test]
901910 #[ should_panic]
902911 async fn get_stats_panics_without_logstream ( ) {
@@ -915,4 +924,41 @@ mod tests {
915924 _ => bail ! ( "expected StreamNotFound error" ) ,
916925 }
917926 }
927+
928+ #[ actix_web:: test]
929+ async fn header_without_log_source ( ) {
930+ let req = TestRequest :: default ( ) . to_http_request ( ) ;
931+ let ( _, _, _, _, _, _, log_source) = fetch_headers_from_put_stream_request ( & req) ;
932+ assert_eq ! ( log_source, crate :: event:: format:: LogSource :: Json ) ;
933+ }
934+
935+ #[ actix_web:: test]
936+ async fn header_with_known_log_source ( ) {
937+ let mut req = TestRequest :: default ( )
938+ . insert_header ( ( "X-P-Log-Source" , "pmeta" ) )
939+ . to_http_request ( ) ;
940+ let ( _, _, _, _, _, _, log_source) = fetch_headers_from_put_stream_request ( & req) ;
941+ assert_eq ! ( log_source, crate :: event:: format:: LogSource :: Pmeta ) ;
942+
943+ req = TestRequest :: default ( )
944+ . insert_header ( ( "X-P-Log-Source" , "otel-logs" ) )
945+ . to_http_request ( ) ;
946+ let ( _, _, _, _, _, _, log_source) = fetch_headers_from_put_stream_request ( & req) ;
947+ assert_eq ! ( log_source, crate :: event:: format:: LogSource :: OtelLogs ) ;
948+
949+ req = TestRequest :: default ( )
950+ . insert_header ( ( "X-P-Log-Source" , "kinesis" ) )
951+ . to_http_request ( ) ;
952+ let ( _, _, _, _, _, _, log_source) = fetch_headers_from_put_stream_request ( & req) ;
953+ assert_eq ! ( log_source, crate :: event:: format:: LogSource :: Kinesis ) ;
954+ }
955+
956+ #[ actix_web:: test]
957+ async fn header_with_unknown_log_source ( ) {
958+ let req = TestRequest :: default ( )
959+ . insert_header ( ( "X-P-Log-Source" , "teststream" ) )
960+ . to_http_request ( ) ;
961+ let ( _, _, _, _, _, _, log_source) = fetch_headers_from_put_stream_request ( & req) ;
962+ assert_eq ! ( log_source, crate :: event:: format:: LogSource :: Json ) ;
963+ }
918964}
0 commit comments