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 \"{protocol}\" to component identified as \
54 \"{name}\" with moniker \"{moniker}\". Original error log:\n{log_line}",
55 )));
56 });
57 results
58 }
59}
6061#[cfg(test)]
62mod tests {
63use super::RoutingErrorsPlugin;
64use crate::metrics::fetch::{FileDataFetcher, TextFetcher};
65use crate::plugins::Plugin;
6667#[fuchsia::test]
68fn test_routing_errors() {
69let 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 ];
8889let 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();
9394let diagnostics_data = Vec::new();
95let mut plugin_input = FileDataFetcher::new(&diagnostics_data);
96 plugin_input.syslog = &fetcher;
97assert_eq!(RoutingErrorsPlugin {}.run(&plugin_input).warnings, expected_output);
98 }
99100#[fuchsia::test]
101fn test_no_match_routing_error() {
102let expected_output: Vec<String> = vec![];
103104let 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();
107108let diagnostics_data = Vec::new();
109let mut plugin_input = FileDataFetcher::new(&diagnostics_data);
110 plugin_input.syslog = &fetcher;
111assert_eq!(RoutingErrorsPlugin {}.run(&plugin_input).warnings, expected_output);
112 }
113}