@@ -34,7 +34,7 @@ use crate::localcache::CacheError;
3434use crate :: metadata:: error:: stream_info:: MetadataError ;
3535use crate :: metadata:: { self , STREAM_INFO } ;
3636use crate :: option:: { Mode , CONFIG } ;
37- use crate :: storage:: { LogStream , ObjectStorageError } ;
37+ use crate :: storage:: { LogStream , ObjectStorageError , StreamType } ;
3838use crate :: utils:: header_parsing:: { collect_labelled_headers, ParseHeaderError } ;
3939use crate :: utils:: json:: convert_array_to_object;
4040use actix_web:: { http:: header:: ContentType , HttpRequest , HttpResponse } ;
@@ -57,13 +57,15 @@ pub async fn ingest(req: HttpRequest, body: Bytes) -> Result<HttpResponse, PostE
5757 . find ( |& ( key, _) | key == STREAM_NAME_HEADER_KEY )
5858 {
5959 let stream_name = stream_name. to_str ( ) . unwrap ( ) . to_owned ( ) ;
60- if stream_name. eq ( INTERNAL_STREAM_NAME ) {
60+ let internal_stream_names = STREAM_INFO . list_internal_streams ( ) ;
61+
62+ if internal_stream_names. contains ( & stream_name) || stream_name == INTERNAL_STREAM_NAME {
6163 return Err ( PostError :: Invalid ( anyhow:: anyhow!(
62- "Stream {} is an internal stream and cannot be ingested into" ,
64+ "The stream {} is reserved for internal use and cannot be ingested into" ,
6365 stream_name
6466 ) ) ) ;
6567 }
66- create_stream_if_not_exists ( & stream_name, false ) . await ?;
68+ create_stream_if_not_exists ( & stream_name, StreamType :: UserDefined ) . await ?;
6769
6870 flatten_and_push_logs ( req, body, stream_name) . await ?;
6971 Ok ( HttpResponse :: Ok ( ) . finish ( ) )
@@ -73,7 +75,7 @@ pub async fn ingest(req: HttpRequest, body: Bytes) -> Result<HttpResponse, PostE
7375}
7476
7577pub async fn ingest_internal_stream ( stream_name : String , body : Bytes ) -> Result < ( ) , PostError > {
76- create_stream_if_not_exists ( & stream_name, true ) . await ?;
78+ create_stream_if_not_exists ( & stream_name, StreamType :: Internal ) . await ?;
7779 let size: usize = body. len ( ) ;
7880 let parsed_timestamp = Utc :: now ( ) . naive_utc ( ) ;
7981 let ( rb, is_first) = {
@@ -100,6 +102,7 @@ pub async fn ingest_internal_stream(stream_name: String, body: Bytes) -> Result<
100102 parsed_timestamp,
101103 time_partition : None ,
102104 custom_partition_values : HashMap :: new ( ) ,
105+ stream_type : StreamType :: Internal ,
103106 }
104107 . process ( )
105108 . await ?;
@@ -116,7 +119,7 @@ pub async fn ingest_otel_logs(req: HttpRequest, body: Bytes) -> Result<HttpRespo
116119 . find ( |& ( key, _) | key == STREAM_NAME_HEADER_KEY )
117120 {
118121 let stream_name = stream_name. to_str ( ) . unwrap ( ) . to_owned ( ) ;
119- create_stream_if_not_exists ( & stream_name, false ) . await ?;
122+ create_stream_if_not_exists ( & stream_name, StreamType :: UserDefined ) . await ?;
120123
121124 //flatten logs
122125 if let Some ( ( _, log_source) ) = req. headers ( ) . iter ( ) . find ( |& ( key, _) | key == LOG_SOURCE_KEY )
@@ -176,7 +179,8 @@ async fn flatten_and_push_logs(
176179// fails if the logstream does not exist
177180pub async fn post_event ( req : HttpRequest , body : Bytes ) -> Result < HttpResponse , PostError > {
178181 let stream_name: String = req. match_info ( ) . get ( "logstream" ) . unwrap ( ) . parse ( ) . unwrap ( ) ;
179- if stream_name. eq ( INTERNAL_STREAM_NAME ) {
182+ let internal_stream_names = STREAM_INFO . list_internal_streams ( ) ;
183+ if internal_stream_names. contains ( & stream_name) || stream_name == INTERNAL_STREAM_NAME {
180184 return Err ( PostError :: Invalid ( anyhow:: anyhow!(
181185 "Stream {} is an internal stream and cannot be ingested into" ,
182186 stream_name
@@ -202,6 +206,7 @@ pub async fn push_logs_unchecked(
202206 time_partition : None ,
203207 is_first_event : true , // NOTE: Maybe should be false
204208 custom_partition_values : HashMap :: new ( ) , // should be an empty map for unchecked push
209+ stream_type : StreamType :: UserDefined ,
205210 } ;
206211 unchecked_event. process_unchecked ( ) ?;
207212
@@ -369,6 +374,7 @@ async fn create_process_record_batch(
369374 parsed_timestamp,
370375 time_partition : time_partition. clone ( ) ,
371376 custom_partition_values : custom_partition_values. clone ( ) ,
377+ stream_type : StreamType :: UserDefined ,
372378 }
373379 . process ( )
374380 . await ?;
@@ -413,7 +419,7 @@ fn into_event_batch(
413419// Check if the stream exists and create a new stream if doesn't exist
414420pub async fn create_stream_if_not_exists (
415421 stream_name : & str ,
416- internal_stream : bool ,
422+ stream_type : StreamType ,
417423) -> Result < ( ) , PostError > {
418424 if STREAM_INFO . stream_exists ( stream_name) {
419425 return Ok ( ( ) ) ;
@@ -427,7 +433,7 @@ pub async fn create_stream_if_not_exists(
427433 "" ,
428434 "" ,
429435 Arc :: new ( Schema :: empty ( ) ) ,
430- internal_stream ,
436+ stream_type ,
431437 )
432438 . await ?;
433439 }
0 commit comments