@@ -39,45 +39,36 @@ pub async fn flatten_and_push_logs(
39
39
stream_name : & str ,
40
40
log_source : & LogSource ,
41
41
) -> Result < ( ) , PostError > {
42
- match log_source {
42
+ let json = match log_source {
43
43
LogSource :: Kinesis => {
44
44
//custom flattening required for Amazon Kinesis
45
45
let message: Message = serde_json:: from_value ( json) ?;
46
- for record in flatten_kinesis_logs ( message) {
47
- push_logs ( stream_name, record, & LogSource :: default ( ) ) . await ?;
48
- }
46
+ flatten_kinesis_logs ( message)
49
47
}
50
48
LogSource :: OtelLogs => {
51
49
//custom flattening required for otel logs
52
50
let logs: LogsData = serde_json:: from_value ( json) ?;
53
- for record in flatten_otel_logs ( & logs) {
54
- push_logs ( stream_name, record, log_source) . await ?;
55
- }
51
+ flatten_otel_logs ( & logs)
56
52
}
57
53
LogSource :: OtelTraces => {
58
54
//custom flattening required for otel traces
59
55
let traces: TracesData = serde_json:: from_value ( json) ?;
60
- for record in flatten_otel_traces ( & traces) {
61
- push_logs ( stream_name, record, log_source) . await ?;
62
- }
56
+ flatten_otel_traces ( & traces)
63
57
}
64
58
LogSource :: OtelMetrics => {
65
59
//custom flattening required for otel metrics
66
60
let metrics: MetricsData = serde_json:: from_value ( json) ?;
67
- for record in flatten_otel_metrics ( metrics) {
68
- push_logs ( stream_name, record, log_source) . await ?;
69
- }
61
+ flatten_otel_metrics ( metrics)
70
62
}
71
- _ => {
72
- push_logs ( stream_name, json, log_source) . await ?;
73
- }
74
- }
63
+ _ => vec ! [ json] ,
64
+ } ;
65
+ push_logs ( stream_name, json, log_source) . await ?;
75
66
Ok ( ( ) )
76
67
}
77
68
78
69
async fn push_logs (
79
70
stream_name : & str ,
80
- json : Value ,
71
+ jsons : Vec < Value > ,
81
72
log_source : & LogSource ,
82
73
) -> Result < ( ) , PostError > {
83
74
let stream = PARSEABLE . get_stream ( stream_name) ?;
@@ -89,42 +80,44 @@ async fn push_logs(
89
80
let custom_partition = stream. get_custom_partition ( ) ;
90
81
let schema_version = stream. get_schema_version ( ) ;
91
82
let p_timestamp = Utc :: now ( ) ;
92
-
93
- let data = if time_partition. is_some ( ) || custom_partition. is_some ( ) {
94
- convert_array_to_object (
95
- json,
96
- time_partition. as_ref ( ) ,
97
- time_partition_limit,
98
- custom_partition. as_ref ( ) ,
99
- schema_version,
100
- log_source,
101
- ) ?
102
- } else {
103
- vec ! [ convert_to_array( convert_array_to_object(
104
- json,
105
- None ,
106
- None ,
107
- None ,
108
- schema_version,
109
- log_source,
110
- ) ?) ?]
111
- } ;
112
-
113
- for json in data {
114
- let origin_size = serde_json:: to_vec ( & json) . unwrap ( ) . len ( ) as u64 ; // string length need not be the same as byte length
115
- let schema = PARSEABLE . get_stream ( stream_name) ?. get_schema_raw ( ) ;
116
- json:: Event { json, p_timestamp }
117
- . into_event (
118
- stream_name. to_owned ( ) ,
119
- origin_size,
120
- & schema,
121
- static_schema_flag,
122
- custom_partition. as_ref ( ) ,
83
+
84
+ for json in jsons {
85
+ let data = if time_partition. is_some ( ) || custom_partition. is_some ( ) {
86
+ convert_array_to_object (
87
+ json,
123
88
time_partition. as_ref ( ) ,
89
+ time_partition_limit,
90
+ custom_partition. as_ref ( ) ,
124
91
schema_version,
125
- StreamType :: UserDefined ,
92
+ log_source ,
126
93
) ?
127
- . process ( ) ?;
94
+ } else {
95
+ vec ! [ convert_to_array( convert_array_to_object(
96
+ json,
97
+ None ,
98
+ None ,
99
+ None ,
100
+ schema_version,
101
+ log_source,
102
+ ) ?) ?]
103
+ } ;
104
+
105
+ for json in data {
106
+ let origin_size = serde_json:: to_vec ( & json) . unwrap ( ) . len ( ) as u64 ; // string length need not be the same as byte length
107
+ let schema = PARSEABLE . get_stream ( stream_name) ?. get_schema_raw ( ) ;
108
+ json:: Event { json, p_timestamp }
109
+ . into_event (
110
+ stream_name. to_owned ( ) ,
111
+ origin_size,
112
+ & schema,
113
+ static_schema_flag,
114
+ custom_partition. as_ref ( ) ,
115
+ time_partition. as_ref ( ) ,
116
+ schema_version,
117
+ StreamType :: UserDefined ,
118
+ ) ?
119
+ . process ( ) ?;
120
+ }
128
121
}
129
122
Ok ( ( ) )
130
123
}
0 commit comments