mirror of https://github.com/Icinga/icinga2.git
RedisWriter: checksum package, source_location and templates separately in metadata_checksum
This commit is contained in:
parent
e980485e23
commit
3ea3b2ba27
|
@ -152,7 +152,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
||||||
String objectKey = CalculateCheckSumString(object->GetName());
|
String objectKey = CalculateCheckSumString(object->GetName());
|
||||||
//String objectKey = object->GetName();
|
//String objectKey = object->GetName();
|
||||||
|
|
||||||
std::set<String> propertiesBlacklist ({"name"});
|
std::set<String> propertiesBlacklist ({"name", "__name", "package", "source_location", "templates"});
|
||||||
|
|
||||||
Dictionary::Ptr checkSums = new Dictionary();
|
Dictionary::Ptr checkSums = new Dictionary();
|
||||||
checkSums->Set("name_checksum", CalculateCheckSumString(object->GetName()));
|
checkSums->Set("name_checksum", CalculateCheckSumString(object->GetName()));
|
||||||
|
@ -200,6 +200,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
||||||
checkSums->Set("vars_checksum", CalculateCheckSumVars(customVarObject));
|
checkSums->Set("vars_checksum", CalculateCheckSumVars(customVarObject));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkSums->Set("metadata_checksum", CalculateCheckSumMetadata(object));
|
||||||
checkSums->Set("properties_checksum", CalculateCheckSumProperties(object, propertiesBlacklist));
|
checkSums->Set("properties_checksum", CalculateCheckSumProperties(object, propertiesBlacklist));
|
||||||
|
|
||||||
String checkSumsBody = JsonEncode(checkSums);
|
String checkSumsBody = JsonEncode(checkSums);
|
||||||
|
|
|
@ -58,6 +58,13 @@ String RedisWriter::CalculateCheckSumProperties(const ConfigObject::Ptr& object,
|
||||||
return HashValue(object, propertiesBlacklist);
|
return HashValue(object, propertiesBlacklist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const std::set<String> metadataWhitelist ({"package", "source_location", "templates"});
|
||||||
|
|
||||||
|
String RedisWriter::CalculateCheckSumMetadata(const ConfigObject::Ptr& object)
|
||||||
|
{
|
||||||
|
return HashValue(object, metadataWhitelist, true);
|
||||||
|
}
|
||||||
|
|
||||||
String RedisWriter::CalculateCheckSumVars(const CustomVarObject::Ptr& object)
|
String RedisWriter::CalculateCheckSumVars(const CustomVarObject::Ptr& object)
|
||||||
{
|
{
|
||||||
Dictionary::Ptr vars = object->GetVars();
|
Dictionary::Ptr vars = object->GetVars();
|
||||||
|
@ -75,7 +82,7 @@ String RedisWriter::HashValue(const Value& value)
|
||||||
return HashValue(value, propertiesBlacklistEmpty);
|
return HashValue(value, propertiesBlacklistEmpty);
|
||||||
}
|
}
|
||||||
|
|
||||||
String RedisWriter::HashValue(const Value& value, const std::set<String>& propertiesBlacklist)
|
String RedisWriter::HashValue(const Value& value, const std::set<String>& propertiesBlacklist, bool propertiesWhitelist)
|
||||||
{
|
{
|
||||||
Value temp;
|
Value temp;
|
||||||
bool mutabl;
|
bool mutabl;
|
||||||
|
@ -98,8 +105,22 @@ String RedisWriter::HashValue(const Value& value, const std::set<String>& proper
|
||||||
dict = dict->ShallowClone();
|
dict = dict->ShallowClone();
|
||||||
|
|
||||||
ObjectLock olock(dict);
|
ObjectLock olock(dict);
|
||||||
|
|
||||||
|
if (propertiesWhitelist) {
|
||||||
|
auto current = dict->Begin();
|
||||||
|
auto propertiesBlacklistEnd = propertiesBlacklist.end();
|
||||||
|
|
||||||
|
while (current != dict->End()) {
|
||||||
|
if (propertiesBlacklist.find(current->first) == propertiesBlacklistEnd) {
|
||||||
|
dict->Remove(current++);
|
||||||
|
} else {
|
||||||
|
++current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
for (auto& property : propertiesBlacklist)
|
for (auto& property : propertiesBlacklist)
|
||||||
dict->Remove(property);
|
dict->Remove(property);
|
||||||
|
}
|
||||||
|
|
||||||
if (!mutabl)
|
if (!mutabl)
|
||||||
temp = dict;
|
temp = dict;
|
||||||
|
|
|
@ -77,10 +77,11 @@ private:
|
||||||
static String CalculateCheckSumString(const String& str);
|
static String CalculateCheckSumString(const String& str);
|
||||||
static String CalculateCheckSumGroups(const Array::Ptr& groups);
|
static String CalculateCheckSumGroups(const Array::Ptr& groups);
|
||||||
static String CalculateCheckSumProperties(const ConfigObject::Ptr& object, const std::set<String>& propertiesBlacklist);
|
static String CalculateCheckSumProperties(const ConfigObject::Ptr& object, const std::set<String>& propertiesBlacklist);
|
||||||
|
static String CalculateCheckSumMetadata(const ConfigObject::Ptr& object);
|
||||||
static String CalculateCheckSumVars(const CustomVarObject::Ptr& object);
|
static String CalculateCheckSumVars(const CustomVarObject::Ptr& object);
|
||||||
|
|
||||||
static String HashValue(const Value& value);
|
static String HashValue(const Value& value);
|
||||||
static String HashValue(const Value& value, const std::set<String>& propertiesBlacklist);
|
static String HashValue(const Value& value, const std::set<String>& propertiesBlacklist, bool propertiesWhitelist = false);
|
||||||
|
|
||||||
static void StateChangedHandler(const ConfigObject::Ptr& object);
|
static void StateChangedHandler(const ConfigObject::Ptr& object);
|
||||||
static void VersionChangedHandler(const ConfigObject::Ptr& object);
|
static void VersionChangedHandler(const ConfigObject::Ptr& object);
|
||||||
|
|
Loading…
Reference in New Issue