lttng: list-triggers: retrieve trigger errors using error queries
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 15 Apr 2021 17:14:37 +0000 (13:14 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 18 Apr 2021 23:28:57 +0000 (19:28 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I1a80125122e2568491d940c598d8445410bf58d9

src/bin/lttng/commands/list_triggers.c
tests/regression/tools/notification/test_notification_notifier_discarded_count
tests/regression/tools/trigger/test_list_triggers_cli
tests/regression/tools/trigger/test_remove_trigger_cli

index d208f4ff68cb66b71fe4db70b36498ed19379991..70ab4c4e540d95c79aae6967207ce20b3f137861 100644 (file)
@@ -19,6 +19,7 @@
 /* For lttng_domain_type_str(). */
 #include "lttng/domain-internal.h"
 #include "../loglevel.h"
+#include <lttng/lttng.h>
 
 #ifdef LTTNG_EMBED_HELP
 static const char help_msg[] =
@@ -418,7 +419,6 @@ void print_condition_on_event(const struct lttng_condition *condition)
        const struct lttng_event_rule *event_rule;
        enum lttng_condition_status condition_status;
        unsigned int cap_desc_count, i;
-       uint64_t error_count;
 
        condition_status =
                lttng_condition_on_event_get_rule(condition, &event_rule);
@@ -431,9 +431,6 @@ void print_condition_on_event(const struct lttng_condition *condition)
                                        condition, &cap_desc_count);
        assert(condition_status == LTTNG_CONDITION_STATUS_OK);
 
-       error_count = lttng_condition_on_event_get_error_count(condition);
-       MSG("    tracer notifications discarded: %" PRIu64, error_count);
-
        if (cap_desc_count > 0) {
                MSG("    captures:");
 
@@ -450,7 +447,93 @@ void print_condition_on_event(const struct lttng_condition *condition)
 }
 
 static
-void print_one_action(const struct lttng_action *action)
+void print_action_errors(const struct lttng_trigger *trigger,
+               const struct lttng_action *action)
+{
+       unsigned int i, count, printed_errors_count = 0;
+       enum lttng_error_code error_query_ret;
+       enum lttng_error_query_results_status results_status;
+       struct lttng_error_query_results *results = NULL;
+       const char *trigger_name;
+       uid_t trigger_uid;
+       enum lttng_trigger_status trigger_status;
+       struct lttng_error_query *query =
+                       lttng_error_query_action_create(trigger, action);
+
+       assert(query);
+
+       trigger_status = lttng_trigger_get_name(trigger, &trigger_name);
+       assert(trigger_status == LTTNG_TRIGGER_STATUS_OK);
+
+       trigger_status = lttng_trigger_get_owner_uid(trigger, &trigger_uid);
+       assert(trigger_status == LTTNG_TRIGGER_STATUS_OK);
+
+       error_query_ret = lttng_error_query_execute(
+                       query, lttng_session_daemon_command_endpoint, &results);
+       if (error_query_ret != LTTNG_OK) {
+               ERR("Failed to query errors of trigger '%s' (owner uid: %d): %s",
+                               trigger_name, (int) trigger_uid,
+                               lttng_strerror(-error_query_ret));
+               goto end;
+       }
+
+       results_status = lttng_error_query_results_get_count(results, &count);
+       assert(results_status == LTTNG_ERROR_QUERY_RESULTS_STATUS_OK);
+
+       _MSG("      errors:");
+
+       for (i = 0; i < count; i++) {
+               const struct lttng_error_query_result *result;
+               enum lttng_error_query_result_status result_status;
+               const char *result_name;
+               const char *result_description;
+               uint64_t result_value;
+
+               results_status = lttng_error_query_results_get_result(
+                               results, &result, i);
+               assert(results_status == LTTNG_ERROR_QUERY_RESULTS_STATUS_OK);
+
+               result_status = lttng_error_query_result_get_name(
+                               result, &result_name);
+               assert(result_status == LTTNG_ERROR_QUERY_RESULT_STATUS_OK);
+               result_status = lttng_error_query_result_get_description(
+                               result, &result_description);
+               assert(result_status == LTTNG_ERROR_QUERY_RESULT_STATUS_OK);
+
+               if (lttng_error_query_result_get_type(result) ==
+                               LTTNG_ERROR_QUERY_RESULT_TYPE_COUNTER) {
+                       result_status = lttng_error_query_result_counter_get_value(
+                                       result, &result_value);
+                       assert(result_status ==
+                                       LTTNG_ERROR_QUERY_RESULT_STATUS_OK);
+                       if (result_value == 0) {
+                               continue;
+                       }
+
+                       MSG("");
+                       _MSG("        %s: %" PRIu64, result_name,
+                                       result_value);
+                       printed_errors_count++;
+               } else {
+                       _MSG("        Unknown error query result type for result '%s' (%s)",
+                                       result_name, result_description);
+                       continue;
+               }
+       }
+
+       if (printed_errors_count == 0) {
+               _MSG(" none");
+       }
+
+end:
+       MSG("");
+       lttng_error_query_destroy(query);
+       lttng_error_query_results_destroy(results);
+}
+
+static
+void print_one_action(const struct lttng_trigger *trigger,
+               const struct lttng_action *action)
 {
        enum lttng_action_type action_type;
        enum lttng_action_status action_status;
@@ -616,10 +699,96 @@ void print_one_action(const struct lttng_action *action)
        }
 
        MSG("");
+       print_action_errors(trigger, action);
+
 end:
        return;
 }
 
