1// Copyright 2020 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
45use super::helpers::analyze_logs;
6use super::Plugin;
7use crate::act::Action;
8use crate::metrics::fetch::FileDataFetcher;
9use regex::Regex;
1011pub struct RoutingErrorsPlugin {}
1213impl Plugin for RoutingErrorsPlugin {
14fn name(&self) -> &'static str {
15"routing_errors"
16}
1718fn display_name(&self) -> &'static str {
19"Routing Errors"
20}
2122fn run_structured(&self, inputs: &FileDataFetcher<'_>) -> Vec<Action> {
23let mut results = Vec::new();
2425let 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| {
27let (moniker, protocol, name): (&str, &str, &str) =
28match (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 ));
39return;
40 }
41 };
42if 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 ));
49return;
50 }
51let log_line: &str = pattern_match.remove(0).into();
52 results.push(Action::new_synthetic_warning(format!(
53"[WARNING]: Error routing capability \"{}\" to component identified as \"{}\" \
54 with moniker \"{}\". Original error log:\n{}",
55 protocol, name, moniker, log_line
56 )));
57 });
58 results
59 }
60}
6162#[cfg(test)]
63mod tests {
64use super::RoutingErrorsPlugin;
65use crate::metrics::fetch::{FileDataFetcher, TextFetcher};
66use crate::plugins::Plugin;
6768#[fuchsia::test]
69fn test_routing_errors() {
70let expected_output = vec![
71"[WARNING]: Error routing capability \
72 \"fidl.examples.routing.echo.Echo\" to component identified as \"echo_client\" \
73 with moniker \"/bootstrap/echo/echo_client\". Original error log:\n[00017.480623]\
74 [1150][1253][echo_client:0] ERROR: Required protocol `fidl.examples.routing.echo.Echo` \
75 was not available for target component `/bootstrap/echo/echo_client`\
76 : A `use from parent` declaration was found at `/bootstrap/echo/echo_client` for \
77 `fidl.examples.routing.echo.Echo`, but no matching `offer` declaration was found in the \
78 parent"
79.to_string(),
80"[WARNING]: Error routing capability \
81 \"foo.bar.Baz\" to component identified as \"foobar\" \
82 with moniker \"/bootstrap/foobar\". Original error log:\n[12471.623480]\
83 [782][9443][foobar:345] ERROR: Required protocol `foo.bar.Baz` \
84 was not available for target component `/bootstrap/foobar`: A `use from parent` \
85 declaration was found at `/bootstrap/foobar` for `foo.bar.Baz`, but no matching \
86 `offer` declaration was found in the parent"
87.to_string(),
88 ];
8990let fetcher: TextFetcher = r#"
91[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
92[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
93"#.into();
9495let diagnostics_data = Vec::new();
96let mut plugin_input = FileDataFetcher::new(&diagnostics_data);
97 plugin_input.syslog = &fetcher;
98assert_eq!(RoutingErrorsPlugin {}.run(&plugin_input).warnings, expected_output);
99 }
100101#[fuchsia::test]
102fn test_no_match_routing_error() {
103let expected_output: Vec<String> = vec![];
104105let fetcher: TextFetcher = r#"
106[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
107"#.into();
108109let diagnostics_data = Vec::new();
110let mut plugin_input = FileDataFetcher::new(&diagnostics_data);
111 plugin_input.syslog = &fetcher;
112assert_eq!(RoutingErrorsPlugin {}.run(&plugin_input).warnings, expected_output);
113 }
114}