1818
1919use std:: collections:: HashMap ;
2020
21- use actix_web:: web:: { Json , Path } ;
21+ use actix_web:: web:: Path ;
2222use actix_web:: { http:: header:: ContentType , HttpRequest , HttpResponse } ;
2323use arrow_array:: RecordBatch ;
24- use bytes:: Bytes ;
2524use chrono:: Utc ;
2625use http:: StatusCode ;
2726use serde_json:: Value ;
@@ -36,14 +35,18 @@ use crate::storage::{ObjectStorageError, StreamType};
3635use crate :: utils:: header_parsing:: ParseHeaderError ;
3736use crate :: utils:: json:: flatten:: JsonFlattenError ;
3837
38+ use super :: cluster:: utils:: JsonWithSize ;
3939use super :: logstream:: error:: { CreateStreamError , StreamError } ;
4040use super :: users:: dashboards:: DashboardError ;
4141use super :: users:: filters:: FiltersError ;
4242
4343// Handler for POST /api/v1/ingest
4444// ingests events by extracting stream name from header
4545// creates if stream does not exist
46- pub async fn ingest ( req : HttpRequest , Json ( json) : Json < Value > ) -> Result < HttpResponse , PostError > {
46+ pub async fn ingest (
47+ req : HttpRequest ,
48+ JsonWithSize { json, byte_size } : JsonWithSize < Value > ,
49+ ) -> Result < HttpResponse , PostError > {
4750 let Some ( stream_name) = req. headers ( ) . get ( STREAM_NAME_HEADER_KEY ) else {
4851 return Err ( PostError :: Header ( ParseHeaderError :: MissingStreamName ) ) ;
4952 } ;
@@ -72,29 +75,18 @@ pub async fn ingest(req: HttpRequest, Json(json): Json<Value>) -> Result<HttpRes
7275
7376 PARSEABLE
7477 . get_or_create_stream ( & stream_name)
75- . push_logs ( json, & log_source)
78+ . push_logs ( json, byte_size , & log_source)
7679 . await ?;
7780
7881 Ok ( HttpResponse :: Ok ( ) . finish ( ) )
7982}
8083
81- pub async fn ingest_internal_stream ( stream_name : String , body : Bytes ) -> Result < ( ) , PostError > {
82- let json: Value = serde_json:: from_slice ( & body) ?;
83-
84- PARSEABLE
85- . get_stream ( & stream_name) ?
86- . push_logs ( json, & LogSource :: Pmeta )
87- . await ?;
88-
89- Ok ( ( ) )
90- }
91-
9284// Handler for POST /v1/logs to ingest OTEL logs
9385// ingests events by extracting stream name from header
9486// creates if stream does not exist
9587pub async fn handle_otel_logs_ingestion (
9688 req : HttpRequest ,
97- Json ( json) : Json < Value > ,
89+ JsonWithSize { json, byte_size } : JsonWithSize < Value > ,
9890) -> Result < HttpResponse , PostError > {
9991 let Some ( stream_name) = req. headers ( ) . get ( STREAM_NAME_HEADER_KEY ) else {
10092 return Err ( PostError :: Header ( ParseHeaderError :: MissingStreamName ) ) ;
@@ -115,7 +107,7 @@ pub async fn handle_otel_logs_ingestion(
115107
116108 PARSEABLE
117109 . get_or_create_stream ( & stream_name)
118- . push_logs ( json, & log_source)
110+ . push_logs ( json, byte_size , & log_source)
119111 . await ?;
120112
121113 Ok ( HttpResponse :: Ok ( ) . finish ( ) )
@@ -126,7 +118,7 @@ pub async fn handle_otel_logs_ingestion(
126118// creates if stream does not exist
127119pub async fn handle_otel_metrics_ingestion (
128120 req : HttpRequest ,
129- Json ( json) : Json < Value > ,
121+ JsonWithSize { json, byte_size } : JsonWithSize < Value > ,
130122) -> Result < HttpResponse , PostError > {
131123 let Some ( stream_name) = req. headers ( ) . get ( STREAM_NAME_HEADER_KEY ) else {
132124 return Err ( PostError :: Header ( ParseHeaderError :: MissingStreamName ) ) ;
@@ -149,7 +141,7 @@ pub async fn handle_otel_metrics_ingestion(
149141
150142 PARSEABLE
151143 . get_or_create_stream ( & stream_name)
152- . push_logs ( json, & log_source)
144+ . push_logs ( json, byte_size , & log_source)
153145 . await ?;
154146
155147 Ok ( HttpResponse :: Ok ( ) . finish ( ) )
@@ -160,7 +152,7 @@ pub async fn handle_otel_metrics_ingestion(
160152// creates if stream does not exist
161153pub async fn handle_otel_traces_ingestion (
162154 req : HttpRequest ,
163- Json ( json) : Json < Value > ,
155+ JsonWithSize { json, byte_size } : JsonWithSize < Value > ,
164156) -> Result < HttpResponse , PostError > {
165157 let Some ( stream_name) = req. headers ( ) . get ( STREAM_NAME_HEADER_KEY ) else {
166158 return Err ( PostError :: Header ( ParseHeaderError :: MissingStreamName ) ) ;
@@ -180,7 +172,7 @@ pub async fn handle_otel_traces_ingestion(
180172
181173 PARSEABLE
182174 . get_or_create_stream ( & stream_name)
183- . push_logs ( json, & log_source)
175+ . push_logs ( json, byte_size , & log_source)
184176 . await ?;
185177
186178 Ok ( HttpResponse :: Ok ( ) . finish ( ) )
@@ -192,7 +184,7 @@ pub async fn handle_otel_traces_ingestion(
192184pub async fn post_event (
193185 req : HttpRequest ,
194186 stream_name : Path < String > ,
195- Json ( json) : Json < Value > ,
187+ JsonWithSize { json, byte_size } : JsonWithSize < Value > ,
196188) -> Result < HttpResponse , PostError > {
197189 let stream_name = stream_name. into_inner ( ) ;
198190
@@ -232,7 +224,7 @@ pub async fn post_event(
232224
233225 PARSEABLE
234226 . get_or_create_stream ( & stream_name)
235- . push_logs ( json, & log_source)
227+ . push_logs ( json, byte_size , & log_source)
236228 . await ?;
237229
238230 Ok ( HttpResponse :: Ok ( ) . finish ( ) )
0 commit comments