@@ -21,8 +21,7 @@ pub async fn get_stats_from_request_body(body: Body) -> anyhow::Result<pb::Clien
21
21
} ;
22
22
23
23
if client_stats_payload. stats . is_empty ( ) {
24
- debug ! ( "Empty trace stats payload received" ) ;
25
- anyhow:: bail!( "No stats in stats payload" ) ;
24
+ debug ! ( "Empty trace stats payload received, but this is okay" ) ;
26
25
}
27
26
Ok ( client_stats_payload)
28
27
}
@@ -186,4 +185,108 @@ mod tests {
186
185
) ;
187
186
assert_eq ! ( res. unwrap( ) , client_stats_payload)
188
187
}
188
+
189
+ #[ tokio:: test]
190
+ async fn test_get_stats_from_request_body_without_stats ( ) {
191
+ let stats_json = r#"{
192
+ "Hostname": "TestHost",
193
+ "Env": "test",
194
+ "Version": "1.0.0",
195
+ "Lang": "javascript",
196
+ "TracerVersion": "1.0.0",
197
+ "RuntimeID": "00000000-0000-0000-0000-000000000000",
198
+ "Sequence": 1
199
+ }"# ;
200
+
201
+ let v: Value = match serde_json:: from_str ( stats_json) {
202
+ Ok ( value) => value,
203
+ Err ( err) => {
204
+ panic ! ( "Failed to parse stats JSON: {}" , err) ;
205
+ }
206
+ } ;
207
+
208
+ let bytes = rmp_serde:: to_vec ( & v) . unwrap ( ) ;
209
+ let request = Request :: builder ( )
210
+ . body ( hyper:: body:: Body :: from ( bytes) )
211
+ . unwrap ( ) ;
212
+
213
+ let res = stats_utils:: get_stats_from_request_body ( request. into_body ( ) ) . await ;
214
+
215
+ let client_stats_payload = ClientStatsPayload {
216
+ hostname : "TestHost" . to_string ( ) ,
217
+ env : "test" . to_string ( ) ,
218
+ version : "1.0.0" . to_string ( ) ,
219
+ stats : vec ! [ ] ,
220
+ lang : "javascript" . to_string ( ) ,
221
+ tracer_version : "1.0.0" . to_string ( ) ,
222
+ runtime_id : "00000000-0000-0000-0000-000000000000" . to_string ( ) ,
223
+ sequence : 1 ,
224
+ agent_aggregation : "" . to_string ( ) ,
225
+ service : "" . to_string ( ) ,
226
+ container_id : "" . to_string ( ) ,
227
+ tags : vec ! [ ] ,
228
+ git_commit_sha : "" . to_string ( ) ,
229
+ image_tag : "" . to_string ( ) ,
230
+ } ;
231
+
232
+ assert ! (
233
+ res. is_ok( ) ,
234
+ "Expected Ok result, but got Err: {}" ,
235
+ res. unwrap_err( )
236
+ ) ;
237
+ assert_eq ! ( res. unwrap( ) , client_stats_payload)
238
+ }
239
+
240
+ #[ tokio:: test]
241
+ async fn test_serialize_client_stats_payload_without_stats ( ) {
242
+ let client_stats_payload_without_stats = ClientStatsPayload {
243
+ hostname : "TestHost" . to_string ( ) ,
244
+ env : "test" . to_string ( ) ,
245
+ version : "1.0.0" . to_string ( ) ,
246
+ stats : vec ! [ ] ,
247
+ lang : "javascript" . to_string ( ) ,
248
+ tracer_version : "1.0.0" . to_string ( ) ,
249
+ runtime_id : "00000000-0000-0000-0000-000000000000" . to_string ( ) ,
250
+ sequence : 1 ,
251
+ agent_aggregation : "" . to_string ( ) ,
252
+ service : "" . to_string ( ) ,
253
+ container_id : "" . to_string ( ) ,
254
+ tags : vec ! [ ] ,
255
+ git_commit_sha : "" . to_string ( ) ,
256
+ image_tag : "" . to_string ( ) ,
257
+ } ;
258
+
259
+ let client_stats_payload_without_inner_stats = ClientStatsPayload {
260
+ hostname : "TestHost" . to_string ( ) ,
261
+ env : "test" . to_string ( ) ,
262
+ version : "1.0.0" . to_string ( ) ,
263
+ stats : vec ! [ ClientStatsBucket {
264
+ start: 0 ,
265
+ duration: 10000000000 ,
266
+ stats: vec![ ] ,
267
+ agent_time_shift: 0 ,
268
+ } ] ,
269
+ lang : "javascript" . to_string ( ) ,
270
+ tracer_version : "1.0.0" . to_string ( ) ,
271
+ runtime_id : "00000000-0000-0000-0000-000000000000" . to_string ( ) ,
272
+ sequence : 1 ,
273
+ agent_aggregation : "" . to_string ( ) ,
274
+ service : "" . to_string ( ) ,
275
+ container_id : "" . to_string ( ) ,
276
+ tags : vec ! [ ] ,
277
+ git_commit_sha : "" . to_string ( ) ,
278
+ image_tag : "" . to_string ( ) ,
279
+ } ;
280
+
281
+ let res = stats_utils:: serialize_stats_payload ( stats_utils:: construct_stats_payload ( vec ! [
282
+ client_stats_payload_without_stats,
283
+ client_stats_payload_without_inner_stats,
284
+ ] ) ) ;
285
+
286
+ assert ! (
287
+ res. is_ok( ) ,
288
+ "Expected Ok result, but got Err: {}" ,
289
+ res. unwrap_err( )
290
+ ) ;
291
+ }
189
292
}
0 commit comments