Sfoglia il codice sorgente

Added interface to get host_id from the metric (#8196)

J 1 mese fa
parent
commit
bbc297481a
2 ha cambiato i file con 12 aggiunte e 0 eliminazioni
  1. 1 0
      metrics/Cargo.toml
  2. 11 0
      metrics/src/metrics.rs

+ 1 - 0
metrics/Cargo.toml

@@ -30,6 +30,7 @@ bencher = { workspace = true }
 env_logger = { workspace = true }
 rand = { workspace = true }
 serial_test = { workspace = true }
+solana-sha256-hasher = { workspace = true, features = ["sha2"] }
 
 [[bench]]
 name = "metrics"

+ 11 - 0
metrics/src/metrics.rs

@@ -407,6 +407,10 @@ pub fn set_host_id(host_id: String) {
     *HOST_ID.write().unwrap() = host_id;
 }
 
+pub fn get_host_id() -> String {
+    HOST_ID.read().unwrap().clone()
+}
+
 /// Submits a new point from any thread.  Note that points are internally queued
 /// and transmitted periodically in batches.
 pub fn submit(point: DataPoint, level: log::Level) {
@@ -739,4 +743,11 @@ mod test {
             .to_owned();
         agent.submit(point, Level::Info);
     }
+
+    #[test]
+    fn test_host_id() {
+        let test_host_id = "test_host_123".to_string();
+        set_host_id(test_host_id.clone());
+        assert_eq!(get_host_id(), test_host_id);
+    }
 }