2 * Copyright (C) 2021 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
8 #include "event-notifier-error-accounting.hpp"
9 #include <lttng/error-query-internal.hpp>
10 #include <lttng/trigger/trigger-internal.hpp>
11 #include <lttng/action/action-internal.hpp>
13 enum lttng_trigger_status
lttng_trigger_add_error_results(
14 const struct lttng_trigger
*trigger
__attribute__((unused
)),
15 struct lttng_error_query_results
*results
__attribute__((unused
)))
17 return LTTNG_TRIGGER_STATUS_OK
;
20 enum lttng_trigger_status
lttng_trigger_condition_add_error_results(
21 const struct lttng_trigger
*trigger
,
22 struct lttng_error_query_results
*results
)
24 enum lttng_trigger_status status
;
25 uint64_t discarded_tracer_messages_count
;
26 enum event_notifier_error_accounting_status error_accounting_status
;
27 struct lttng_error_query_result
*discarded_tracer_messages_counter
= NULL
;
28 const char *trigger_name
;
31 status
= lttng_trigger_get_name(trigger
, &trigger_name
);
32 trigger_name
= status
== LTTNG_TRIGGER_STATUS_OK
?
33 trigger_name
: "(anonymous)";
34 status
= lttng_trigger_get_owner_uid(trigger
,
36 LTTNG_ASSERT(status
== LTTNG_TRIGGER_STATUS_OK
);
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
44 if (!lttng_trigger_needs_tracer_notifier(trigger
)) {
45 status
= LTTNG_TRIGGER_STATUS_OK
;
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
, (int) trigger_owner
);
54 status
= LTTNG_TRIGGER_STATUS_ERROR
;
58 discarded_tracer_messages_counter
= lttng_error_query_result_counter_create(
59 "discarded tracer messages",
60 "Count of messages discarded by the tracer due to a communication error with the session daemon",
61 discarded_tracer_messages_count
);
62 if (!discarded_tracer_messages_counter
) {
63 status
= LTTNG_TRIGGER_STATUS_ERROR
;
67 if (lttng_error_query_results_add_result(
68 results
, discarded_tracer_messages_counter
)) {
69 status
= LTTNG_TRIGGER_STATUS_ERROR
;
73 /* Ownership transferred to the results. */
74 discarded_tracer_messages_counter
= NULL
;
76 status
= LTTNG_TRIGGER_STATUS_OK
;
78 lttng_error_query_result_destroy(discarded_tracer_messages_counter
);
82 enum lttng_trigger_status
lttng_trigger_add_action_error_query_results(
83 struct lttng_trigger
*trigger
,
84 struct lttng_error_query_results
*results
)
86 enum lttng_trigger_status status
;
87 const char *trigger_name
;
89 enum lttng_action_status action_status
;
91 status
= lttng_trigger_get_name(trigger
, &trigger_name
);
92 trigger_name
= status
== LTTNG_TRIGGER_STATUS_OK
?
93 trigger_name
: "(anonymous)";
94 status
= lttng_trigger_get_owner_uid(trigger
,
96 LTTNG_ASSERT(status
== LTTNG_TRIGGER_STATUS_OK
);
98 action_status
= lttng_action_add_error_query_results(
99 lttng_trigger_get_action(trigger
), results
);
100 switch (action_status
) {
101 case LTTNG_ACTION_STATUS_OK
:
104 status
= LTTNG_TRIGGER_STATUS_ERROR
;
108 status
= LTTNG_TRIGGER_STATUS_OK
;