+static
+void print_trigger_errors(const struct lttng_trigger *trigger)
+{
+       unsigned int i, count, printed_errors_count = 0;
+       enum lttng_error_code error_query_ret;
+       enum lttng_error_query_results_status results_status;
+       struct lttng_error_query_results *results = NULL;
+       enum lttng_trigger_status trigger_status;
+       const char *trigger_name;
+       uid_t trigger_uid;
+       struct lttng_error_query *query =
+                       lttng_error_query_trigger_create(trigger);
+
+       assert(query);
+
+       trigger_status = lttng_trigger_get_name(trigger, &trigger_name);
+       assert(trigger_status == LTTNG_TRIGGER_STATUS_OK);
+
+       trigger_status = lttng_trigger_get_owner_uid(trigger, &trigger_uid);
+       assert(trigger_status == LTTNG_TRIGGER_STATUS_OK);
+
+       error_query_ret = lttng_error_query_execute(
+                       query, lttng_session_daemon_command_endpoint, &results);
+       if (error_query_ret != LTTNG_OK) {
+               ERR("Failed to query errors of trigger '%s' (owner uid: %d): %s",
+                               trigger_name, (int) trigger_uid,
+                               lttng_strerror(-error_query_ret));
+               goto end;
+       }
+
+       results_status = lttng_error_query_results_get_count(results, &count);
+       assert(results_status == LTTNG_ERROR_QUERY_RESULTS_STATUS_OK);
+
+       _MSG("  errors:");
+
+       for (i = 0; i < count; i++) {
+               const struct lttng_error_query_result *result;
+               enum lttng_error_query_result_status result_status;
+               const char *result_name;
+               const char *result_description;
+               uint64_t result_value;
+
+               results_status = lttng_error_query_results_get_result(
+                               results, &result, i);
+               assert(results_status == LTTNG_ERROR_QUERY_RESULTS_STATUS_OK);
+
+               result_status = lttng_error_query_result_get_name(
+                               result, &result_name);
+               assert(result_status == LTTNG_ERROR_QUERY_RESULT_STATUS_OK);
+               result_status = lttng_error_query_result_get_description(
+                               result, &result_description);
+               assert(result_status == LTTNG_ERROR_QUERY_RESULT_STATUS_OK);
+
+               if (lttng_error_query_result_get_type(result) ==
+                               LTTNG_ERROR_QUERY_RESULT_TYPE_COUNTER) {
+                       result_status = lttng_error_query_result_counter_get_value(
+                                       result, &result_value);
+                       assert(result_status ==
+                                       LTTNG_ERROR_QUERY_RESULT_STATUS_OK);
+                       if (result_value == 0) {
+                               continue;
+                       }
+
+                       MSG("");
+                       _MSG("    %s: %" PRIu64, result_name,
+                                       result_value);
+                       printed_errors_count++;
+               } else {
+                       _MSG("    Unknown error query result type for result '%s' (%s)",
+                                       result_name, result_description);
+                       continue;
+               }
+       }
+
+       if (printed_errors_count == 0) {
+               _MSG(" none");
+       }
+
+end:
+       MSG("");
+       lttng_error_query_destroy(query);
+       lttng_error_query_results_destroy(results);
+}
+
 static
 void print_one_trigger(const struct lttng_trigger *trigger)
 {
@@ -669,13 +838,14 @@ void print_one_trigger(const struct lttng_trigger *trigger)
                                                        action, i);
 
                        _MSG("    ");
