faucet_core/observability/
labels.rs1use std::sync::Arc;
5
6#[derive(Debug, Clone)]
13pub struct Labels {
14 pub pipeline: Arc<str>,
15 pub row: Arc<str>,
16 pub run_id: Arc<str>,
17}
18
19impl Labels {
20 pub fn new(
21 pipeline: impl Into<Arc<str>>,
22 row: impl Into<Arc<str>>,
23 run_id: impl Into<Arc<str>>,
24 ) -> Self {
25 Self {
26 pipeline: pipeline.into(),
27 row: row.into(),
28 run_id: run_id.into(),
29 }
30 }
31
32 pub fn for_named(pipeline: impl Into<Arc<str>>) -> Self {
35 let run_id: Arc<str> = uuid::Uuid::now_v7().to_string().into();
36 Self::new(pipeline, "", run_id)
37 }
38}
39
40#[cfg(test)]
41mod tests {
42 use super::*;
43
44 #[test]
45 fn stores_all_fields() {
46 let l = Labels::new("p", "r", "rid");
47 assert_eq!(&*l.pipeline, "p");
48 assert_eq!(&*l.row, "r");
49 assert_eq!(&*l.run_id, "rid");
50 }
51
52 #[test]
53 fn for_named_mints_run_id() {
54 let l = Labels::for_named("p");
55 assert_eq!(&*l.pipeline, "p");
56 assert_eq!(&*l.row, "");
57 assert_eq!(l.run_id.len(), 36);
59 }
60
61 #[test]
62 fn clone_is_arc_shallow() {
63 let l = Labels::new("p", "r", "rid");
64 let c = l.clone();
65 assert!(Arc::ptr_eq(&l.pipeline, &c.pipeline));
67 assert!(Arc::ptr_eq(&l.row, &c.row));
68 assert!(Arc::ptr_eq(&l.run_id, &c.run_id));
69 }
70}