@@ -89,16 +89,32 @@ pub async fn ingest(
89
89
} ;
90
90
91
91
let log_source_entry = LogSourceEntry :: new ( log_source. clone ( ) , fields) ;
92
- let p_custom_fields = get_custom_fields_from_header ( req) ;
93
-
92
+
94
93
PARSEABLE
95
94
. create_stream_if_not_exists (
96
95
& stream_name,
97
96
StreamType :: UserDefined ,
98
- vec ! [ log_source_entry] ,
97
+ vec ! [ log_source_entry. clone ( ) ] ,
99
98
)
100
99
. await ?;
101
100
101
+ //if stream exists, fetch the stream log source
102
+ //return error if the stream log source is otel traces or otel metrics
103
+ if let Ok ( stream) = PARSEABLE . get_stream ( & stream_name) {
104
+ stream
105
+ . get_log_source ( )
106
+ . iter ( )
107
+ . find ( |& stream_log_source_entry| {
108
+ stream_log_source_entry. log_source_format != LogSource :: OtelTraces
109
+ && stream_log_source_entry. log_source_format != LogSource :: OtelMetrics
110
+ } )
111
+ . ok_or ( PostError :: IncorrectLogFormat ( stream_name. clone ( ) ) ) ?;
112
+ }
113
+
114
+ PARSEABLE
115
+ . add_update_log_source ( & stream_name, log_source_entry)
116
+ . await ?;
117
+ let p_custom_fields = get_custom_fields_from_header ( req) ;
102
118
flatten_and_push_logs ( json, & stream_name, & log_source, & p_custom_fields) . await ?;
103
119
104
120
Ok ( HttpResponse :: Ok ( ) . finish ( ) )
@@ -159,9 +175,27 @@ pub async fn handle_otel_logs_ingestion(
159
175
. create_stream_if_not_exists (
160
176
& stream_name,
161
177
StreamType :: UserDefined ,
162
- vec ! [ log_source_entry] ,
178
+ vec ! [ log_source_entry. clone ( ) ] ,
163
179
)
164
180
. await ?;
181
+
182
+ //if stream exists, fetch the stream log source
183
+ //return error if the stream log source is otel traces or otel metrics
184
+ if let Ok ( stream) = PARSEABLE . get_stream ( & stream_name) {
185
+ stream
186
+ . get_log_source ( )
187
+ . iter ( )
188
+ . find ( |& stream_log_source_entry| {
189
+ stream_log_source_entry. log_source_format != LogSource :: OtelTraces
190
+ && stream_log_source_entry. log_source_format != LogSource :: OtelMetrics
191
+ } )
192
+ . ok_or ( PostError :: IncorrectLogFormat ( stream_name. clone ( ) ) ) ?;
193
+ }
194
+
195
+ PARSEABLE
196
+ . add_update_log_source ( & stream_name, log_source_entry)
197
+ . await ?;
198
+
165
199
let p_custom_fields = get_custom_fields_from_header ( req) ;
166
200
167
201
flatten_and_push_logs ( json, & stream_name, & log_source, & p_custom_fields) . await ?;
@@ -188,6 +222,7 @@ pub async fn handle_otel_metrics_ingestion(
188
222
}
189
223
190
224
let stream_name = stream_name. to_str ( ) . unwrap ( ) . to_owned ( ) ;
225
+
191
226
let log_source_entry = LogSourceEntry :: new (
192
227
log_source. clone ( ) ,
193
228
OTEL_METRICS_KNOWN_FIELD_LIST
@@ -199,10 +234,26 @@ pub async fn handle_otel_metrics_ingestion(
199
234
. create_stream_if_not_exists (
200
235
& stream_name,
201
236
StreamType :: UserDefined ,
202
- vec ! [ log_source_entry] ,
237
+ vec ! [ log_source_entry. clone ( ) ] ,
203
238
)
204
239
. await ?;
205
240
241
+ //if stream exists, fetch the stream log source
242
+ //return error if the stream log source is not otel metrics
243
+ if let Ok ( stream) = PARSEABLE . get_stream ( & stream_name) {
244
+ stream
245
+ . get_log_source ( )
246
+ . iter ( )
247
+ . find ( |& stream_log_source_entry| {
248
+ stream_log_source_entry. log_source_format == log_source. clone ( )
249
+ } )
250
+ . ok_or ( PostError :: IncorrectLogFormat ( stream_name. clone ( ) ) ) ?;
251
+ }
252
+
253
+ PARSEABLE
254
+ . add_update_log_source ( & stream_name, log_source_entry)
255
+ . await ?;
256
+
206
257
let p_custom_fields = get_custom_fields_from_header ( req) ;
207
258
208
259
flatten_and_push_logs ( json, & stream_name, & log_source, & p_custom_fields) . await ?;
@@ -229,6 +280,7 @@ pub async fn handle_otel_traces_ingestion(
229
280
return Err ( PostError :: IncorrectLogSource ( LogSource :: OtelTraces ) ) ;
230
281
}
231
282
let stream_name = stream_name. to_str ( ) . unwrap ( ) . to_owned ( ) ;
283
+
232
284
let log_source_entry = LogSourceEntry :: new (
233
285
log_source. clone ( ) ,
234
286
OTEL_TRACES_KNOWN_FIELD_LIST
@@ -241,10 +293,26 @@ pub async fn handle_otel_traces_ingestion(
241
293
. create_stream_if_not_exists (
242
294
& stream_name,
243
295
StreamType :: UserDefined ,
244
- vec ! [ log_source_entry] ,
296
+ vec ! [ log_source_entry. clone ( ) ] ,
245
297
)
246
298
. await ?;
247
299
300
+ //if stream exists, fetch the stream log source
301
+ //return error if the stream log source is not otel traces
302
+ if let Ok ( stream) = PARSEABLE . get_stream ( & stream_name) {
303
+ stream
304
+ . get_log_source ( )
305
+ . iter ( )
306
+ . find ( |& stream_log_source_entry| {
307
+ stream_log_source_entry. log_source_format == log_source. clone ( )
308
+ } )
309
+ . ok_or ( PostError :: IncorrectLogFormat ( stream_name. clone ( ) ) ) ?;
310
+ }
311
+
312
+ PARSEABLE
313
+ . add_update_log_source ( & stream_name, log_source_entry)
314
+ . await ?;
315
+
248
316
let p_custom_fields = get_custom_fields_from_header ( req) ;
249
317
250
318
flatten_and_push_logs ( json, & stream_name, & log_source, & p_custom_fields) . await ?;
@@ -304,6 +372,18 @@ pub async fn post_event(
304
372
_ => { }
305
373
}
306
374
375
+ //if stream exists, fetch the stream log source
376
+ //return error if the stream log source is otel traces or otel metrics
377
+ if let Ok ( stream) = PARSEABLE . get_stream ( & stream_name) {
378
+ stream
379
+ . get_log_source ( )
380
+ . iter ( )
381
+ . find ( |& stream_log_source_entry| {
382
+ stream_log_source_entry. log_source_format != LogSource :: OtelTraces
383
+ && stream_log_source_entry. log_source_format != LogSource :: OtelMetrics
384
+ } )
385
+ . ok_or ( PostError :: IncorrectLogFormat ( stream_name. clone ( ) ) ) ?;
386
+ }
307
387
let p_custom_fields = get_custom_fields_from_header ( req) ;
308
388
flatten_and_push_logs ( json, & stream_name, & log_source, & p_custom_fields) . await ?;
309
389
@@ -373,6 +453,8 @@ pub enum PostError {
373
453
MissingTimePartition ( String ) ,
374
454
#[ error( "{0}" ) ]
375
455
KnownFormat ( #[ from] known_schema:: Error ) ,
456
+ #[ error( "Ingestion is not allowed to stream {0} as it is already associated with a different OTEL format" ) ]
457
+ IncorrectLogFormat ( String ) ,
376
458
}
377
459
378
460
impl actix_web:: ResponseError for PostError {
@@ -400,6 +482,7 @@ impl actix_web::ResponseError for PostError {
400
482
PostError :: IngestionNotAllowed => StatusCode :: BAD_REQUEST ,
401
483
PostError :: MissingTimePartition ( _) => StatusCode :: BAD_REQUEST ,
402
484
PostError :: KnownFormat ( _) => StatusCode :: BAD_REQUEST ,
485
+ PostError :: IncorrectLogFormat ( _) => StatusCode :: BAD_REQUEST ,
403
486
}
404
487
}
405
488
0 commit comments