mirror of
https://github.com/netdata/netdata.git
synced 2025-04-17 11:12:42 +00:00
Remove strftime from statements and use unixepoch instead (#13250)
This commit is contained in:
parent
d40041406e
commit
36280fc2cf
7 changed files with 28 additions and 28 deletions
|
@ -23,11 +23,11 @@ const char *aclk_sync_config[] = {
|
|||
|
||||
"CREATE TRIGGER IF NOT EXISTS tr_dim_del AFTER DELETE ON dimension BEGIN INSERT INTO dimension_delete "
|
||||
"(dimension_id, dimension_name, chart_type_id, dim_id, chart_id, host_id, date_created)"
|
||||
" select old.id, old.name, c.type||\".\"||c.id, old.dim_id, old.chart_id, c.host_id, strftime('%s') FROM"
|
||||
" select old.id, old.name, c.type||\".\"||c.id, old.dim_id, old.chart_id, c.host_id, unixepoch() FROM"
|
||||
" chart c WHERE c.chart_id = old.chart_id; END;",
|
||||
|
||||
"DELETE FROM dimension_delete WHERE host_id NOT IN"
|
||||
" (SELECT host_id FROM host) OR strftime('%s') - date_created > 604800;",
|
||||
" (SELECT host_id FROM host) OR unixepoch() - date_created > 604800;",
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
@ -773,7 +773,7 @@ void sql_maint_aclk_sync_database(struct aclk_database_worker_config *wc, struct
|
|||
BUFFER *sql = buffer_create(ACLK_SYNC_QUERY_SIZE);
|
||||
|
||||
buffer_sprintf(sql,"DELETE FROM aclk_chart_%s WHERE date_submitted IS NOT NULL AND "
|
||||
"date_updated < strftime('%%s','now','-%d seconds');", wc->uuid_str, ACLK_DELETE_ACK_INTERNAL);
|
||||
"date_updated < unixepoch()-%d;", wc->uuid_str, ACLK_DELETE_ACK_INTERNAL);
|
||||
db_execute(buffer_tostring(sql));
|
||||
buffer_flush(sql);
|
||||
|
||||
|
@ -784,7 +784,7 @@ void sql_maint_aclk_sync_database(struct aclk_database_worker_config *wc, struct
|
|||
buffer_flush(sql);
|
||||
|
||||
buffer_sprintf(sql,"DELETE FROM aclk_alert_%s WHERE date_submitted IS NOT NULL AND "
|
||||
"date_cloud_ack < strftime('%%s','now','-%d seconds');", wc->uuid_str, ACLK_DELETE_ACK_ALERTS_INTERNAL);
|
||||
"date_cloud_ack < unixepoch()-%d;", wc->uuid_str, ACLK_DELETE_ACK_ALERTS_INTERNAL);
|
||||
db_execute(buffer_tostring(sql));
|
||||
|
||||
buffer_free(sql);
|
||||
|
@ -910,7 +910,7 @@ void sql_check_aclk_table_list(struct aclk_database_worker_config *wc)
|
|||
sqlite3_free(err_msg);
|
||||
}
|
||||
db_execute("DELETE FROM dimension_delete WHERE host_id NOT IN (SELECT host_id FROM host) "
|
||||
" OR strftime('%s') - date_created > 604800;");
|
||||
" OR unixepoch() - date_created > 604800;");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ static inline char *get_str_from_uuid(uuid_t *uuid)
|
|||
#define TRIGGER_ACLK_CHART_PAYLOAD "CREATE TRIGGER IF NOT EXISTS aclk_tr_chart_payload_%s " \
|
||||
"after insert on aclk_chart_payload_%s " \
|
||||
"begin insert into aclk_chart_%s (uuid, unique_id, type, status, date_created) values " \
|
||||
" (new.uuid, new.unique_id, new.type, 'pending', strftime('%%s')) on conflict(uuid, status) " \
|
||||
" (new.uuid, new.unique_id, new.type, 'pending', unixepoch()) on conflict(uuid, status) " \
|
||||
" do update set unique_id = new.unique_id, update_count = update_count + 1; " \
|
||||
"end;"
|
||||
|
||||
|
|
|
@ -149,7 +149,7 @@ int sql_queue_alarm_to_aclk(RRDHOST *host, ALARM_ENTRY *ae, int skip_filter)
|
|||
buffer_sprintf(
|
||||
sql,
|
||||
"INSERT INTO aclk_alert_%s (alert_unique_id, date_created) "
|
||||
"VALUES (@alert_unique_id, strftime('%%s')) on conflict (alert_unique_id) do nothing; ",
|
||||
"VALUES (@alert_unique_id, unixepoch()) on conflict (alert_unique_id) do nothing; ",
|
||||
uuid_str);
|
||||
|
||||
rc = sqlite3_prepare_v2(db_meta, buffer_tostring(sql), -1, &res_alert, 0);
|
||||
|
@ -239,9 +239,9 @@ void aclk_push_alert_event(struct aclk_database_worker_config *wc, struct aclk_d
|
|||
buffer_sprintf(
|
||||
sql,
|
||||
"UPDATE aclk_alert_%s SET date_submitted = NULL, date_cloud_ack = NULL WHERE sequence_id >= %"PRIu64
|
||||
"; UPDATE aclk_alert_%s SET date_cloud_ack = strftime('%%s','now') WHERE sequence_id < %"PRIu64
|
||||
"; UPDATE aclk_alert_%s SET date_cloud_ack = unixepoch() WHERE sequence_id < %"PRIu64
|
||||
" and date_cloud_ack is null "
|
||||
"; UPDATE aclk_alert_%s SET date_submitted = strftime('%%s','now') WHERE sequence_id < %"PRIu64
|
||||
"; UPDATE aclk_alert_%s SET date_submitted = unixepoch() WHERE sequence_id < %"PRIu64
|
||||
" and date_submitted is null",
|
||||
wc->uuid_str,
|
||||
wc->alerts_start_seq_id,
|
||||
|
@ -361,7 +361,7 @@ void aclk_push_alert_event(struct aclk_database_worker_config *wc, struct aclk_d
|
|||
|
||||
if (first_sequence_id) {
|
||||
buffer_flush(sql);
|
||||
buffer_sprintf(sql, "UPDATE aclk_alert_%s SET date_submitted=strftime('%%s') "
|
||||
buffer_sprintf(sql, "UPDATE aclk_alert_%s SET date_submitted=unixepoch() "
|
||||
"WHERE date_submitted IS NULL AND sequence_id BETWEEN %" PRIu64 " AND %" PRIu64 ";",
|
||||
wc->uuid_str, first_sequence_id, last_sequence_id);
|
||||
db_execute(buffer_tostring(sql));
|
||||
|
@ -397,7 +397,7 @@ void sql_queue_existing_alerts_to_aclk(RRDHOST *host)
|
|||
BUFFER *sql = buffer_create(1024);
|
||||
|
||||
buffer_sprintf(sql,"insert into aclk_alert_%s (alert_unique_id, date_created) " \
|
||||
"select unique_id alert_unique_id, strftime('%%s') date_created from health_log_%s " \
|
||||
"select unique_id alert_unique_id, unixepoch() from health_log_%s " \
|
||||
"where new_status <> 0 and new_status <> -2 and config_hash_id is not null and updated_by_id = 0 " \
|
||||
"order by unique_id asc on conflict (alert_unique_id) do nothing;", uuid_str, uuid_str);
|
||||
|
||||
|
@ -737,7 +737,7 @@ void sql_process_queue_removed_alerts_to_aclk(struct aclk_database_worker_config
|
|||
BUFFER *sql = buffer_create(1024);
|
||||
|
||||
buffer_sprintf(sql,"insert into aclk_alert_%s (alert_unique_id, date_created) " \
|
||||
"select unique_id alert_unique_id, strftime('%%s') date_created from health_log_%s " \
|
||||
"select unique_id alert_unique_id, unixepoch() from health_log_%s " \
|
||||
"where new_status = -2 and updated_by_id = 0 and unique_id not in " \
|
||||
"(select alert_unique_id from aclk_alert_%s) order by unique_id asc " \
|
||||
"on conflict (alert_unique_id) do nothing;", wc->uuid_str, wc->uuid_str, wc->uuid_str);
|
||||
|
@ -819,7 +819,7 @@ void aclk_mark_alert_cloud_ack(char *uuid_str, uint64_t alerts_ack_sequence_id)
|
|||
if (alerts_ack_sequence_id != 0) {
|
||||
buffer_sprintf(
|
||||
sql,
|
||||
"UPDATE aclk_alert_%s SET date_cloud_ack = strftime('%%s','now') WHERE sequence_id <= %" PRIu64 "",
|
||||
"UPDATE aclk_alert_%s SET date_cloud_ack = unixepoch() WHERE sequence_id <= %" PRIu64 "",
|
||||
uuid_str,
|
||||
alerts_ack_sequence_id);
|
||||
db_execute(buffer_tostring(sql));
|
||||
|
|
|
@ -87,7 +87,7 @@ static int aclk_add_chart_payload(
|
|||
char sql[ACLK_SYNC_QUERY_SIZE];
|
||||
snprintfz(sql,ACLK_SYNC_QUERY_SIZE-1,
|
||||
"INSERT INTO aclk_chart_payload_%s (unique_id, uuid, claim_id, date_created, type, payload) " \
|
||||
"VALUES (@unique_id, @uuid, @claim_id, strftime('%%s','now'), @type, @payload);", wc->uuid_str);
|
||||
"VALUES (@unique_id, @uuid, @claim_id, unixepoch(), @type, @payload);", wc->uuid_str);
|
||||
rc = prepare_statement(db_meta, sql, &res_chart);
|
||||
if (rc != SQLITE_OK) {
|
||||
error_report("Failed to prepare statement to store chart payload data");
|
||||
|
@ -398,7 +398,7 @@ void aclk_send_chart_event(struct aclk_database_worker_config *wc, struct aclk_d
|
|||
if (likely(first_sequence)) {
|
||||
|
||||
db_lock();
|
||||
snprintfz(sql,ACLK_SYNC_QUERY_SIZE-1, "UPDATE aclk_chart_%s SET status = NULL, date_submitted=strftime('%%s','now') "
|
||||
snprintfz(sql,ACLK_SYNC_QUERY_SIZE-1, "UPDATE aclk_chart_%s SET status = NULL, date_submitted=unixepoch() "
|
||||
"WHERE date_submitted IS NULL AND sequence_id BETWEEN %" PRIu64 " AND %" PRIu64 ";",
|
||||
wc->uuid_str, first_sequence, last_sequence);
|
||||
db_execute(sql);
|
||||
|
@ -540,7 +540,7 @@ void aclk_receive_chart_ack(struct aclk_database_worker_config *wc, struct aclk_
|
|||
|
||||
char sql[ACLK_SYNC_QUERY_SIZE];
|
||||
|
||||
snprintfz(sql,ACLK_SYNC_QUERY_SIZE-1,"UPDATE aclk_chart_%s SET date_updated=strftime('%%s','now') WHERE sequence_id <= @sequence_id "
|
||||
snprintfz(sql,ACLK_SYNC_QUERY_SIZE-1,"UPDATE aclk_chart_%s SET date_updated=unixepoch() WHERE sequence_id <= @sequence_id "
|
||||
"AND date_submitted IS NOT NULL AND date_updated IS NULL;", wc->uuid_str);
|
||||
|
||||
rc = sqlite3_prepare_v2(db_meta, sql, -1, &res, 0);
|
||||
|
|
|
@ -42,14 +42,14 @@ const char *database_config[] = {
|
|||
"WHERE ch.hash_id = chm.hash_id;",
|
||||
|
||||
"CREATE TRIGGER IF NOT EXISTS ins_host AFTER INSERT ON host BEGIN INSERT INTO node_instance (host_id, date_created)"
|
||||
" SELECT new.host_id, strftime(\"%s\") WHERE new.host_id NOT IN (SELECT host_id FROM node_instance); END;",
|
||||
" SELECT new.host_id, unixepoch() WHERE new.host_id NOT IN (SELECT host_id FROM node_instance); END;",
|
||||
|
||||
"CREATE TRIGGER IF NOT EXISTS tr_v_chart_hash INSTEAD OF INSERT on v_chart_hash BEGIN "
|
||||
"INSERT INTO chart_hash (hash_id, type, id, name, family, context, title, unit, plugin, "
|
||||
"module, priority, chart_type, last_used) "
|
||||
"values (new.hash_id, new.type, new.id, new.name, new.family, new.context, new.title, new.unit, new.plugin, "
|
||||
"new.module, new.priority, new.chart_type, strftime('%s')) "
|
||||
"ON CONFLICT (hash_id) DO UPDATE SET last_used = strftime('%s'); "
|
||||
"new.module, new.priority, new.chart_type, unixepoch()) "
|
||||
"ON CONFLICT (hash_id) DO UPDATE SET last_used = unixepoch(); "
|
||||
"INSERT INTO chart_hash_map (chart_id, hash_id) values (new.chart_id, new.hash_id) "
|
||||
"on conflict (chart_id, hash_id) do nothing; END; ",
|
||||
|
||||
|
@ -1444,7 +1444,7 @@ int file_is_migrated(char *path)
|
|||
}
|
||||
|
||||
#define STORE_MIGRATED_FILE "insert or replace into metadata_migration (filename, file_size, date_created) " \
|
||||
"values (@file, @size, strftime('%s'));"
|
||||
"values (@file, @size, unixepoch());"
|
||||
|
||||
void add_migrated_file(char *path, uint64_t file_size)
|
||||
{
|
||||
|
@ -1481,7 +1481,7 @@ void add_migrated_file(char *path, uint64_t file_size)
|
|||
|
||||
#define SQL_INS_CHART_LABEL "insert or replace into chart_label " \
|
||||
"(chart_id, source_type, label_key, label_value, date_created) " \
|
||||
"values (@chart, @source, @label, @value, strftime('%s'));"
|
||||
"values (@chart, @source, @label, @value, unixepoch());"
|
||||
|
||||
void sql_store_chart_label(uuid_t *chart_uuid, int source_type, char *label, char *value)
|
||||
{
|
||||
|
@ -1740,7 +1740,7 @@ failed:
|
|||
|
||||
#define SQL_STORE_CHART_HASH "insert into v_chart_hash (hash_id, type, id, " \
|
||||
"name, family, context, title, unit, plugin, module, priority, chart_type, last_used, chart_id) " \
|
||||
"values (?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,?11, ?12, strftime('%s'), ?13);"
|
||||
"values (?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,?11, ?12, unixepoch(), ?13);"
|
||||
|
||||
int sql_store_chart_hash(
|
||||
uuid_t *hash_id, uuid_t *chart_id, const char *type, const char *id, const char *name, const char *family,
|
||||
|
@ -1911,7 +1911,7 @@ void compute_chart_hash(RRDSET *st)
|
|||
}
|
||||
|
||||
#define SQL_STORE_CLAIM_ID "insert into node_instance " \
|
||||
"(host_id, claim_id, date_created) values (@host_id, @claim_id, strftime('%s')) " \
|
||||
"(host_id, claim_id, date_created) values (@host_id, @claim_id, unixepoch()) " \
|
||||
"on conflict(host_id) do update set claim_id = excluded.claim_id;"
|
||||
|
||||
void store_claim_id(uuid_t *host_id, uuid_t *claim_id)
|
||||
|
|
|
@ -38,7 +38,7 @@ typedef enum db_check_action_type {
|
|||
"select chart_id from chart where host_id = @host and type=@type and id=@id and (name is null or name=@name);"
|
||||
|
||||
#define SQL_STORE_ACTIVE_CHART \
|
||||
"insert or replace into chart_active (chart_id, date_created) values (@id, strftime('%s'));"
|
||||
"insert or replace into chart_active (chart_id, date_created) values (@id, unixepoch());"
|
||||
|
||||
#define SQL_STORE_DIMENSION \
|
||||
"INSERT OR REPLACE into dimension (dim_id, chart_id, id, name, multiplier, divisor , algorithm) values (?0001,?0002,?0003,?0004,?0005,?0006,?0007);"
|
||||
|
@ -47,7 +47,7 @@ typedef enum db_check_action_type {
|
|||
"select dim_id from dimension where chart_id=@chart and id=@id and name=@name and length(dim_id)=16;"
|
||||
|
||||
#define SQL_STORE_ACTIVE_DIMENSION \
|
||||
"insert or replace into dimension_active (dim_id, date_created) values (@id, strftime('%s'));"
|
||||
"insert or replace into dimension_active (dim_id, date_created) values (@id, unixepoch());"
|
||||
|
||||
#define CHECK_SQLITE_CONNECTION(db_meta) \
|
||||
if (unlikely(!db_meta)) { \
|
||||
|
|
|
@ -435,8 +435,8 @@ void sql_health_alarm_log_count(RRDHOST *host) {
|
|||
|
||||
#define SQL_INJECT_REMOVED(guid, guid2) "insert into health_log_%s (hostname, unique_id, alarm_id, alarm_event_id, config_hash_id, updated_by_id, updates_id, when_key, duration, non_clear_duration, flags, exec_run_timestamp, " \
|
||||
"delay_up_to_timestamp, name, chart, family, exec, recipient, source, units, info, exec_code, new_status, old_status, delay, new_value, old_value, last_repeat, class, component, type) " \
|
||||
"select hostname, ?1, ?2, ?3, config_hash_id, 0, ?4, strftime('%%s'), 0, 0, flags, exec_run_timestamp, " \
|
||||
"strftime('%%s'), name, chart, family, exec, recipient, source, units, info, exec_code, -2, new_status, delay, NULL, new_value, 0, class, component, type " \
|
||||
"select hostname, ?1, ?2, ?3, config_hash_id, 0, ?4, unixepoch(), 0, 0, flags, exec_run_timestamp, " \
|
||||
"unixepoch(), name, chart, family, exec, recipient, source, units, info, exec_code, -2, new_status, delay, NULL, new_value, 0, class, component, type " \
|
||||
"from health_log_%s where unique_id = ?5", guid, guid2
|
||||
#define SQL_INJECT_REMOVED_UPDATE(guid) "update health_log_%s set flags = flags | ?1, updated_by_id = ?2 where unique_id = ?3; ", guid
|
||||
void sql_inject_removed_status(char *uuid_str, uint32_t alarm_id, uint32_t alarm_event_id, uint32_t unique_id, uint32_t max_unique_id)
|
||||
|
@ -814,7 +814,7 @@ void sql_health_alarm_log_load(RRDHOST *host) {
|
|||
"on_key, class, component, type, os, hosts, lookup, every, units, calc, families, plugin, module, " \
|
||||
"charts, green, red, warn, crit, exec, to_key, info, delay, options, repeat, host_labels, " \
|
||||
"p_db_lookup_dimensions, p_db_lookup_method, p_db_lookup_options, p_db_lookup_after, " \
|
||||
"p_db_lookup_before, p_update_every) values (?1,strftime('%s'),?2,?3,?4,?5,?6,?7,?8,?9,?10,?11,?12," \
|
||||
"p_db_lookup_before, p_update_every) values (?1,unixepoch(),?2,?3,?4,?5,?6,?7,?8,?9,?10,?11,?12," \
|
||||
"?13,?14,?15,?16,?17,?18,?19,?20,?21,?22,?23,?24,?25,?26,?27,?28,?29,?30,?31,?32,?33,?34);"
|
||||
|
||||
int sql_store_alert_config_hash(uuid_t *hash_id, struct alert_config *cfg)
|
||||
|
|
Loading…
Add table
Reference in a new issue