Skip to content

Commit

Permalink
Merge pull request #2 from nobleo/feature/HARVEY-1380-new-analyser-group
Browse files Browse the repository at this point in the history
Report STALE when there is at least one STALE and no ERROR
  • Loading branch information
Rayman authored May 3, 2023
2 parents 14d2d79 + ef48cc6 commit 2b561e5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
27 changes: 17 additions & 10 deletions diagnostic_aggregator/src/aggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void Aggregator::publishData()
diagnostic_msgs::DiagnosticStatus diag_toplevel_state;
diag_toplevel_state.name = "toplevel_state";
diag_toplevel_state.level = -1;
int min_level = 255;
int8_t max_level_without_stale = 0;
uint non_ok_status_depth = 0;
uint report_idx = 0;

Expand All @@ -252,9 +252,10 @@ void Aggregator::publishData()
non_ok_status_depth = depth;
report_idx = i;
}
if (processed[i]->level < min_level)
{
min_level = processed[i]->level;
if (
processed[i]->level > max_level_without_stale &&
processed[i]->level != diagnostic_msgs::DiagnosticStatus::STALE) {
max_level_without_stale = processed[i]->level;
}
}
// When a non-ok item was found, copy the complete status message once
Expand Down Expand Up @@ -292,9 +293,10 @@ void Aggregator::publishData()
non_ok_status_depth = depth;
report_idx = i;
}
if (processed_other[i]->level < min_level)
{
min_level = processed_other[i]->level;
if (
processed_other[i]->level > max_level_without_stale &&
processed_other[i]->level != diagnostic_msgs::DiagnosticStatus::STALE) {
max_level_without_stale = processed_other[i]->level;
}
// When a non-ok item was found AND it was reported in 'other' categpry, copy the complete status message once
if (diag_toplevel_state.level > diagnostic_msgs::DiagnosticStatus::OK && non_ok_status_depth > 0)
Expand All @@ -310,9 +312,14 @@ void Aggregator::publishData()

agg_pub_.publish(diag_array);

// Top level is error if we have stale items, unless all stale
if (diag_toplevel_state.level > int(DiagnosticLevel::Level_Error) && min_level <= int(DiagnosticLevel::Level_Error))
diag_toplevel_state.level = DiagnosticLevel::Level_Error;
// If there is at least one stale message and there are no errors, report stale
if (
diag_toplevel_state.level == DiagnosticLevel::Level_Stale &&
max_level_without_stale < DiagnosticLevel::Level_Error) {
diag_toplevel_state.level = DiagnosticLevel::Level_Stale;
} else {
diag_toplevel_state.level = max_level_without_stale;
}

// Store latest toplevel state for immediate publish checking
diag_toplevel_ = diag_toplevel_state.level;
Expand Down
19 changes: 13 additions & 6 deletions diagnostic_aggregator/src/analyzer_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ vector<boost::shared_ptr<diagnostic_msgs::DiagnosticStatus> > AnalyzerGroup::rep
return output;
}

bool all_stale = true;
int8_t max_level_without_stale = 0;

for (unsigned int j = 0; j < analyzers_.size(); ++j)
{
Expand All @@ -278,17 +278,24 @@ vector<boost::shared_ptr<diagnostic_msgs::DiagnosticStatus> > AnalyzerGroup::rep
diagnostic_msgs::KeyValue kv;
kv.key = nice_name;
kv.value = processed[i]->message;

all_stale = all_stale && (processed[i]->level == int(DiagnosticLevel::Level_Stale));

if (processed[i]->level != DiagnosticLevel::Level_Stale) {
max_level_without_stale = max(max_level_without_stale, processed[i]->level);
}
header_status->level = max(header_status->level, processed[i]->level);
header_status->values.push_back(kv);
}
}
}

// Report stale as errors unless all stale
if (header_status->level == int(DiagnosticLevel::Level_Stale) && !all_stale)
header_status->level = DiagnosticLevel::Level_Error;
// If one STALE and no ERROR, report STALE
if (
header_status->level == DiagnosticLevel::Level_Stale &&
max_level_without_stale < DiagnosticLevel::Level_Error) {
header_status->level = DiagnosticLevel::Level_Stale;
} else {
header_status->level = max_level_without_stale;
}

header_status->message = valToMsg(header_status->level);

Expand Down

0 comments on commit 2b561e5

Please sign in to comment.