@@ -20,8 +20,8 @@ use self::error::{CreateStreamError, StreamError};
2020use super :: base_path_without_preceding_slash;
2121use super :: cluster:: utils:: { merge_quried_stats, IngestionStats , QueriedStats , StorageStats } ;
2222use super :: cluster:: {
23- fetch_daily_stats_from_ingestors, fetch_stats_from_ingestors,
24- sync_internal_streams_with_ingestors , sync_streams_with_ingestors , INTERNAL_STREAM_NAME ,
23+ fetch_daily_stats_from_ingestors, fetch_stats_from_ingestors, sync_streams_with_ingestors ,
24+ INTERNAL_STREAM_NAME ,
2525} ;
2626use super :: ingest:: create_stream_if_not_exists;
2727use crate :: alerts:: Alerts ;
@@ -44,16 +44,19 @@ use crate::{
4444} ;
4545
4646use crate :: { metadata, validator} ;
47+ use actix_web:: http:: header:: { self , HeaderMap } ;
4748use actix_web:: http:: StatusCode ;
4849use actix_web:: { web, HttpRequest , Responder } ;
4950use arrow_schema:: { Field , Schema } ;
5051use bytes:: Bytes ;
5152use chrono:: Utc ;
53+ use http:: { HeaderName , HeaderValue } ;
5254use itertools:: Itertools ;
5355use serde_json:: Value ;
5456use std:: collections:: HashMap ;
5557use std:: fs;
5658use std:: num:: NonZeroU32 ;
59+ use std:: str:: FromStr ;
5760use std:: sync:: Arc ;
5861
5962pub async fn delete ( req : HttpRequest ) -> Result < impl Responder , StreamError > {
@@ -179,12 +182,9 @@ pub async fn put_stream(req: HttpRequest, body: Bytes) -> Result<impl Responder,
179182 let stream_name: String = req. match_info ( ) . get ( "logstream" ) . unwrap ( ) . parse ( ) . unwrap ( ) ;
180183
181184 if CONFIG . parseable . mode == Mode :: Query {
182- create_update_stream ( & req, & body, & stream_name) . await ?;
183- sync_streams_with_ingestors ( req , body, & stream_name) . await ?;
185+ let headers = create_update_stream ( & req, & body, & stream_name) . await ?;
186+ sync_streams_with_ingestors ( headers , body, & stream_name) . await ?;
184187 } else {
185- if STREAM_INFO . stream_exists ( & stream_name) {
186- return Ok ( ( "Log stream already exists" , StatusCode :: OK ) ) ;
187- }
188188 create_update_stream ( & req, & body, & stream_name) . await ?;
189189 }
190190
@@ -314,7 +314,7 @@ async fn create_update_stream(
314314 req : & HttpRequest ,
315315 body : & Bytes ,
316316 stream_name : & str ,
317- ) -> Result < ( ) , StreamError > {
317+ ) -> Result < HeaderMap , StreamError > {
318318 let (
319319 time_partition,
320320 time_partition_limit,
@@ -355,17 +355,16 @@ async fn create_update_stream(
355355 let time_partition_days = validate_time_partition_limit ( & time_partition_limit) ?;
356356 update_time_partition_limit_in_stream ( stream_name. to_string ( ) , time_partition_days)
357357 . await ?;
358- return Ok ( ( ) ) ;
358+ return Ok ( req . headers ( ) . clone ( ) ) ;
359359 }
360360
361361 if !custom_partition. is_empty ( ) {
362362 validate_custom_partition ( & custom_partition) ?;
363363 update_custom_partition_in_stream ( stream_name. to_string ( ) , & custom_partition) . await ?;
364- return Ok ( ( ) ) ;
365364 } else {
366365 update_custom_partition_in_stream ( stream_name. to_string ( ) , "" ) . await ?;
367- return Ok ( ( ) ) ;
368366 }
367+ return Ok ( req. headers ( ) . clone ( ) ) ;
369368 }
370369 let mut time_partition_in_days = "" ;
371370 if !time_partition_limit. is_empty ( ) {
@@ -398,7 +397,7 @@ async fn create_update_stream(
398397 )
399398 . await ?;
400399
401- Ok ( ( ) )
400+ Ok ( req . headers ( ) . clone ( ) )
402401}
403402pub async fn put_alert (
404403 req : HttpRequest ,
@@ -1066,7 +1065,16 @@ pub async fn create_internal_stream_if_not_exists() -> Result<(), StreamError> {
10661065 . await
10671066 . is_ok ( )
10681067 {
1069- sync_internal_streams_with_ingestors ( INTERNAL_STREAM_NAME ) . await ?;
1068+ let mut header_map = HeaderMap :: new ( ) ;
1069+ header_map. insert (
1070+ HeaderName :: from_str ( STREAM_TYPE_KEY ) . unwrap ( ) ,
1071+ HeaderValue :: from_str ( & StreamType :: Internal . to_string ( ) ) . unwrap ( ) ,
1072+ ) ;
1073+ header_map. insert (
1074+ header:: CONTENT_TYPE ,
1075+ HeaderValue :: from_static ( "application/json" ) ,
1076+ ) ;
1077+ sync_streams_with_ingestors ( header_map, Bytes :: new ( ) , INTERNAL_STREAM_NAME ) . await ?;
10701078 }
10711079 Ok ( ( ) )
10721080}
0 commit comments