-                       print_one_action(subaction);
+                       print_one_action(trigger, subaction);
                }
        } else {
                _MSG(" action:");
-               print_one_action(action);
+               print_one_action(trigger, action);
        }
 
+       print_trigger_errors(trigger);
 }
 
 static
index e49d355285c59e15d77c5112b28202b35732ea3f..697c652bc79cce22b0dfd1c9263bc274bbbfb810 100755 (executable)
@@ -27,8 +27,8 @@ source "$CURDIR/util_event_generator.sh"
 FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
 FULL_LTTNG_SESSIOND_BIN="${TESTDIR}/../src/bin/lttng-sessiond/lttng-sessiond"
 
-UST_NUM_TESTS=16
-KERNEL_NUM_TESTS=15
+UST_NUM_TESTS=18
+KERNEL_NUM_TESTS=17
 NUM_TESTS=$(($UST_NUM_TESTS + $KERNEL_NUM_TESTS))
 
 plan_tests $NUM_TESTS
@@ -60,11 +60,15 @@ function test_kernel_notifier_discarded_count
 
        "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout"
 
-       # Confirm that the discarded notification line is present.
-       cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded: 0"
-       ok $? "No discarded tracer notification"
+       # Confirm that the discarded notification line is not present.
+       cat "$list_triggers_stdout" | grep -v --quiet "discarded tracer messages"
+       ok $? "No discarded tracer notification message"
+
+       tail -n 1 "$list_triggers_stdout" | grep --quiet "errors: none"
+       ok $? "Trigger 'errors: none' notification message"
 
        # Stop consumption of notifier tracer notifications.
+       diag "Pause consumption of tracer messages"
        echo -n 1 > $sessiond_pipe
 
        # The notifier ring buffer configuration is currently made of 16 4096
@@ -78,11 +82,11 @@ function test_kernel_notifier_discarded_count
 
        # Confirm that the discarded notification line is present. To avoid
        # false positives.
-       cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded"
+       cat "$list_triggers_stdout" | grep --quiet "dicarded tracer messages"
        ok $? "Tracer notification discarded line printed"
 
-       # Confirm that the number of tracer notifications discarded is not zero.
-       cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded: 0"
+       # Confirm that the number of dicarded tracer messages is not zero.
+       cat "$list_triggers_stdout" | grep --quiet "dicarded tracer messages: 0"
        isnt $? 0 "Discarded tracer notification number non-zero as expected"
 
        lttng_remove_trigger_ok "$trigger_name"
@@ -96,10 +100,12 @@ function test_kernel_notifier_discarded_count
                --condition on-event --kernel lttng_test_filter_event \
                --action notify
 
-       # Confirm that the discarded notification line is present.
-       "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout"
-       cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded: 0"
-       ok $? "No discarded tracer notification"
+       # Confirm that the discarded notification line is not present.
+       cat "$list_triggers_stdout" | grep -v --quiet "discarded tracer messages"
+       ok $? "No discarded tracer notification message"
+
+       tail -n 1 "$list_triggers_stdout" | grep --quiet "errors: none"
+       ok $? "Trigger 'errors: none' notification message"
 
        lttng_remove_trigger_ok "$trigger_name"
 
@@ -174,11 +180,15 @@ function test_ust_notifier_discarded_count
 
        "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout"
 
-       # Confirm that the discarded notification line is present.
-       cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded: 0"
-       ok $? "No discarded tracer notification"
+       # Confirm that the discarded notification line is not present.
+       cat "$list_triggers_stdout" | grep -v --quiet "discarded tracer messages"
+       ok $? "No discarded tracer notification message"
+
+       tail -n 1 "$list_triggers_stdout" | grep --quiet "errors: none"
+       ok $? "Trigger 'errors: none' notification message"
 
        # Stop consumption of notifier tracer notifications.
