archivist_config/
archivist-config_rust_config_lib_source.rs
1use fidl::unpersist;
2use fidl_cf_sc_internal_archivistconfig::Config as FidlConfig;
3use fuchsia_inspect::{ArrayProperty, Node};
4use fuchsia_runtime::{take_startup_handle, HandleInfo, HandleType};
5#[derive(Debug)]
6pub struct Config {
7 pub allow_serial_logs: Vec<String>,
8 pub bind_services: Vec<String>,
9 pub component_initial_interests: Vec<String>,
10 pub deny_serial_log_tags: Vec<String>,
11 pub enable_klog: bool,
12 pub log_to_debuglog: bool,
13 pub logs_max_cached_original_bytes: u64,
14 pub maximum_concurrent_snapshots_per_reader: u64,
15 pub num_threads: u8,
16 pub per_component_batch_timeout_seconds: i64,
17 pub pipelines_path: String,
18}
19impl Config {
20 pub fn take_from_startup_handle() -> Self {
21 let config_vmo: zx::Vmo =
22 take_startup_handle(HandleInfo::new(HandleType::ComponentConfigVmo, 0))
23 .expect("Config VMO handle must be provided and cannot already have been taken.")
24 .into();
25 let config_size =
26 config_vmo.get_content_size().expect("must be able to read config vmo content size");
27 assert_ne!(config_size, 0, "config vmo must be non-empty");
28 let config_bytes =
29 config_vmo.read_to_vec(0, config_size).expect("must be able to read config vmo");
30 let checksum_length = u16::from_le_bytes([config_bytes[0], config_bytes[1]]) as usize;
31 let fidl_start = 2 + checksum_length;
32 let observed_checksum = &config_bytes[2..fidl_start];
33 let expected_checksum = vec![
34 0xad, 0x2d, 0xa7, 0x3c, 0x98, 0x65, 0x93, 0x64, 0x02, 0xd1, 0x39, 0x15, 0xc7, 0x21,
35 0xaf, 0xe3, 0x63, 0xcd, 0x55, 0xb3, 0xcf, 0x36, 0x33, 0x1f, 0x99, 0xcf, 0x24, 0x43,
36 0x9f, 0x16, 0xe9, 0xf9,
37 ];
38 assert_eq!(
39 observed_checksum, expected_checksum,
40 "checksum from config VMO does not match expected checksum"
41 );
42 let fidl_config: FidlConfig = unpersist(&config_bytes[fidl_start..])
43 .expect("must be able to parse bytes as config FIDL");
44 Self {
45 allow_serial_logs: fidl_config.allow_serial_logs,
46 bind_services: fidl_config.bind_services,
47 component_initial_interests: fidl_config.component_initial_interests,
48 deny_serial_log_tags: fidl_config.deny_serial_log_tags,
49 enable_klog: fidl_config.enable_klog,
50 log_to_debuglog: fidl_config.log_to_debuglog,
51 logs_max_cached_original_bytes: fidl_config.logs_max_cached_original_bytes,
52 maximum_concurrent_snapshots_per_reader: fidl_config
53 .maximum_concurrent_snapshots_per_reader,
54 num_threads: fidl_config.num_threads,
55 per_component_batch_timeout_seconds: fidl_config.per_component_batch_timeout_seconds,
56 pipelines_path: fidl_config.pipelines_path,
57 }
58 }
59 pub fn record_inspect(&self, inspector_node: &Node) {
60 let arr =
61 inspector_node.create_string_array("allow_serial_logs", self.allow_serial_logs.len());
62 for i in 0..self.allow_serial_logs.len() {
63 arr.set(i, &self.allow_serial_logs[i]);
64 }
65 inspector_node.record(arr);
66 let arr = inspector_node.create_string_array("bind_services", self.bind_services.len());
67 for i in 0..self.bind_services.len() {
68 arr.set(i, &self.bind_services[i]);
69 }
70 inspector_node.record(arr);
71 let arr = inspector_node.create_string_array(
72 "component_initial_interests",
73 self.component_initial_interests.len(),
74 );
75 for i in 0..self.component_initial_interests.len() {
76 arr.set(i, &self.component_initial_interests[i]);
77 }
78 inspector_node.record(arr);
79 let arr = inspector_node
80 .create_string_array("deny_serial_log_tags", self.deny_serial_log_tags.len());
81 for i in 0..self.deny_serial_log_tags.len() {
82 arr.set(i, &self.deny_serial_log_tags[i]);
83 }
84 inspector_node.record(arr);
85 inspector_node.record_bool("enable_klog", self.enable_klog);
86 inspector_node.record_bool("log_to_debuglog", self.log_to_debuglog);
87 inspector_node
88 .record_uint("logs_max_cached_original_bytes", self.logs_max_cached_original_bytes);
89 inspector_node.record_uint(
90 "maximum_concurrent_snapshots_per_reader",
91 self.maximum_concurrent_snapshots_per_reader,
92 );
93 inspector_node.record_uint("num_threads", self.num_threads as u64);
94 inspector_node.record_int(
95 "per_component_batch_timeout_seconds",
96 self.per_component_batch_timeout_seconds,
97 );
98 inspector_node.record_string("pipelines_path", &self.pipelines_path);
99 }
100}