128dd9d15cc8f4fd16bbadb3391adae4a3cac095
[lttng-tools.git] / src / bin / lttng-sessiond / trigger-error-query.cpp
1 /*
2 * Copyright (C) 2021 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8 #include "event-notifier-error-accounting.hpp"
9
10 #include <lttng/action/action-internal.hpp>
11 #include <lttng/error-query-internal.hpp>
12 #include <lttng/trigger/trigger-internal.hpp>
13
14 enum lttng_trigger_status lttng_trigger_add_error_results(const struct lttng_trigger *trigger
15 __attribute__((unused)),
16 struct lttng_error_query_results *results
17 __attribute__((unused)))
18 {
19 return LTTNG_TRIGGER_STATUS_OK;
20 }
21
22 enum lttng_trigger_status
23 lttng_trigger_condition_add_error_results(const struct lttng_trigger *trigger,
24 struct lttng_error_query_results *results)
25 {
26 enum lttng_trigger_status status;
27 uint64_t discarded_tracer_messages_count;
28 enum event_notifier_error_accounting_status error_accounting_status;
29 struct lttng_error_query_result *discarded_tracer_messages_counter = NULL;
30 const char *trigger_name;
31 uid_t trigger_owner;
32
33 status = lttng_trigger_get_name(trigger, &trigger_name);
34 trigger_name = status == LTTNG_TRIGGER_STATUS_OK ? trigger_name : "(anonymous)";
35 status = lttng_trigger_get_owner_uid(trigger, &trigger_owner);
36 LTTNG_ASSERT(status == LTTNG_TRIGGER_STATUS_OK);
37
38 /*
39 * Only add discarded tracer messages count for applicable conditions.
40 * As of 2.13, only "event rule matches" conditions can generate
41 * reportable errors hence why this function is very specific to this
42 * condition type.
43 */
44 if (!lttng_trigger_needs_tracer_notifier(trigger)) {
45 status = LTTNG_TRIGGER_STATUS_OK;
46 goto end;
47 }
48
49 error_accounting_status = event_notifier_error_accounting_get_count(
50 trigger, &discarded_tracer_messages_count);
51 if (error_accounting_status != EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK) {
52 ERR("Failed to retrieve tracer discarded messages count for trigger: trigger name = '%s', trigger owner uid = %d",
53 trigger_name,
54 (int) trigger_owner);
55 status = LTTNG_TRIGGER_STATUS_ERROR;
56 goto end;
57 }
58
59 discarded_tracer_messages_counter = lttng_error_query_result_counter_create(
60 "discarded tracer messages",
61 "Count of messages discarded by the tracer due to a communication error with the session daemon",
62 discarded_tracer_messages_count);
63 if (!discarded_tracer_messages_counter) {
64 status = LTTNG_TRIGGER_STATUS_ERROR;
65 goto end;
66 }
67
68 if (lttng_error_query_results_add_result(results, discarded_tracer_messages_counter)) {
69 status = LTTNG_TRIGGER_STATUS_ERROR;
70 goto end;
71 }
72
73 /* Ownership transferred to the results. */
74 discarded_tracer_messages_counter = NULL;
75
76 status = LTTNG_TRIGGER_STATUS_OK;
77 end:
78 lttng_error_query_result_destroy(discarded_tracer_messages_counter);
79 return status;
80 }
81
82 enum lttng_trigger_status
83 lttng_trigger_add_action_error_query_results(struct lttng_trigger *trigger,
84 struct lttng_error_query_results *results)
85 {
86 enum lttng_trigger_status status;
87 const char *trigger_name;
88 uid_t trigger_owner;
89 enum lttng_action_status action_status;
90
91 status = lttng_trigger_get_name(trigger, &trigger_name);
92 trigger_name = status == LTTNG_TRIGGER_STATUS_OK ? trigger_name : "(anonymous)";
93 status = lttng_trigger_get_owner_uid(trigger, &trigger_owner);
94 LTTNG_ASSERT(status == LTTNG_TRIGGER_STATUS_OK);
95
96 action_status =
97 lttng_action_add_error_query_results(lttng_trigger_get_action(trigger), results);
98 switch (action_status) {
99 case LTTNG_ACTION_STATUS_OK:
100 break;
101 default:
102 status = LTTNG_TRIGGER_STATUS_ERROR;
103 goto end;
104 }
105
106 status = LTTNG_TRIGGER_STATUS_OK;
107 end:
108 return status;
109 }
This page took 0.031653 seconds and 4 git commands to generate.