+       diag "Pause consumption of tracer messages"
        echo -n 1 > $sessiond_pipe
 
        $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT
@@ -188,11 +198,11 @@ function test_ust_notifier_discarded_count
 
        # Confirm that the discarded notification line is present. To avoid
        # false positive.
-       cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded"
+       cat "$list_triggers_stdout" | grep --quiet "discarded tracer messages"
        ok $? "Tracer notification discarded line printed"
 
-       # Confirm that the number of tracer notifications discarded is not zero.
-       cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded: 0"
+       # Confirm that the number of discarded tracer messages is not zero.
+       cat "$list_triggers_stdout" | grep --quiet "discarded tracer messages: 0"
        isnt $? 0 "Discarded tracer notification number non-zero as expected"
 
        # Remove the notifier.
@@ -207,10 +217,15 @@ function test_ust_notifier_discarded_count
                --condition on-event --userspace tp:tptest \
                --action notify
 
-       # Confirm that the discarded notification line is present.
+       # Confirm that the discarded notification line is not present.
        "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout"
-       cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded: 0"
-       ok $? "No discarded tracer notification"
+
+       # Confirm that the discarded notification line is not present.
+       cat "$list_triggers_stdout" | grep -v --quiet "discarded tracer messages"
+       ok $? "No discarded tracer notification message"
+
+       tail -n 1 "$list_triggers_stdout" | grep --quiet "errors: none"
+       ok $? "Trigger 'errors: none' notification message"
 
        lttng_remove_trigger_ok "$trigger_name"
 
