LCOV - differential code coverage report
Current view: top level - libs/metrics/src - launch_timestamp.rs (source / functions) Coverage Total Hit CBC
Current: cd44433dd675caa99df17a61b18949c8387e2242.info Lines: 100.0 % 19 19 19
Current Date: 2024-01-09 02:06:09 Functions: 100.0 % 4 4 4
Baseline: 66c52a629a0f4a503e193045e0df4c77139e344b.info
Baseline Date: 2024-01-08 15:34:46

           TLA  Line data    Source code
       1                 : //! A timestamp captured at process startup to identify restarts of the process, e.g., in logs and metrics.
       2                 : 
       3                 : use chrono::Utc;
       4                 : 
       5                 : use super::register_uint_gauge;
       6                 : use std::fmt::Display;
       7                 : 
       8                 : pub struct LaunchTimestamp(chrono::DateTime<Utc>);
       9                 : 
      10                 : impl LaunchTimestamp {
      11 CBC        1259 :     pub fn generate() -> Self {
      12            1259 :         LaunchTimestamp(Utc::now())
      13            1259 :     }
      14                 : }
      15                 : 
      16                 : impl Display for LaunchTimestamp {
      17            1114 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      18            1114 :         write!(f, "{}", self.0)
      19            1114 :     }
      20                 : }
      21                 : 
      22             557 : pub fn set_launch_timestamp_metric(launch_ts: &'static LaunchTimestamp) {
      23             557 :     let millis_since_epoch: u64 = launch_ts
      24             557 :         .0
      25             557 :         .timestamp_millis()
      26             557 :         .try_into()
      27             557 :         .expect("we're after the epoch, this should be positive");
      28             557 :     let metric = register_uint_gauge!(
      29             557 :         "libmetrics_launch_timestamp",
      30             557 :         "Timestamp (millis since epoch) at wich the process launched."
      31             557 :     )
      32             557 :     .unwrap();
      33             557 :     metric.set(millis_since_epoch);
      34             557 : }
        

Generated by: LCOV version 2.1-beta