Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Commit

Permalink
fix(apm): Return the correct time (#400)
Browse files Browse the repository at this point in the history
* fix(apm): Return the correct time

* fix lint

* add test

* fix lint

* fix ci

* fix lint
  • Loading branch information
yejiayu authored Aug 6, 2020
1 parent f951a95 commit fd6549a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions common/apm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp
#![allow(clippy::float_cmp)]

pub mod metrics;

pub use muta_apm;
Expand Down
16 changes: 15 additions & 1 deletion common/apm/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl From<Error> for ProtocolError {
impl std::error::Error for Error {}

pub fn duration_to_sec(d: Duration) -> f64 {
d.as_secs_f64() + (f64::from(d.subsec_nanos()) / 1e9)
d.as_secs_f64()
}

pub fn all_metrics() -> ProtocolResult<Vec<u8>> {
Expand All @@ -54,3 +54,17 @@ pub fn all_metrics() -> ProtocolResult<Vec<u8>> {

Ok(encoded_metrics)
}

#[cfg(test)]
mod tests {
use super::duration_to_sec;
use std::time::Duration;

#[test]
fn test_duration_to_sec() {
let d = Duration::from_millis(1110);
let sec = duration_to_sec(d);

assert_eq!(sec, 1.11 as f64);
}
}

0 comments on commit fd6549a

Please sign in to comment.