@@ -20,16 +20,14 @@ use super::logstream::error::{CreateStreamError, StreamError};
20
20
use super :: modal:: utils:: ingest_utils:: { flatten_and_push_logs, push_logs} ;
21
21
use super :: users:: dashboards:: DashboardError ;
22
22
use super :: users:: filters:: FiltersError ;
23
+ use crate :: event:: format:: LogSource ;
23
24
use crate :: event:: {
24
25
self ,
25
26
error:: EventError ,
26
27
format:: { self , EventFormat } ,
27
28
} ;
28
29
use crate :: handlers:: http:: modal:: utils:: logstream_utils:: create_stream_and_schema_from_storage;
29
- use crate :: handlers:: {
30
- LOG_SOURCE_KEY , LOG_SOURCE_OTEL_LOGS , LOG_SOURCE_OTEL_METRICS , LOG_SOURCE_OTEL_TRACES ,
31
- STREAM_NAME_HEADER_KEY ,
32
- } ;
30
+ use crate :: handlers:: { LOG_SOURCE_KEY , STREAM_NAME_HEADER_KEY } ;
33
31
use crate :: metadata:: error:: stream_info:: MetadataError ;
34
32
use crate :: metadata:: { SchemaVersion , STREAM_INFO } ;
35
33
use crate :: option:: { Mode , CONFIG } ;
@@ -95,7 +93,7 @@ pub async fn ingest_internal_stream(stream_name: String, body: Bytes) -> Result<
95
93
metadata : String :: default ( ) ,
96
94
} ;
97
95
// For internal streams, use old schema
98
- event. into_recordbatch ( & schema, None , None , SchemaVersion :: V0 , "" ) ?
96
+ event. into_recordbatch ( & schema, None , None , SchemaVersion :: V0 , & LogSource :: default ( ) ) ?
99
97
} ;
100
98
event:: Event {
101
99
rb,
@@ -127,8 +125,8 @@ pub async fn handle_otel_logs_ingestion(
127
125
let Some ( log_source) = req. headers ( ) . get ( LOG_SOURCE_KEY ) else {
128
126
return Err ( PostError :: Header ( ParseHeaderError :: MissingLogSource ) ) ;
129
127
} ;
130
- let log_source = log_source. to_str ( ) . unwrap ( ) ;
131
- if log_source != LOG_SOURCE_OTEL_LOGS {
128
+ let log_source = LogSource :: from ( log_source. to_str ( ) . unwrap ( ) ) ;
129
+ if log_source != LogSource :: OtelLogs {
132
130
return Err ( PostError :: Invalid ( anyhow:: anyhow!(
133
131
"Please use x-p-log-source: otel-logs for ingesting otel logs"
134
132
) ) ) ;
@@ -142,7 +140,7 @@ pub async fn handle_otel_logs_ingestion(
142
140
let mut json = flatten_otel_logs ( & logs) ;
143
141
for record in json. iter_mut ( ) {
144
142
let body: Bytes = serde_json:: to_vec ( record) . unwrap ( ) . into ( ) ;
145
- push_logs ( & stream_name, & req, & body, log_source) . await ?;
143
+ push_logs ( & stream_name, & req, & body, & log_source) . await ?;
146
144
}
147
145
148
146
Ok ( HttpResponse :: Ok ( ) . finish ( ) )
@@ -161,8 +159,8 @@ pub async fn handle_otel_metrics_ingestion(
161
159
let Some ( log_source) = req. headers ( ) . get ( LOG_SOURCE_KEY ) else {
162
160
return Err ( PostError :: Header ( ParseHeaderError :: MissingLogSource ) ) ;
163
161
} ;
164
- let log_source = log_source. to_str ( ) . unwrap ( ) ;
165
- if log_source != LOG_SOURCE_OTEL_METRICS {
162
+ let log_source = LogSource :: from ( log_source. to_str ( ) . unwrap ( ) ) ;
163
+ if log_source != LogSource :: OtelMetrics {
166
164
return Err ( PostError :: Invalid ( anyhow:: anyhow!(
167
165
"Please use x-p-log-source: otel-metrics for ingesting otel metrics"
168
166
) ) ) ;
@@ -175,7 +173,7 @@ pub async fn handle_otel_metrics_ingestion(
175
173
let mut json = flatten_otel_metrics ( metrics) ;
176
174
for record in json. iter_mut ( ) {
177
175
let body: Bytes = serde_json:: to_vec ( record) . unwrap ( ) . into ( ) ;
178
- push_logs ( & stream_name, & req, & body, log_source) . await ?;
176
+ push_logs ( & stream_name, & req, & body, & log_source) . await ?;
179
177
}
180
178
181
179
Ok ( HttpResponse :: Ok ( ) . finish ( ) )
@@ -195,8 +193,8 @@ pub async fn handle_otel_traces_ingestion(
195
193
let Some ( log_source) = req. headers ( ) . get ( LOG_SOURCE_KEY ) else {
196
194
return Err ( PostError :: Header ( ParseHeaderError :: MissingLogSource ) ) ;
197
195
} ;
198
- let log_source = log_source. to_str ( ) . unwrap ( ) ;
199
- if log_source != LOG_SOURCE_OTEL_TRACES {
196
+ let log_source = LogSource :: from ( log_source. to_str ( ) . unwrap ( ) ) ;
197
+ if log_source != LogSource :: OtelTraces {
200
198
return Err ( PostError :: Invalid ( anyhow:: anyhow!(
201
199
"Please use x-p-log-source: otel-traces for ingesting otel traces"
202
200
) ) ) ;
@@ -209,7 +207,7 @@ pub async fn handle_otel_traces_ingestion(
209
207
let mut json = flatten_otel_traces ( & traces) ;
210
208
for record in json. iter_mut ( ) {
211
209
let body: Bytes = serde_json:: to_vec ( record) . unwrap ( ) . into ( ) ;
212
- push_logs ( & stream_name, & req, & body, log_source) . await ?;
210
+ push_logs ( & stream_name, & req, & body, & log_source) . await ?;
213
211
}
214
212
215
213
Ok ( HttpResponse :: Ok ( ) . finish ( ) )
@@ -371,7 +369,7 @@ mod tests {
371
369
use serde_json:: json;
372
370
373
371
use crate :: {
374
- event,
372
+ event:: { self , format :: LogSource } ,
375
373
handlers:: { http:: modal:: utils:: ingest_utils:: into_event_batch, PREFIX_META , PREFIX_TAGS } ,
376
374
metadata:: SchemaVersion ,
377
375
} ;
@@ -420,7 +418,7 @@ mod tests {
420
418
None ,
421
419
None ,
422
420
SchemaVersion :: V0 ,
423
- "" ,
421
+ & LogSource :: default ( ) ,
424
422
)
425
423
. unwrap ( ) ;
426
424
@@ -471,7 +469,7 @@ mod tests {
471
469
None ,
472
470
None ,
473
471
SchemaVersion :: V0 ,
474
- "" ,
472
+ & LogSource :: default ( ) ,
475
473
)
476
474
. unwrap ( ) ;
477
475
@@ -505,8 +503,16 @@ mod tests {
505
503
506
504
let req = TestRequest :: default ( ) . to_http_request ( ) ;
507
505
508
- let ( rb, _) =
509
- into_event_batch ( & req, & json, schema, None , None , SchemaVersion :: V0 , "" ) . unwrap ( ) ;
506
+ let ( rb, _) = into_event_batch (
507
+ & req,
508
+ & json,
509
+ schema,
510
+ None ,
511
+ None ,
512
+ SchemaVersion :: V0 ,
513
+ & LogSource :: default ( ) ,
514
+ )
515
+ . unwrap ( ) ;
510
516
511
517
assert_eq ! ( rb. num_rows( ) , 1 ) ;
512
518
assert_eq ! ( rb. num_columns( ) , 5 ) ;
@@ -538,7 +544,16 @@ mod tests {
538
544
539
545
let req = TestRequest :: default ( ) . to_http_request ( ) ;
540
546
541
- assert ! ( into_event_batch( & req, & json, schema, None , None , SchemaVersion :: V0 , "" ) . is_err( ) ) ;
547
+ assert ! ( into_event_batch(
548
+ & req,
549
+ & json,
550
+ schema,
551
+ None ,
552
+ None ,
553
+ SchemaVersion :: V0 ,
554
+ & LogSource :: default ( )
555
+ )
556
+ . is_err( ) ) ;
542
557
}
543
558
544
559
#[ test]
@@ -556,8 +571,16 @@ mod tests {
556
571
557
572
let req = TestRequest :: default ( ) . to_http_request ( ) ;
558
573
559
- let ( rb, _) =
560
- into_event_batch ( & req, & json, schema, None , None , SchemaVersion :: V0 , "" ) . unwrap ( ) ;
574
+ let ( rb, _) = into_event_batch (
575
+ & req,
576
+ & json,
577
+ schema,
578
+ None ,
579
+ None ,
580
+ SchemaVersion :: V0 ,
581
+ & LogSource :: default ( ) ,
582
+ )
583
+ . unwrap ( ) ;
561
584
562
585
assert_eq ! ( rb. num_rows( ) , 1 ) ;
563
586
assert_eq ! ( rb. num_columns( ) , 3 ) ;
@@ -576,7 +599,7 @@ mod tests {
576
599
None ,
577
600
None ,
578
601
SchemaVersion :: V0 ,
579
- ""
602
+ & LogSource :: default ( )
580
603
)
581
604
. is_err( ) )
582
605
}
@@ -608,7 +631,7 @@ mod tests {
608
631
None ,
609
632
None ,
610
633
SchemaVersion :: V0 ,
611
- "" ,
634
+ & LogSource :: default ( ) ,
612
635
)
613
636
. unwrap ( ) ;
614
637
@@ -665,7 +688,7 @@ mod tests {
665
688
None ,
666
689
None ,
667
690
SchemaVersion :: V0 ,
668
- "" ,
691
+ & LogSource :: default ( ) ,
669
692
)
670
693
. unwrap ( ) ;
671
694
@@ -715,8 +738,16 @@ mod tests {
715
738
) ;
716
739
let req = TestRequest :: default ( ) . to_http_request ( ) ;
717
740
718
- let ( rb, _) =
719
- into_event_batch ( & req, & json, schema, None , None , SchemaVersion :: V0 , "" ) . unwrap ( ) ;
741
+ let ( rb, _) = into_event_batch (
742
+ & req,
743
+ & json,
744
+ schema,
745
+ None ,
746
+ None ,
747
+ SchemaVersion :: V0 ,
748
+ & LogSource :: default ( ) ,
749
+ )
750
+ . unwrap ( ) ;
720
751
721
752
assert_eq ! ( rb. num_rows( ) , 3 ) ;
722
753
assert_eq ! ( rb. num_columns( ) , 6 ) ;
@@ -765,7 +796,16 @@ mod tests {
765
796
. into_iter ( ) ,
766
797
) ;
767
798
768
- assert ! ( into_event_batch( & req, & json, schema, None , None , SchemaVersion :: V0 , "" ) . is_err( ) ) ;
799
+ assert ! ( into_event_batch(
800
+ & req,
801
+ & json,
802
+ schema,
803
+ None ,
804
+ None ,
805
+ SchemaVersion :: V0 ,
806
+ & LogSource :: default ( )
807
+ )
808
+ . is_err( ) ) ;
769
809
}
770
810
771
811
#[ test]
@@ -800,7 +840,7 @@ mod tests {
800
840
None ,
801
841
None ,
802
842
SchemaVersion :: V0 ,
803
- "" ,
843
+ & LogSource :: default ( ) ,
804
844
)
805
845
. unwrap ( ) ;
806
846
@@ -881,7 +921,7 @@ mod tests {
881
921
None ,
882
922
None ,
883
923
SchemaVersion :: V1 ,
884
- "" ,
924
+ & LogSource :: default ( ) ,
885
925
)
886
926
. unwrap ( ) ;
887
927
0 commit comments