Skip to content

Commit 58a56f5

Browse files
authored
Merge branch 'main' into taegyunkim/12.0.0-release
2 parents 2ce2701 + d0832ff commit 58a56f5

File tree

2 files changed

+113
-8
lines changed

2 files changed

+113
-8
lines changed

trace-mini-agent/src/stats_processor.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ impl StatsProcessor for ServerlessStatsProcessor {
6262
}
6363
};
6464

65-
let start = SystemTime::now();
66-
let timestamp = start
67-
.duration_since(UNIX_EPOCH)
68-
.unwrap_or_default()
69-
.as_nanos();
70-
stats.stats[0].start = timestamp as u64;
65+
if !stats.stats.is_empty() {
66+
let start = SystemTime::now();
67+
let timestamp = start
68+
.duration_since(UNIX_EPOCH)
69+
.unwrap_or_default()
70+
.as_nanos();
71+
stats.stats[0].start = timestamp as u64;
72+
}
7173

7274
// send trace payload to our trace flusher
7375
match tx.send(stats).await {

trace-utils/src/stats_utils.rs

Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ pub async fn get_stats_from_request_body(body: Body) -> anyhow::Result<pb::Clien
2121
};
2222

2323
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");
2625
}
2726
Ok(client_stats_payload)
2827
}
@@ -186,4 +185,108 @@ mod tests {
186185
);
187186
assert_eq!(res.unwrap(), client_stats_payload)
188187
}
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+
}
189292
}

0 commit comments

Comments
 (0)