index 169613375132bb6f3b60fa59b0db923bc6bbe69f..2c39582075b1f5fc87ee8ec3f1994d8faa778d29 100755 (executable)
@@ -69,9 +69,10 @@ test_top_level_options ()
          user id: ${uid}
          condition: event rule hit
            rule: test-id (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            notify
+             errors: none
+         errors: none
        EOF
 
        list_triggers "top level options" "${tmp_expected_stdout}"
@@ -100,74 +101,83 @@ test_on_event_tracepoint ()
          user id: ${uid}
          condition: event rule hit
            rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
-           tracer notifications discarded: 0
          actions:
            notify
+             errors: none
+         errors: none
        - id: B
          user id: ${uid}
          condition: event rule hit
            rule: gerboise (type: tracepoint, domain: ust, log level at least INFO)
-           tracer notifications discarded: 0
          actions:
            notify
+             errors: none
+         errors: none
        - id: C
          user id: ${uid}
          condition: event rule hit
            rule: * (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            notify
+             errors: none
+         errors: none
        - id: D
          user id: ${uid}
          condition: event rule hit
            rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
-           tracer notifications discarded: 0
          actions:
            notify
+             errors: none
+         errors: none
        - id: E
          user id: ${uid}
          condition: event rule hit
            rule: lemming (type: tracepoint, domain: ust, log level is WARNING)
-           tracer notifications discarded: 0
          actions:
            notify
+             errors: none
+         errors: none
        - id: F
          user id: ${uid}
          condition: event rule hit
            rule: capture-payload-field (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
            captures:
              - a
          actions:
            notify
+             errors: none
+         errors: none
        - id: G
          user id: ${uid}
          condition: event rule hit
            rule: capture-array (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
            captures:
              - a[2]
              - \$ctx.tourlou[18]
          actions:
            notify
+             errors: none
+         errors: none
        - id: H
          user id: ${uid}
          condition: event rule hit
            rule: capture-chan-ctx (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
            captures:
              - \$ctx.vpid
          actions:
            notify
+             errors: none
+         errors: none
        - id: I
          user id: ${uid}
          condition: event rule hit
            rule: capture-app-ctx (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
            captures:
              - \$app.iga:active_clients
          actions:
            notify
+             errors: none
+         errors: none
        EOF
 
        list_triggers "on-event, tracepoint event rule" "${tmp_expected_stdout}"
@@ -208,23 +218,26 @@ test_on_event_probe ()
          user id: ${uid}
          condition: event rule hit
            rule: my_channel_enable (type: probe, location: lttng_channel_enable)
-           tracer notifications discarded: 0
          actions:
            notify
+             errors: none
+         errors: none
        - id: T1
          user id: ${uid}
          condition: event rule hit
            rule: my_channel_enable (type: probe, location: ${base_symbol}+${offset_hex})
-           tracer notifications discarded: 0
          actions:
            notify
+             errors: none
+         errors: none
        - id: T2
          user id: ${uid}
          condition: event rule hit
            rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr})
-           tracer notifications discarded: 0
          actions:
            notify
+             errors: none
+         errors: none
        EOF
 
        list_triggers "on-event, probe event rule" "${tmp_expected_stdout}"
@@ -244,9 +257,10 @@ test_on_event_userspace_probe ()
          user id: ${uid}
          condition: event rule hit
            rule: ma-probe (type: userspace probe, location: ${uprobe_elf_binary}:test_function)
-           tracer notifications discarded: 0
          actions:
            notify
+             errors: none
+         errors: none
        EOF
 
        list_triggers "on-event, userspace-probe event rule" "${tmp_expected_stdout}"
@@ -267,16 +281,18 @@ test_on_event_syscall ()
          user id: ${uid}
          condition: event rule hit
            rule: open (type: syscall)
-           tracer notifications discarded: 0
          actions:
            notify
+             errors: none
+         errors: none
        - id: T1
          user id: ${uid}
          condition: event rule hit
            rule: ptrace (type: syscall, filter: a > 2)
-           tracer notifications discarded: 0
          actions:
            notify
+             errors: none
+         errors: none
        EOF
 
        list_triggers "on-event, syscall event rule" "${tmp_expected_stdout}"
@@ -305,72 +321,82 @@ test_snapshot_action ()
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            snapshot session \`ze-session\`
+             errors: none
+         errors: none
        - id: T1
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            snapshot session \`ze-session\`, path: /some/path
+             errors: none
+         errors: none
        - id: T2
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            snapshot session \`ze-session\`, path: /some/other/path
+             errors: none
+         errors: none
        - id: T3
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            snapshot session \`ze-session\`, url: net://1.2.3.4
+             errors: none
+         errors: none
        - id: T4
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
+             errors: none
+         errors: none
        - id: T5
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
+             errors: none
+         errors: none
        - id: T6
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            snapshot session \`ze-session\`, path: /some/path, max size: 1234
+             errors: none
+         errors: none
        - id: T7
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            snapshot session \`ze-session\`, path: /some/path, name: meh
+             errors: none
+         errors: none
        - id: T8
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            snapshot session \`ze-session\`, rate policy: after every 10 occurrences
+             errors: none
+         errors: none
        - id: T9
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            snapshot session \`ze-session\`, rate policy: once after 10 occurrences
+             errors: none
+         errors: none
        EOF
 
        list_triggers "snapshot action" "${tmp_expected_stdout}"
@@ -391,16 +417,18 @@ test_notify_action ()
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            notify, rate policy: once after 5 occurrences
+             errors: none
+         errors: none
        - id: T1
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            notify, rate policy: after every 10 occurrences
+             errors: none
+         errors: none
        EOF
 
        list_triggers "snapshot action" "${tmp_expected_stdout}"
index 582cce7ef3fe4958aef349d455b145354601d4ae..8a0f90a9e4049fad013132c2db73c72a890b814c 100755 (executable)
@@ -76,16 +76,18 @@ cat > "${tmp_expected_stdout}" <<- EOF
   user id: ${uid}
   condition: event rule hit
     rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
-    tracer notifications discarded: 0
   actions:
     notify
+      errors: none
+  errors: none
 - id: DEF
   user id: ${uid}
   condition: event rule hit
     rule: * (type: tracepoint, domain: ust)
-    tracer notifications discarded: 0
   actions:
     notify
+      errors: none
+  errors: none
 EOF
 list_triggers "two triggers left" "${tmp_expected_stdout}"
 
@@ -96,9 +98,10 @@ cat > "${tmp_expected_stdout}" <<- EOF
   user id: ${uid}
   condition: event rule hit
     rule: * (type: tracepoint, domain: ust)
-    tracer notifications discarded: 0
   actions:
     notify
+      errors: none
+  errors: none
 EOF
 list_triggers "one trigger left" "${tmp_expected_stdout}"
 
This page took 0.049605 seconds and 4 git commands to generate.