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
Emmanuel Vasilakis committed
Mar 11, 2022 at 10:49 UTC
4566c0835e99d1b00542ddbc1600450eb61a6a70
5 files changed
+21
-9
database/sqlite/sqlite_health.c
+4
-2
@@ -900,7 +900,8 @@ int sql_store_alert_config_hash(uuid_t *hash_id, struct alert_config *cfg)
900
#endif
901
int alert_hash_and_store_config(
902
uuid_t hash_id,
903
- struct alert_config *cfg)
903
+ struct alert_config *cfg,
904
+ int store_hash)
905
{
906
#if !defined DISABLE_CLOUD && defined ENABLE_HTTPS
907
EVP_MD_CTX *evpctx;
@@ -946,7 +947,8 @@ int alert_hash_and_store_config(
947
uuid_copy(hash_id, *((uuid_t *)&hash_value));
948
949
/* store everything, so it can be recreated when not in memory or just a subset ? */
949
- (void)sql_store_alert_config_hash( (uuid_t *)&hash_value, cfg);
950
+ if (store_hash)
951
+ (void)sql_store_alert_config_hash( (uuid_t *)&hash_value, cfg);
952
#else
953
UNUSED(hash_id);
954
UNUSED(cfg);
database/sqlite/sqlite_health.h
+1
-1
@@ -12,6 +12,6 @@ extern void sql_health_alarm_log_update(RRDHOST *host, ALARM_ENTRY *ae);
12
extern void sql_health_alarm_log_insert(RRDHOST *host, ALARM_ENTRY *ae);
13
extern void sql_health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae);
14
extern void sql_health_alarm_log_cleanup(RRDHOST *host);
15
-extern int alert_hash_and_store_config(uuid_t hash_id, struct alert_config *cfg);
15
+extern int alert_hash_and_store_config(uuid_t hash_id, struct alert_config *cfg, int store_hash);
16
extern void sql_aclk_alert_clean_dead_entries(RRDHOST *host);
17
#endif //NETDATA_SQLITE_HEALTH_H
health/health.c
+2
@@ -223,6 +223,8 @@ void health_reload(void) {
223
if (netdata_cloud_setting)
224
aclk_single_update_disable();
225
#endif
226
+ sql_refresh_hashes();
227
+
228
rrd_rdlock();
229
230
RRDHOST *host;
health/health.h
+1
@@ -87,6 +87,7 @@ extern void *health_cmdapi_thread(void *ptr);
87
extern void health_label_log_save(RRDHOST *host);
88
89
extern char *health_edit_command_from_source(const char *source);
90
+extern void sql_refresh_hashes(void);
91
92
extern SIMPLE_PATTERN *health_pattern_from_foreach(char *s);
93
health/health_config.c
+13
-6
@@ -538,6 +538,7 @@ static inline void alert_config_free(struct alert_config *cfg)
538
freez(cfg);
539
}
540
541
+int sql_store_hashes = 1;
542
static int health_readfile(const char *filename, void *data) {
543
RRDHOST *host = (RRDHOST *)data;
544
@@ -662,7 +663,7 @@ static int health_readfile(const char *filename, void *data) {
663
664
if(hash == hash_alarm && !strcasecmp(key, HEALTH_ALARM_KEY)) {
665
if(rc) {
665
- if(ignore_this || !alert_hash_and_store_config(rc->config_hash_id, alert_cfg) || !rrdcalc_add_alarm_from_config(host, rc)) {
666
+ if(!alert_hash_and_store_config(rc->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalc_add_alarm_from_config(host, rc)) {
667
rrdcalc_free(rc);
668
alert_config_free(alert_cfg);
669
}
@@ -670,7 +671,7 @@ static int health_readfile(const char *filename, void *data) {
671
}
672
673
if(rt) {
673
- if (ignore_this || !alert_hash_and_store_config(rt->config_hash_id, alert_cfg) || !rrdcalctemplate_add_template_from_config(host, rt)) {
674
+ if (!alert_hash_and_store_config(rt->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalctemplate_add_template_from_config(host, rt)) {
675
rrdcalctemplate_free(rt);
676
alert_config_free(alert_cfg);
677
}
@@ -701,7 +702,7 @@ static int health_readfile(const char *filename, void *data) {
702
else if(hash == hash_template && !strcasecmp(key, HEALTH_TEMPLATE_KEY)) {
703
if(rc) {
704
// health_add_alarms_loop(host, rc, ignore_this) ;
704
- if(ignore_this || !alert_hash_and_store_config(rc->config_hash_id, alert_cfg) || !rrdcalc_add_alarm_from_config(host, rc)) {
705
+ if(!alert_hash_and_store_config(rc->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalc_add_alarm_from_config(host, rc)) {
706
rrdcalc_free(rc);
707
alert_config_free(alert_cfg);
708
}
@@ -710,7 +711,7 @@ static int health_readfile(const char *filename, void *data) {
711
}
712
713
if(rt) {
713
- if(ignore_this || !alert_hash_and_store_config(rt->config_hash_id, alert_cfg) || !rrdcalctemplate_add_template_from_config(host, rt)) {
714
+ if(!alert_hash_and_store_config(rt->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalctemplate_add_template_from_config(host, rt)) {
715
rrdcalctemplate_free(rt);
716
alert_config_free(alert_cfg);
717
}
@@ -1225,13 +1226,13 @@ static int health_readfile(const char *filename, void *data) {
1226
1227
if(rc) {
1228
//health_add_alarms_loop(host, rc, ignore_this) ;
1228
- if(ignore_this || !alert_hash_and_store_config(rc->config_hash_id, alert_cfg) || !rrdcalc_add_alarm_from_config(host, rc)) {
1229
+ if(!alert_hash_and_store_config(rc->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalc_add_alarm_from_config(host, rc)) {
1230
rrdcalc_free(rc);
1231
}
1232
}
1233
1234
if(rt) {
1234
- if(ignore_this || !alert_hash_and_store_config(rt->config_hash_id, alert_cfg) || !rrdcalctemplate_add_template_from_config(host, rt)) {
1235
+ if(!alert_hash_and_store_config(rt->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalctemplate_add_template_from_config(host, rt)) {
1236
rrdcalctemplate_free(rt);
1237
}
1238
}
@@ -1243,6 +1244,11 @@ static int health_readfile(const char *filename, void *data) {
1244
return 1;
1245
}
1246
1247
+void sql_refresh_hashes(void)
1248
+{
1249
+ sql_store_hashes = 1;
1250
+}
1251
+
1252
void health_readdir(RRDHOST *host, const char *user_path, const char *stock_path, const char *subpath) {
1253
if(unlikely(!host->health_enabled)) {
1254
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
1264
}
1265
1266
recursive_config_double_dir_load(user_path, stock_path, subpath, health_readfile, (void *) host, 0);
1267
+ sql_store_hashes = 0;
1268
}