fuchsia_triage/plugins/
routing.rs1use super::helpers::analyze_logs;
6use super::Plugin;
7use crate::act::Action;
8use crate::metrics::fetch::FileDataFetcher;
9use regex::Regex;
10
11pub struct RoutingErrorsPlugin {}
12
13impl Plugin for RoutingErrorsPlugin {
14 fn name(&self) -> &'static str {
15 "routing_errors"
16 }
17
18 fn display_name(&self) -> &'static str {
19 "Routing Errors"
20 }
21
22 fn run_structured(&self, inputs: &FileDataFetcher<'_>) -> Vec<Action> {
23 let mut results = Vec::new();
24
25 let re = Regex::new(r".*\[([^:]+):[0-9]+\] ERROR.*Required protocol `([^`]+)` was not available for target component `([^`]+)`.*").expect("regex compilation failed");
26 analyze_logs(inputs, re, |mut pattern_match| {
27 let (moniker, protocol, name): (&str, &str, &str) =
28 match (pattern_match.pop(), pattern_match.pop(), pattern_match.pop()) {
29 (Some(moniker), Some(protocol), Some(name)) => {
30 (moniker.into(), protocol.into(), name.into())
31 }
32 _ => {
33 results.push(Action::new_synthetic_error(
34 "[DEBUG: BAD DATA] Routing Errors plugin encountered a bug analyzing \
35 log line, capture group missing"
36 .to_string(),
37 "Diagnostics>Triage".to_string(),
38 ));
39 return;
40 }
41 };
42 if pattern_match.is_empty() {
43 results.push(Action::new_synthetic_error(
44 "[DEBUG: BAD DATA] Routing Errors plugin encountered a bug analyzing log \
45 line, capture group missing"
46 .to_string(),
47 "Diagnostics>Triage".to_string(),
48 ));
49 return;
50 }
51 let log_line: &str = pattern_match.remove(0).into();
52 results.push(Action::new_synthetic_warning(format!(
53 "[WARNING]: Error routing capability \"{protocol}\" to component identified as \
54 \"{name}\" with moniker \"{moniker}\". Original error log:\n{log_line}",
55 )));
56 });
57 results
58 }
59}
60
61#[cfg(test)]
62mod tests {
63 use super::RoutingErrorsPlugin;
64 use crate::metrics::fetch::{FileDataFetcher, TextFetcher};
65 use crate::plugins::Plugin;
66
67 #[fuchsia::test]
68 fn test_routing_errors() {
69 let expected_output = vec![
70 "[WARNING]: Error routing capability \
71 \"fidl.examples.routing.echo.Echo\" to component identified as \"echo_client\" \
72 with moniker \"/bootstrap/echo/echo_client\". Original error log:\n[00017.480623]\
73 [1150][1253][echo_client:0] ERROR: Required protocol `fidl.examples.routing.echo.Echo` \
74 was not available for target component `/bootstrap/echo/echo_client`\
75 : A `use from parent` declaration was found at `/bootstrap/echo/echo_client` for \
76 `fidl.examples.routing.echo.Echo`, but no matching `offer` declaration was found in the \
77 parent"
78 .to_string(),
79 "[WARNING]: Error routing capability \
80 \"foo.bar.Baz\" to component identified as \"foobar\" \
81 with moniker \"/bootstrap/foobar\". Original error log:\n[12471.623480]\
82 [782][9443][foobar:345] ERROR: Required protocol `foo.bar.Baz` \
83 was not available for target component `/bootstrap/foobar`: A `use from parent` \
84 declaration was found at `/bootstrap/foobar` for `foo.bar.Baz`, but no matching \
85 `offer` declaration was found in the parent"
86 .to_string(),
87 ];
88
89 let fetcher: TextFetcher = r#"
90[00017.480623][1150][1253][echo_client:0] ERROR: Required protocol `fidl.examples.routing.echo.Echo` was not available for target component `/bootstrap/echo/echo_client`: A `use from parent` declaration was found at `/bootstrap/echo/echo_client` for `fidl.examples.routing.echo.Echo`, but no matching `offer` declaration was found in the parent
91[12471.623480][782][9443][foobar:345] ERROR: Required protocol `foo.bar.Baz` was not available for target component `/bootstrap/foobar`: A `use from parent` declaration was found at `/bootstrap/foobar` for `foo.bar.Baz`, but no matching `offer` declaration was found in the parent
92"#.into();
93
94 let diagnostics_data = Vec::new();
95 let mut plugin_input = FileDataFetcher::new(&diagnostics_data);
96 plugin_input.syslog = &fetcher;
97 assert_eq!(RoutingErrorsPlugin {}.run(&plugin_input).warnings, expected_output);
98 }
99
100 #[fuchsia::test]
101 fn test_no_match_routing_error() {
102 let expected_output: Vec<String> = vec![];
103
104 let fetcher: TextFetcher = r#"
105[00017.480623][1150][1253][component manager] ERROR: Required protocol `fidl.examples.routing.echo.Echo` was not available for target component `/bootstrap/echo/echo_client`: A `use from parent` declaration was found at `/bootstrap/echo/echo_client` for `fidl.examples.routing.echo.Echo`, but no matching `offer` declaration was found in the parent
106"#.into();
107
108 let diagnostics_data = Vec::new();
109 let mut plugin_input = FileDataFetcher::new(&diagnostics_data);
110 plugin_input.syslog = &fetcher;
111 assert_eq!(RoutingErrorsPlugin {}.run(&plugin_input).warnings, expected_output);
112 }
113}