Split IcingaDB#SendStatusUpdate(), separate stream and history

This commit is contained in:
Alexander A. Klimov 2021-07-29 12:13:32 +02:00
parent 2818245e01
commit 173a93c487
2 changed files with 30 additions and 22 deletions

View File

@ -1513,7 +1513,32 @@ unsigned short GetPreviousState(const Checkable::Ptr& checkable, const Service::
} }
} }
void IcingaDB::SendStatusUpdate(const ConfigObject::Ptr& object, const CheckResult::Ptr& cr, StateType type) void IcingaDB::SendStatusUpdate(const Checkable::Ptr& checkable)
{
if (!m_Rcon || !m_Rcon->IsConnected())
return;
Host::Ptr host;
Service::Ptr service;
Dictionary::Ptr objectAttrs = SerializeState(checkable);
std::vector<String> streamadd({"XADD", "icinga:runtime:state", "MAXLEN", "~", "1000000", "*"});
ObjectLock olock(objectAttrs);
tie(host, service) = GetHostService(checkable);
objectAttrs->Set("redis_key", service ? "icinga:service:state" : "icinga:host:state");
objectAttrs->Set("runtime_type", "upsert");
objectAttrs->Set("checksum", HashValue(objectAttrs));
for (const Dictionary::Pair& kv : objectAttrs) {
streamadd.emplace_back(kv.first);
streamadd.emplace_back(IcingaToStreamValue(kv.second));
}
m_Rcon->FireAndForgetQuery(std::move(streamadd), Prio::RuntimeStateStream);
}
void IcingaDB::SendStateChange(const ConfigObject::Ptr& object, const CheckResult::Ptr& cr, StateType type)
{ {
if (!m_Rcon || !m_Rcon->IsConnected()) if (!m_Rcon || !m_Rcon->IsConnected())
return; return;
@ -1527,25 +1552,7 @@ void IcingaDB::SendStatusUpdate(const ConfigObject::Ptr& object, const CheckResu
tie(host, service) = GetHostService(checkable); tie(host, service) = GetHostService(checkable);
String redisKey; SendStatusUpdate(checkable);
if (service)
redisKey = "icinga:service:state";
else
redisKey = "icinga:host:state";
Dictionary::Ptr objectAttrs = SerializeState(checkable);
objectAttrs->Set("redis_key", redisKey);
objectAttrs->Set("runtime_type", "upsert");
objectAttrs->Set("checksum", HashValue(objectAttrs));
std::vector<String> streamadd({"XADD", "icinga:runtime:state", "MAXLEN", "~", "1000000", "*"});
ObjectLock olock(objectAttrs);
for (const Dictionary::Pair& kv : objectAttrs) {
streamadd.emplace_back(kv.first);
streamadd.emplace_back(IcingaToStreamValue(kv.second));
}
m_Rcon->FireAndForgetQuery(std::move(streamadd), Prio::RuntimeStateStream);
int hard_state; int hard_state;
if (!cr) { if (!cr) {
@ -2319,7 +2326,7 @@ void IcingaDB::StateChangeHandler(const ConfigObject::Ptr& object)
void IcingaDB::StateChangeHandler(const ConfigObject::Ptr& object, const CheckResult::Ptr& cr, StateType type) void IcingaDB::StateChangeHandler(const ConfigObject::Ptr& object, const CheckResult::Ptr& cr, StateType type)
{ {
for (const IcingaDB::Ptr& rw : ConfigType::GetObjectsByType<IcingaDB>()) { for (const IcingaDB::Ptr& rw : ConfigType::GetObjectsByType<IcingaDB>()) {
rw->SendStatusUpdate(object, cr, type); rw->SendStateChange(object, cr, type);
} }
} }

View File

@ -72,7 +72,8 @@ private:
void CreateConfigUpdate(const ConfigObject::Ptr& object, const String type, std::map<String, std::vector<String>>& hMSets, void CreateConfigUpdate(const ConfigObject::Ptr& object, const String type, std::map<String, std::vector<String>>& hMSets,
std::vector<Dictionary::Ptr>& runtimeUpdates, bool runtimeUpdate); std::vector<Dictionary::Ptr>& runtimeUpdates, bool runtimeUpdate);
void SendConfigDelete(const ConfigObject::Ptr& object); void SendConfigDelete(const ConfigObject::Ptr& object);
void SendStatusUpdate(const ConfigObject::Ptr& object, const CheckResult::Ptr& cr, StateType type); void SendStatusUpdate(const Checkable::Ptr& checkable);
void SendStateChange(const ConfigObject::Ptr& object, const CheckResult::Ptr& cr, StateType type);
void AddObjectDataToRuntimeUpdates(std::vector<Dictionary::Ptr>& runtimeUpdates, const String& objectKey, void AddObjectDataToRuntimeUpdates(std::vector<Dictionary::Ptr>& runtimeUpdates, const String& objectKey,
const String& redisKey, const Dictionary::Ptr& data); const String& redisKey, const Dictionary::Ptr& data);