Skip to content

GenericAnalyzer: expected matcher never populates expected_ (analyzer fails to initialise) #656

Description

@matthew-t-watson

Summary

GenericAnalyzer's expected matcher is non-functional: an analyzer whose only matcher is expected fails to initialise, and even alongside another matcher, expected never matches anything.

Root cause

In generic_analyzer.cpp, the expected branch of GenericAnalyzer::init only pre-seeds the base-class items_ map (via addItem()); it never populates the expected_ vector:

} else if (pname.compare("expected") == 0) {
  ...
  for (auto exp : pvalue.as_string_array()) {
    auto item = std::make_shared<StatusItem>(exp);
    this->addItem(exp, item);          // -> items_, never expected_
  }
}

But expected_ is what the rest of the class relies on:

  • the init guard — startswith_.size() == 0 && name_.size() == 0 && contains_.size() == 0 && expected_.size() == 0 && regex_.size() == 0 — decides "was not initialized with any way of checking diagnostics";
  • match() — iterates expected_ (name == expected_[i]);
  • report() — iterates expected_ for missing-item detection.

expected_ is never written anywhere in the file, so:

  1. an expected-only analyzer trips the init guard and is dropped, leaving its AnalyzerGroup empty (Group '<x>' doesn't contain any analyzers, can't match); and
  2. even combined with another matcher, expected contributes nothing, since match()/report() read the empty expected_.

This is a regression from the ROS 1 implementation, which populated the vector via getParamVals(expected, expected_) before creating the pre-seeded items (noetic-devel generic_analyzer.cpp).

Reproduction

Config (aggregator_node --ros-args --params-file expected.yaml):

/**:
  ros__parameters:
    path: Test
    loctest:
      type: diagnostic_aggregator/GenericAnalyzer
      path: LocTest
      expected: ['some/expected/status_name']
      timeout: 5.0

Actual: node logs GenericAnalyzer 'LocTest' was not initialized with any way of checking diagnostics and Group 'Test' doesn't contain any analyzers, can't match. Swapping expected for startswith/contains/regex works.

Expected: the analyzer initialises and matches statuses whose names are in expected (and reports missing expected items as stale, per the ROS 1 behaviour).

Affected versions

Present in the installed Jazzy build (diagnostic_aggregator 4.2.7) and the current ros2 (rolling) branch.

Fix

A fix (restore expected_ population) plus a regression test is proposed in #655.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions