IcingaDB: Sync affects_children as part of runtime state updates

This commit is contained in:
Yonas Habteab 2024-12-02 14:37:09 +01:00
parent 297b62d841
commit 6321606671
3 changed files with 31 additions and 0 deletions

View File

@ -122,6 +122,35 @@ bool Checkable::IsReachable(DependencyType dt, Dependency::Ptr *failedDependency
return true;
}
/**
* Checks whether the last check result of this Checkable affects its child dependencies.
*
* A Checkable affects its child dependencies if it runs into a non-OK state and results in any of its child
* Checkables to become unreachable. Though, that unavailable dependency may not necessarily cause the child
* Checkable to be in unreachable state as it might have some other dependencies that are still reachable, instead
* it just indicates whether the edge/connection between this and the child Checkable is broken or not.
*
* @return bool - Returns true if the Checkable affects its child dependencies, otherwise false.
*/
bool Checkable::AffectsChildren() const
{
if (!GetLastCheckResult() || !IsReachable()) {
// If there is no check result, or the Checkable is not reachable, we can't safely determine whether
// the Checkable affects its child dependencies.
return false;
}
for (auto& dep : GetReverseDependencies()) {
if (!dep->IsAvailable(DependencyState)) {
// If one of the child dependency is not available, then it's definitely due to the
// current Checkable state, so we don't need to verify the remaining ones.
return true;
}
}
return false;
}
std::set<Checkable::Ptr> Checkable::GetParents() const
{
std::set<Checkable::Ptr> parents;

View File

@ -82,6 +82,7 @@ public:
void AddGroup(const String& name);
bool IsReachable(DependencyType dt = DependencyState, intrusive_ptr<Dependency> *failedDependency = nullptr, int rstack = 0) const;
bool AffectsChildren() const;
AcknowledgementType GetAcknowledgement();

View File

@ -2828,6 +2828,7 @@ Dictionary::Ptr IcingaDB::SerializeState(const Checkable::Ptr& checkable)
attrs->Set("check_attempt", checkable->GetCheckAttempt());
attrs->Set("is_active", checkable->IsActive());
attrs->Set("affects_children", checkable->AffectsChildren());
CheckResult::Ptr cr = checkable->GetLastCheckResult();