Skip to content

Commit faab6be

Browse files
stelfragMrZammler
authored andcommitted
Misc code cleanup (netdata#15665)
* Cleanup code * Add SQLITE3_COLUMN_STRDUPZ_OR_NULL for readability * Bind unique id properly * Cleanup with is_claimed parameter to decide which cleanup to use Unify cleanup function sql_health_alarm_log_cleanup Add SQLITE3_BIND_STRING_OR_NULL and SQLITE3_COLUMN_STRINGDUP_OR_NULL sql_health_alarm_log_count returns number of rows instead of updating host->health.health_log_entries_written Reformat queries for clarity * Try to fix codacy issue * Try to fix codacy issue -- issue small warning * Change label from fail to done * Drop index on unique_id and health_log_id and create one on both * Update database/sqlite/sqlite_aclk_alert.c Co-authored-by: Emmanuel Vasilakis <[email protected]> * Fix double bind --------- Co-authored-by: Emmanuel Vasilakis <[email protected]>
1 parent d4dd633 commit faab6be

File tree

8 files changed

+475
-580
lines changed

8 files changed

+475
-580
lines changed

database/rrd.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -716,13 +716,6 @@ STORAGE_ENGINE* storage_engine_find(const char* name);
716716

717717
#define rrddim_foreach_read(rd, st) \
718718
dfe_start_read((st)->rrddim_root_index, rd)
719-
720-
#define rrddim_foreach_write(rd, st) \
721-
dfe_start_write((st)->rrddim_root_index, rd)
722-
723-
#define rrddim_foreach_reentrant(rd, st) \
724-
dfe_start_reentrant((st)->rrddim_root_index, rd)
725-
726719
#define rrddim_foreach_done(rd) \
727720
dfe_done(rd)
728721

@@ -1094,8 +1087,6 @@ struct alarm_entry {
10941087
#define ae_chart_context(ae) string2str((ae)->chart_context)
10951088
#define ae_family(ae) string2str((ae)->family)
10961089
#define ae_classification(ae) string2str((ae)->classification)
1097-
#define ae_component(ae) string2str((ae)->component)
1098-
#define ae_type(ae) string2str((ae)->type)
10991090
#define ae_exec(ae) string2str((ae)->exec)
11001091
#define ae_recipient(ae) string2str((ae)->recipient)
11011092
#define ae_source(ae) string2str((ae)->source)
@@ -1115,13 +1106,13 @@ typedef struct alarm_log {
11151106
} ALARM_LOG;
11161107

11171108
typedef struct health {
1118-
unsigned int health_enabled; // 1 when this host has health enabled
11191109
time_t health_delay_up_to; // a timestamp to delay alarms processing up to
11201110
STRING *health_default_exec; // the full path of the alarms notifications program
11211111
STRING *health_default_recipient; // the default recipient for all alarms
1122-
size_t health_log_entries_written; // the number of alarm events written to the alarms event log
1112+
int health_log_entries_written; // the number of alarm events written to the alarms event log
11231113
uint32_t health_default_warn_repeat_every; // the default value for the interval between repeating warning notifications
11241114
uint32_t health_default_crit_repeat_every; // the default value for the interval between repeating critical notifications
1115+
unsigned int health_enabled; // 1 when this host has health enabled
11251116
} HEALTH;
11261117

11271118
// ----------------------------------------------------------------------------

database/sqlite/sqlite_aclk_alert.c

Lines changed: 157 additions & 141 deletions
Large diffs are not rendered by default.

database/sqlite/sqlite_aclk_alert.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ struct proto_alert_status {
1515
uint64_t last_submitted_sequence_id;
1616
};
1717

18-
int aclk_add_alert_event(struct aclk_sync_host_config *wc, struct aclk_database_cmd cmd);
1918
void aclk_push_alert_event(struct aclk_sync_host_config *wc);
2019
void aclk_send_alarm_configuration (char *config_hash);
2120
int aclk_push_alert_config_event(char *node_id, char *config_hash);
@@ -28,8 +27,7 @@ void aclk_push_alarm_checkpoint(RRDHOST *host);
2827
void aclk_push_alert_snapshot_event(char *node_id);
2928
void aclk_process_send_alarm_snapshot(char *node_id, char *claim_id, char *snapshot_uuid);
3029
int get_proto_alert_status(RRDHOST *host, struct proto_alert_status *proto_alert_status);
31-
int sql_queue_alarm_to_aclk(RRDHOST *host, ALARM_ENTRY *ae, int skip_filter);
30+
void sql_queue_alarm_to_aclk(RRDHOST *host, ALARM_ENTRY *ae, bool skip_filter);
3231
void aclk_push_alert_events_for_all_hosts(void);
3332

34-
3533
#endif //NETDATA_SQLITE_ACLK_ALERT_H

database/sqlite/sqlite_functions.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ const char *database_config[] = {
5555
"info text, exec_code int, new_status real, old_status real, delay int, "
5656
"new_value double, old_value double, last_repeat int, transition_id blob, global_id int);",
5757

58-
"CREATE INDEX IF NOT EXISTS health_log_d_ind_1 ON health_log_detail (unique_id);",
5958
"CREATE INDEX IF NOT EXISTS health_log_d_ind_2 ON health_log_detail (global_id);",
6059
"CREATE INDEX IF NOT EXISTS health_log_d_ind_3 ON health_log_detail (transition_id);",
61-
"CREATE INDEX IF NOT EXISTS health_log_d_ind_4 ON health_log_detail (health_log_id);",
60+
"CREATE INDEX IF NOT EXISTS health_log_d_ind_5 ON health_log_detail (health_log_id, unique_id DESC);",
6261

6362
NULL
6463
};
@@ -74,6 +73,8 @@ const char *database_cleanup[] = {
7473
"DROP INDEX IF EXISTS ind_c1;",
7574
"DROP INDEX IF EXISTS ind_c2;",
7675
"DROP INDEX IF EXISTS alert_hash_index;",
76+
"DROP INDEX IF EXISTS health_log_d_ind_4;",
77+
"DROP INDEX IF EXISTS health_log_d_ind_1;",
7778
NULL
7879
};
7980

0 commit comments

Comments
 (0)