@cryptotaxi247 / netdata-1 / commits / 3cdedeed4

add chart id and name to alert instances and transitions (#15430)

Costa Tsaousis committed Jul 18, 2023 at 15:37 UTC 3cdedeed4030f10bb98d0893878b19d23443aed5
5 files changed +59 -76
database/contexts/api_v2.c
+38 -13
@@ -9,41 +9,59 @@
9
10 struct alert_transitions_facets alert_transition_facets[] = {
11 [ATF_STATUS] = {
12 - .id = "status",
12 + .id = "f_status",
13 .name = "Alert Status",
14 - .query_param = "status",
14 + .query_param = "f_status",
15 .order = 1,
16 },
17 [ATF_TYPE] = {
18 - .id = "type",
18 + .id = "f_type",
19 .name = "Alert Type",
20 - .query_param = "type",
20 + .query_param = "f_type",
21 .order = 2,
22 },
23 [ATF_ROLE] = {
24 - .id = "role",
24 + .id = "f_role",
25 .name = "Recipient Role",
26 - .query_param = "role",
26 + .query_param = "f_role",
27 .order = 3,
28 },
29 [ATF_CLASS] = {
30 - .id = "class",
30 + .id = "f_class",
31 .name = "Alert Class",
32 - .query_param = "class",
32 + .query_param = "f_class",
33 .order = 4,
34 },
35 [ATF_COMPONENT] = {
36 - .id = "component",
36 + .id = "f_component",
37 .name = "Alert Component",
38 - .query_param = "component",
38 + .query_param = "f_component",
39 .order = 5,
40 },
41 [ATF_NODE] = {
42 - .id = "node",
42 + .id = "f_node",
43 .name = "Alert Node",
44 - .query_param = "node",
44 + .query_param = "f_node",
45 .order = 6,
46 },
47 + [ATF_ALERT_NAME] = {
48 + .id = "f_alert",
49 + .name = "Alert Name",
50 + .query_param = "f_alert",
51 + .order = 7,
52 + },
53 + [ATF_CHART_NAME] = {
54 + .id = "f_instance",
55 + .name = "Instance Name",
56 + .query_param = "f_instance",
57 + .order = 8,
58 + },
59 + [ATF_CONTEXT] = {
60 + .id = "f_context",
61 + .name = "Context",
62 + .query_param = "f_context",
63 + .order = 9,
64 + },
65
66 // terminator
67 [ATF_TOTAL_ENTRIES] = {
@@ -1300,7 +1318,8 @@ static int contexts_v2_alert_instance_to_json_callback(const DICTIONARY_ITEM *it
1318 buffer_json_member_add_uint64(wb, "ni", t->ni);
1319
1320 buffer_json_member_add_string(wb, "nm", string2str(t->name));
1303 - buffer_json_member_add_string(wb, "ch", string2str(t->chart_name));
1321 + buffer_json_member_add_string(wb, "ch", string2str(t->chart_id));
1322 + buffer_json_member_add_string(wb, "ch_n", string2str(t->chart_name));
1323
1324 if(ctl->request->options & CONTEXT_V2_OPTION_ALERTS_WITH_SUMMARY)
1325 buffer_json_member_add_uint64(wb, "ati", t->ati);
@@ -1392,6 +1411,7 @@ struct sql_alert_transition_fixed_size {
1411 uint32_t alarm_id;
1412 char alert_name[SQL_TRANSITION_DATA_SMALL_STRING];
1413 char chart[RRD_ID_LENGTH_MAX];
1414 + char chart_name[RRD_ID_LENGTH_MAX];
1415 char chart_context[SQL_TRANSITION_DATA_MEDIUM_STRING];
1416 char family[SQL_TRANSITION_DATA_SMALL_STRING];
1417 char recipient[SQL_TRANSITION_DATA_MEDIUM_STRING];
@@ -1430,6 +1450,7 @@ static struct sql_alert_transition_fixed_size *contexts_v2_alert_transition_dup(
1450 n->alarm_id = t->alarm_id;
1451 strncpyz(n->alert_name, t->alert_name ? t->alert_name : "", sizeof(n->alert_name) - 1);
1452 strncpyz(n->chart, t->chart ? t->chart : "", sizeof(n->chart) - 1);
1453 + strncpyz(n->chart_name, t->chart_name ? t->chart_name : n->chart, sizeof(n->chart_name) - 1);
1454 strncpyz(n->chart_context, t->chart_context ? t->chart_context : "", sizeof(n->chart_context) - 1);
1455 strncpyz(n->family, t->family ? t->family : "", sizeof(n->family) - 1);
1456 strncpyz(n->recipient, t->recipient ? t->recipient : "", sizeof(n->recipient) - 1);
@@ -1547,6 +1568,9 @@ static void contexts_v2_alert_transition_callback(struct sql_alert_transition_da
1568 [ATF_COMPONENT] = t->component,
1569 [ATF_ROLE] = t->recipient && *t->recipient ? t->recipient : string2str(localhost->health.health_default_recipient),
1570 [ATF_NODE] = machine_guid,
1571 + [ATF_ALERT_NAME] = t->alert_name,
1572 + [ATF_CHART_NAME] = t->chart_name,
1573 + [ATF_CONTEXT] = t->chart_context,
1574 };
1575
1576 for(size_t i = 0; i < ATF_TOTAL_ENTRIES ;i++) {
@@ -1681,6 +1705,7 @@ static void contexts_v2_alert_transitions_to_json(BUFFER *wb, struct rrdcontext_
1705
1706 buffer_json_member_add_string(wb, "alert", *t->alert_name ? t->alert_name : NULL);
1707 buffer_json_member_add_string(wb, "instance", *t->chart ? t->chart : NULL);
1708 + buffer_json_member_add_string(wb, "instance_n", *t->chart_name ? t->chart_name : NULL);
1709 buffer_json_member_add_string(wb, "context", *t->chart_context ? t->chart_context : NULL);
1710 // buffer_json_member_add_string(wb, "family", *t->family ? t->family : NULL);
1711 buffer_json_member_add_string(wb, "component", *t->component ? t->component : NULL);
database/contexts/rrdcontext.h
+4
@@ -424,6 +424,7 @@ struct sql_alert_transition_data {
424 uint32_t alarm_id;
425 const char *alert_name;
426 const char *chart;
427 + const char *chart_name;
428 const char *chart_context;
429 const char *family;
430 const char *recipient;
@@ -589,6 +590,9 @@ typedef enum __attribute__((packed)) {
590 ATF_COMPONENT,
591 ATF_ROLE,
592 ATF_NODE,
593 + ATF_ALERT_NAME,
594 + ATF_CHART_NAME,
595 + ATF_CONTEXT,
596
597 // total
598 ATF_TOTAL_ENTRIES,
database/sqlite/sqlite_health.c
+14 -8
@@ -1766,16 +1766,21 @@ fail:
1766
1767 #define SQL_POPULATE_TEMP_ALERT_TRANSITION_TABLE "INSERT INTO v_%p (host_id) VALUES (@host_id)"
1768
1769 -#define SQL_SEARCH_ALERT_TRANSITION "SELECT h.host_id, h.alarm_id, h.config_hash_id, h.name, h.chart, h.family, h.recipient, h.units, h.exec, h.chart_context, d.when_key, " \
1770 - "d.duration, d.non_clear_duration, d.flags, d.delay_up_to_timestamp, d.info, d.exec_code, d.new_status, d.old_status, d.delay, " \
1771 - " d.new_value, d.old_value, d.last_repeat, d.transition_id, d.global_id, ah.class, ah.type, ah.component FROM health_log h, health_log_detail d, v_%p t, alert_hash ah " \
1772 - " WHERE h.host_id = t.host_id AND h.config_hash_id = ah.hash_id AND h.health_log_id = d.health_log_id AND d.global_id BETWEEN @after AND @before "
1769 +#define SQL_SEARCH_ALERT_TRANSITION_SELECT "SELECT " \
1770 + "h.host_id, h.alarm_id, h.config_hash_id, h.name, h.chart, h.family, h.recipient, h.units, h.exec, " \
1771 + "h.chart_context, d.when_key, d.duration, d.non_clear_duration, d.flags, d.delay_up_to_timestamp, " \
1772 + "d.info, d.exec_code, d.new_status, d.old_status, d.delay, d.new_value, d.old_value, d.last_repeat, " \
1773 + "d.transition_id, d.global_id, ah.class, ah.type, ah.component, d.exec_run_timestamp"
1774
1775 +#define SQL_SEARCH_ALERT_TRANSITION_COMMON_WHERE \
1776 + "h.config_hash_id = ah.hash_id AND h.health_log_id = d.health_log_id" \
1777 + " AND ( d.new_status > 2 OR d.old_status > 2 )"
1778
1775 -#define SQL_SEARCH_ALERT_TRANSITION_DIRECT "SELECT h.host_id, h.alarm_id, h.config_hash_id, h.name, h.chart, h.family, h.recipient, h.units, h.exec, h.chart_context, d.when_key, " \
1776 - "d.duration, d.non_clear_duration, d.flags, d.delay_up_to_timestamp, d.info, d.exec_code, d.new_status, d.old_status, d.delay, " \
1777 - " d.new_value, d.old_value, d.last_repeat, d.transition_id, d.global_id, ah.class, ah.type, ah.component, d.exec_run_timestamp FROM health_log h, health_log_detail d, alert_hash ah " \
1778 - " WHERE h.config_hash_id = ah.hash_id AND h.health_log_id = d.health_log_id AND transition_id = @transition "
1779 +#define SQL_SEARCH_ALERT_TRANSITION SQL_SEARCH_ALERT_TRANSITION_SELECT " FROM health_log h, health_log_detail d, v_%p t, alert_hash ah " \
1780 + " WHERE h.host_id = t.host_id AND " SQL_SEARCH_ALERT_TRANSITION_COMMON_WHERE " AND d.global_id BETWEEN @after AND @before "
1781 +
1782 +#define SQL_SEARCH_ALERT_TRANSITION_DIRECT SQL_SEARCH_ALERT_TRANSITION_SELECT " FROM health_log h, health_log_detail d, alert_hash ah " \
1783 + " WHERE " SQL_SEARCH_ALERT_TRANSITION_COMMON_WHERE " AND transition_id = @transition "
1784
1785 void sql_alert_transitions(
1786 DICTIONARY *nodes,
@@ -1909,6 +1914,7 @@ run_query:;
1914 atd.config_hash_id = (uuid_t *)sqlite3_column_blob(res, 2);
1915 atd.alert_name = (const char *) sqlite3_column_text(res, 3);
1916 atd.chart = (const char *) sqlite3_column_text(res, 4);
1917 + atd.chart_name = (const char *) sqlite3_column_text(res, 4); // FIXME don't copy the id, find the name
1918 atd.family = (const char *) sqlite3_column_text(res, 5);
1919 atd.recipient = (const char *) sqlite3_column_text(res, 6);
1920 atd.units = (const char *) sqlite3_column_text(res, 7);
libnetdata/eval/eval.h
+3 -3
@@ -12,9 +12,9 @@ typedef enum rrdcalc_status {
12 RRDCALC_STATUS_UNDEFINED = -1,
13 RRDCALC_STATUS_UNINITIALIZED = 0,
14 RRDCALC_STATUS_CLEAR = 1,
15 - RRDCALC_STATUS_RAISED = 2,
16 - RRDCALC_STATUS_WARNING = 3,
17 - RRDCALC_STATUS_CRITICAL = 4
15 + RRDCALC_STATUS_RAISED = 2, // DO NOT CHANGE THESE NUMBERS
16 + RRDCALC_STATUS_WARNING = 3, // DO NOT CHANGE THESE NUMBERS
17 + RRDCALC_STATUS_CRITICAL = 4, // DO NOT CHANGE THESE NUMBERS
18 } RRDCALC_STATUS;
19
20 typedef struct eval_variable {
tests/ebpf/ebpf_thread_function.sh deleted
-52
@@ -1,52 +0,0 @@
1 -#!/bin/bash
2 -
3 -netdata_ebpf_test_functions() {
4 - echo "QUERYING: ${1}"
5 - curl -k -o /tmp/ebpf_netdata_test_functions.txt "${1}"
6 - TEST=$?
7 - if [ $TEST -ne 0 ]; then
8 - echo "Cannot request run a for ${1}. See '/tmp/ebpf_netdata_test_functions.txt' for more details."
9 - exit 1
10 - fi
11 -
12 - grep "${2}" /tmp/ebpf_netdata_test_functions.txt >/dev/null
13 - TEST=$?
14 - if [ $TEST -ne 0 ]; then
15 - echo "Cannot find ${2} in the output. See '/tmp/ebpf_netdata_test_functions.txt' for more details.."
16 - exit 1
17 - fi
18 -
19 - rm /tmp/ebpf_netdata_test_functions.txt
20 -}
21 -
22 -MURL="http://127.0.0.1:19999"
23 -INTERVAL=60
24 -
25 -if [ -n "$1" ]; then
26 - MURL="$1"
27 -fi
28 -
29 -# Check function loaded
30 -netdata_ebpf_test_functions "${MURL}/api/v1/functions" "ebpf_thread"
31 -
32 -# Check function help
33 -netdata_ebpf_test_functions "${MURL}/api/v1/function?function=ebpf_thread%20help" "allows user to control eBPF threads"
34 -
35 -#Test default request
36 -netdata_ebpf_test_functions "${MURL}/api/v1/function?function=ebpf_thread" "columns"
37 -
38 -#Test thread requests . The mdflush is not enabled, because it is not present in all distributions by default.
39 -#Socket is not in the list, because it will have a complete refactory with next PR
40 -for THREAD in "cachestat" "dc" "disk" "fd" "filesystem" "hardirq" "mount" "oomkill" "process" "shm" "softirq" "sync" "swap" "vfs" ;
41 -do
42 - echo "TESTING ${THREAD}"
43 - netdata_ebpf_test_functions "${MURL}/api/v1/function?function=ebpf_thread%20enable:${THREAD}:${INTERVAL}%20thread:${THREAD}"
44 - sleep 17
45 - netdata_ebpf_test_functions "${MURL}/api/v1/function?function=ebpf_thread%20thread:${THREAD}" "running"
46 - sleep 17
47 - netdata_ebpf_test_functions "${MURL}/api/v1/function?function=ebpf_thread%20disable:${THREAD}"
48 - sleep 6
49 - netdata_ebpf_test_functions "${MURL}/api/v1/function?function=ebpf_thread%20thread:${THREAD}" "stopped"
50 - sleep 6
51 -done
52 -