summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmmanuel Vasilakis <mrzammler@mm.st>2022-03-11 10:49:21 +0200
committerGitHub <noreply@github.com>2022-03-11 10:49:21 +0200
commit4566c0835e99d1b00542ddbc1600450eb61a6a70 (patch)
treee3fed3b41fdcc53f59b2248ac08d5c50da02aeab
parentd752b3e8b74ecf9f384b3e72e1284826d4ceb72a (diff)
Only store alert hashes once per health config iteration (#12292)
* only store alert hashes when iterated from localhost * store hashes on start and health reload, at least for one pass of a host
-rw-r--r--database/sqlite/sqlite_health.c6
-rw-r--r--database/sqlite/sqlite_health.h2
-rw-r--r--health/health.c2
-rw-r--r--health/health.h1
-rw-r--r--health/health_config.c19
5 files changed, 21 insertions, 9 deletions
diff --git a/database/sqlite/sqlite_health.c b/database/sqlite/sqlite_health.c
index 27c67c3aa5..67b3a5913e 100644
--- a/database/sqlite/sqlite_health.c
+++ b/database/sqlite/sqlite_health.c
@@ -900,7 +900,8 @@ int sql_store_alert_config_hash(uuid_t *hash_id, struct alert_config *cfg)
#endif
int alert_hash_and_store_config(
uuid_t hash_id,
- struct alert_config *cfg)
+ struct alert_config *cfg,
+ int store_hash)
{
#if !defined DISABLE_CLOUD && defined ENABLE_HTTPS
EVP_MD_CTX *evpctx;
@@ -946,7 +947,8 @@ int alert_hash_and_store_config(
uuid_copy(hash_id, *((uuid_t *)&hash_value));
/* store everything, so it can be recreated when not in memory or just a subset ? */
- (void)sql_store_alert_config_hash( (uuid_t *)&hash_value, cfg);
+ if (store_hash)
+ (void)sql_store_alert_config_hash( (uuid_t *)&hash_value, cfg);
#else
UNUSED(hash_id);
UNUSED(cfg);
diff --git a/database/sqlite/sqlite_health.h b/database/sqlite/sqlite_health.h
index 3b94608975..ef837894a2 100644
--- a/database/sqlite/sqlite_health.h
+++ b/database/sqlite/sqlite_health.h
@@ -12,6 +12,6 @@ extern void sql_health_alarm_log_update(RRDHOST *host, ALARM_ENTRY *ae);
extern void sql_health_alarm_log_insert(RRDHOST *host, ALARM_ENTRY *ae);
extern void sql_health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae);
extern void sql_health_alarm_log_cleanup(RRDHOST *host);
-extern int alert_hash_and_store_config(uuid_t hash_id, struct alert_config *cfg);
+extern int alert_hash_and_store_config(uuid_t hash_id, struct alert_config *cfg, int store_hash);
extern void sql_aclk_alert_clean_dead_entries(RRDHOST *host);
#endif //NETDATA_SQLITE_HEALTH_H
diff --git a/health/health.c b/health/health.c
index e8c41ec294..d95bcee121 100644
--- a/health/health.c
+++ b/health/health.c
@@ -223,6 +223,8 @@ void health_reload(void) {
if (netdata_cloud_setting)
aclk_single_update_disable();
#endif
+ sql_refresh_hashes();
+
rrd_rdlock();
RRDHOST *host;
diff --git a/health/health.h b/health/health.h
index 323279bac3..f25ae6bc63 100644
--- a/health/health.h
+++ b/health/health.h
@@ -87,6 +87,7 @@ extern void *health_cmdapi_thread(void *ptr);
extern void health_label_log_save(RRDHOST *host);
extern char *health_edit_command_from_source(const char *source);
+extern void sql_refresh_hashes(void);
extern SIMPLE_PATTERN *health_pattern_from_foreach(char *s);
diff --git a/health/health_config.c b/health/health_config.c
index da71f13d84..a49702bdd4 100644
--- a/health/health_config.c
+++ b/health/health_config.c
@@ -538,6 +538,7 @@ static inline void alert_config_free(struct alert_config *cfg)
freez(cfg);
}
+int sql_store_hashes = 1;
static int health_readfile(const char *filename, void *data) {
RRDHOST *host = (RRDHOST *)data;
@@ -662,7 +663,7 @@ static int health_readfile(const char *filename, void *data) {
if(hash == hash_alarm && !strcasecmp(key, HEALTH_ALARM_KEY)) {
if(rc) {
- if(ignore_this || !alert_hash_and_store_config(rc->config_hash_id, alert_cfg) || !rrdcalc_add_alarm_from_config(host, rc)) {
+ if(!alert_hash_and_store_config(rc->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalc_add_alarm_from_config(host, rc)) {
rrdcalc_free(rc);
alert_config_free(alert_cfg);
}
@@ -670,7 +671,7 @@ static int health_readfile(const char *filename, void *data) {
}
if(rt) {
- if (ignore_this || !alert_hash_and_store_config(rt->config_hash_id, alert_cfg) || !rrdcalctemplate_add_template_from_config(host, rt)) {
+ if (!alert_hash_and_store_config(rt->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalctemplate_add_template_from_config(host, rt)) {
rrdcalctemplate_free(rt);
alert_config_free(alert_cfg);
}
@@ -701,7 +702,7 @@ static int health_readfile(const char *filename, void *data) {
else if(hash == hash_template && !strcasecmp(key, HEALTH_TEMPLATE_KEY)) {
if(rc) {
// health_add_alarms_loop(host, rc, ignore_this) ;
- if(ignore_this || !alert_hash_and_store_config(rc->config_hash_id, alert_cfg) || !rrdcalc_add_alarm_from_config(host, rc)) {
+ if(!alert_hash_and_store_config(rc->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalc_add_alarm_from_config(host, rc)) {
rrdcalc_free(rc);
alert_config_free(alert_cfg);
}
@@ -710,7 +711,7 @@ static int health_readfile(const char *filename, void *data) {
}
if(rt) {
- if(ignore_this || !alert_hash_and_store_config(rt->config_hash_id, alert_cfg) || !rrdcalctemplate_add_template_from_config(host, rt)) {
+ if(!alert_hash_and_store_config(rt->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalctemplate_add_template_from_config(host, rt)) {
rrdcalctemplate_free(rt);
alert_config_free(alert_cfg);
}
@@ -1225,13 +1226,13 @@ static int health_readfile(const char *filename, void *data) {
if(rc) {
//health_add_alarms_loop(host, rc, ignore_this) ;
- if(ignore_this || !alert_hash_and_store_config(rc->config_hash_id, alert_cfg) || !rrdcalc_add_alarm_from_config(host, rc)) {
+ if(!alert_hash_and_store_config(rc->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalc_add_alarm_from_config(host, rc)) {
rrdcalc_free(rc);
}
}
if(rt) {
- if(ignore_this || !alert_hash_and_store_config(rt->config_hash_id, alert_cfg) || !rrdcalctemplate_add_template_from_config(host, rt)) {
+ if(!alert_hash_and_store_config(rt->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalctemplate_add_template_from_config(host, rt)) {
rrdcalctemplate_free(rt);
}
}
@@ -1243,6 +1244,11 @@ static int health_readfile(const char *filename, void *data) {
return 1;
}
+void sql_refresh_hashes(void)
+{
+ sql_store_hashes = 1;
+}
+
void health_readdir(RRDHOST *host, const char *user_path, const char *stock_path, const char *subpath) {
if(unlikely(!host->health_enabled)) {
debug(D_HEALTH, "CONFIG health is not enabled for host '%s'", host->hostname);
@@ -1258,4 +1264,5 @@ void health_readdir(RRDHOST *host, const char *user_path, const char *stock_path
}
recursive_config_double_dir_load(user_path, stock_path, subpath, health_readfile, (void *) host, 0);
+ sql_store_hashes = 0;
}