diff options
author | Costa Tsaousis <costa@netdata.cloud> | 2023-07-06 14:43:01 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-06 14:43:01 +0300 |
commit | 6526a34f86e646610eed4a26215f5b40dfe718ab (patch) | |
tree | 544fc0413f8f4ce2fbe669a4d747f69b3e545a81 /database | |
parent | 328ce0938ac12fa61c1dcfa6f9e70c1ef07af83a (diff) |
fix alerts transitions sorting (#15315)
Diffstat (limited to 'database')
-rw-r--r-- | database/contexts/api_v2.c | 20 | ||||
-rw-r--r-- | database/sqlite/sqlite_health.c | 2 |
2 files changed, 16 insertions, 6 deletions
diff --git a/database/contexts/api_v2.c b/database/contexts/api_v2.c index 1e4ae53673..91bbcb33c6 100644 --- a/database/contexts/api_v2.c +++ b/database/contexts/api_v2.c @@ -1431,25 +1431,27 @@ static inline void contexts_v2_alert_transition_keep(struct alert_transitions_ca } struct sql_alert_transition_data *last = d->last_added; - while(last != d->base && last->prev->global_id > t->global_id) { + while(last->prev != d->base->prev && t->global_id > last->prev->global_id) { last = last->prev; d->stats.backwards++; } - while(last->next && last->next->global_id < t->global_id) { + while(last->next && t->global_id < last->next->global_id) { last = last->next; d->stats.forwards++; } - if(d->items >= d->limit && last == d->base->prev && last->global_id < t->global_id) { - d->stats.skips_after++; - return; + if(d->items >= d->limit) { + if(last == d->base->prev && t->global_id < last->global_id) { + d->stats.skips_after++; + return; + } } d->items++; d->last_added = contexts_v2_alert_transition_dup(t, machine_guid); - if(last->global_id > t->global_id) { + if(t->global_id > last->global_id) { DOUBLE_LINKED_LIST_PREPEND_ITEM_UNSAFE(d->base, d->last_added, prev, next); d->stats.prepend++; } @@ -1606,10 +1608,16 @@ static void contexts_v2_alert_transitions_to_json(BUFFER *wb, struct rrdcontext_ for(struct sql_alert_transition_data *t = data.base; t ; t = t->next) { buffer_json_add_array_item_object(wb); { + RRDHOST *host = rrdhost_find_by_guid(t->machine_guid); + buffer_json_member_add_uint64(wb, "gi", t->global_id); buffer_json_member_add_uuid(wb, "transition_id", t->transition_id); buffer_json_member_add_uuid(wb, "config_hash_id", t->config_hash_id); buffer_json_member_add_string(wb, "machine_guid", t->machine_guid); + + if(host && host->node_id) + buffer_json_member_add_uuid(wb, "node_id", host->node_id); + buffer_json_member_add_string(wb, "alert", t->alert_name); buffer_json_member_add_string(wb, "instance", t->chart); buffer_json_member_add_string(wb, "context", t->chart_context); diff --git a/database/sqlite/sqlite_health.c b/database/sqlite/sqlite_health.c index 1ddc6a00d5..cca6e051e9 100644 --- a/database/sqlite/sqlite_health.c +++ b/database/sqlite/sqlite_health.c @@ -1846,6 +1846,8 @@ void sql_alert_transitions( if (alert_name) buffer_sprintf(command, " AND h.name = @alert_name"); + buffer_strcat(command, " ORDER BY d.global_id DESC"); + rc = sqlite3_prepare_v2(db_meta, buffer_tostring(command), -1, &res, 0); if (unlikely(rc != SQLITE_OK)) { error_report("Failed to prepare statement sql_alert_transitions"); |