@@ -3,7 +3,7 @@ use std::{convert::TryInto, io::ErrorKind};
3
3
use async_compression:: tokio:: bufread;
4
4
use aws_sdk_s3:: types:: ByteStream ;
5
5
use codecs:: decoding:: { DeserializerConfig , FramingConfig , NewlineDelimitedDecoderOptions } ;
6
- use codecs:: { BytesDeserializerConfig , NewlineDelimitedDecoderConfig } ;
6
+ use codecs:: NewlineDelimitedDecoderConfig ;
7
7
use futures:: { stream, stream:: StreamExt , TryStreamExt } ;
8
8
use lookup:: owned_value_path;
9
9
use snafu:: Snafu ;
@@ -14,7 +14,6 @@ use vrl::value::{kind::Collection, Kind};
14
14
15
15
use super :: util:: MultilineConfig ;
16
16
use crate :: codecs:: DecodingConfig ;
17
- use crate :: config:: DataType ;
18
17
use crate :: {
19
18
aws:: { auth:: AwsAuthentication , create_client, create_client_and_region, RegionOrEndpoint } ,
20
19
common:: { s3:: S3ClientBuilder , sqs:: SqsClientBuilder } ,
@@ -163,7 +162,8 @@ impl SourceConfig for AwsS3Config {
163
162
164
163
fn outputs ( & self , global_log_namespace : LogNamespace ) -> Vec < SourceOutput > {
165
164
let log_namespace = global_log_namespace. merge ( self . log_namespace ) ;
166
- let mut schema_definition = BytesDeserializerConfig
165
+ let mut schema_definition = self
166
+ . decoding
167
167
. schema_definition ( log_namespace)
168
168
. with_source_metadata (
169
169
Self :: NAME ,
@@ -199,7 +199,7 @@ impl SourceConfig for AwsS3Config {
199
199
Self :: NAME ,
200
200
None ,
201
201
& owned_value_path ! ( "metadata" ) ,
202
- Kind :: object ( Collection :: empty ( ) . with_unknown ( Kind :: bytes ( ) ) ) ,
202
+ Kind :: object ( Collection :: empty ( ) . with_unknown ( Kind :: bytes ( ) ) ) . or_undefined ( ) ,
203
203
None ,
204
204
) ;
205
205
@@ -208,7 +208,10 @@ impl SourceConfig for AwsS3Config {
208
208
schema_definition = schema_definition. unknown_fields ( Kind :: bytes ( ) ) ;
209
209
}
210
210
211
- vec ! [ SourceOutput :: new_logs( DataType :: Log , schema_definition) ]
211
+ vec ! [ SourceOutput :: new_logs(
212
+ self . decoding. output_type( ) ,
213
+ schema_definition,
214
+ ) ]
212
215
}
213
216
214
217
fn can_acknowledge ( & self ) -> bool {
@@ -440,6 +443,7 @@ mod integration_tests {
440
443
441
444
use aws_sdk_s3:: { types:: ByteStream , Client as S3Client } ;
442
445
use aws_sdk_sqs:: { model:: QueueAttributeName , Client as SqsClient } ;
446
+ use codecs:: { decoding:: DeserializerConfig , JsonDeserializerConfig } ;
443
447
use lookup:: path;
444
448
use similar_asserts:: assert_eq;
445
449
use vrl:: value:: Value ;
@@ -483,6 +487,35 @@ mod integration_tests {
483
487
logs,
484
488
Delivered ,
485
489
false ,
490
+ DeserializerConfig :: Bytes ,
491
+ )
492
+ . await ;
493
+ }
494
+
495
+ #[ tokio:: test]
496
+ async fn s3_process_json_message ( ) {
497
+ trace_init ( ) ;
498
+
499
+ let logs: Vec < String > = random_lines ( 100 ) . take ( 10 ) . collect ( ) ;
500
+
501
+ let json_logs: Vec < String > = logs
502
+ . iter ( )
503
+ . map ( |msg| {
504
+ // convert to JSON object
505
+ format ! ( r#"{{"message": "{}"}}"# , msg)
506
+ } )
507
+ . collect ( ) ;
508
+
509
+ test_event (
510
+ None ,
511
+ None ,
512
+ None ,
513
+ None ,
514
+ json_logs. join ( "\n " ) . into_bytes ( ) ,
515
+ logs,
516
+ Delivered ,
517
+ false ,
518
+ DeserializerConfig :: Json ( JsonDeserializerConfig :: default ( ) ) ,
486
519
)
487
520
. await ;
488
521
}
@@ -502,6 +535,7 @@ mod integration_tests {
502
535
logs,
503
536
Delivered ,
504
537
true ,
538
+ DeserializerConfig :: Bytes ,
505
539
)
506
540
. await ;
507
541
}
@@ -522,6 +556,7 @@ mod integration_tests {
522
556
logs,
523
557
Delivered ,
524
558
false ,
559
+ DeserializerConfig :: Bytes ,
525
560
)
526
561
. await ;
527
562
}
@@ -542,6 +577,7 @@ mod integration_tests {
542
577
logs,
543
578
Delivered ,
544
579
false ,
580
+ DeserializerConfig :: Bytes ,
545
581
)
546
582
. await ;
547
583
}
@@ -570,6 +606,7 @@ mod integration_tests {
570
606
logs,
571
607
Delivered ,
572
608
false ,
609
+ DeserializerConfig :: Bytes ,
573
610
)
574
611
. await ;
575
612
}
@@ -599,6 +636,7 @@ mod integration_tests {
599
636
logs,
600
637
Delivered ,
601
638
false ,
639
+ DeserializerConfig :: Bytes ,
602
640
)
603
641
. await ;
604
642
}
@@ -628,6 +666,7 @@ mod integration_tests {
628
666
logs,
629
667
Delivered ,
630
668
false ,
669
+ DeserializerConfig :: Bytes ,
631
670
)
632
671
. await ;
633
672
}
@@ -655,6 +694,7 @@ mod integration_tests {
655
694
vec ! [ "abc\n def\n geh" . to_owned( ) ] ,
656
695
Delivered ,
657
696
false ,
697
+ DeserializerConfig :: Bytes ,
658
698
)
659
699
. await ;
660
700
}
@@ -677,6 +717,7 @@ mod integration_tests {
677
717
logs,
678
718
Errored ,
679
719
false ,
720
+ DeserializerConfig :: Bytes ,
680
721
)
681
722
. await ;
682
723
}
@@ -696,6 +737,7 @@ mod integration_tests {
696
737
logs,
697
738
Rejected ,
698
739
false ,
740
+ DeserializerConfig :: Bytes ,
699
741
)
700
742
. await ;
701
743
}
@@ -708,6 +750,7 @@ mod integration_tests {
708
750
queue_url : & str ,
709
751
multiline : Option < MultilineConfig > ,
710
752
log_namespace : bool ,
753
+ decoding : DeserializerConfig ,
711
754
) -> AwsS3Config {
712
755
AwsS3Config {
713
756
region : RegionOrEndpoint :: with_both ( "us-east-1" , s3_address ( ) ) ,
@@ -723,6 +766,7 @@ mod integration_tests {
723
766
} ) ,
724
767
acknowledgements : true . into ( ) ,
725
768
log_namespace : Some ( log_namespace) ,
769
+ decoding,
726
770
..Default :: default ( )
727
771
}
728
772
}
@@ -738,6 +782,7 @@ mod integration_tests {
738
782
expected_lines : Vec < String > ,
739
783
status : EventStatus ,
740
784
log_namespace : bool ,
785
+ decoding : DeserializerConfig ,
741
786
) {
742
787
assert_source_compliance ( & SOURCE_TAGS , async move {
743
788
let key = key. unwrap_or_else ( || uuid:: Uuid :: new_v4 ( ) . to_string ( ) ) ;
@@ -750,7 +795,7 @@ mod integration_tests {
750
795
751
796
tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
752
797
753
- let config = config ( & queue, multiline, log_namespace) ;
798
+ let config = config ( & queue, multiline, log_namespace, decoding ) ;
754
799
755
800
s3. put_object ( )
756
801
. bucket ( bucket. clone ( ) )
@@ -831,6 +876,11 @@ mod integration_tests {
831
876
832
877
assert_eq ! ( expected_lines. len( ) , events. len( ) ) ;
833
878
for ( i, event) in events. iter ( ) . enumerate ( ) {
879
+
880
+ if let Some ( schema_definition) = config. outputs ( namespace) . pop ( ) . unwrap ( ) . schema_definition {
881
+ schema_definition. is_valid_for_event ( event) . unwrap ( ) ;
882
+ }
883
+
834
884
let message = expected_lines[ i] . as_str ( ) ;
835
885
836
886
let log = event. as_log ( ) ;
0 commit comments