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.h"
9 #include <lttng/error-query-internal.h>
10 #include <lttng/trigger/trigger-internal.h>
11 #include <lttng/action/action-internal.h>
14 enum lttng_trigger_status
lttng_trigger_add_error_results(
15 const struct lttng_trigger
*trigger
,
16 struct lttng_error_query_results
*results
)
18 return LTTNG_TRIGGER_STATUS_OK
;
22 enum lttng_trigger_status
lttng_trigger_condition_add_error_results(
23 const struct lttng_trigger
*trigger
,
24 struct lttng_error_query_results
*results
)
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
;
33 status
= lttng_trigger_get_name(trigger
, &trigger_name
);
34 trigger_name
= status
== LTTNG_TRIGGER_STATUS_OK
?
35 trigger_name
: "(anonymous)";
36 status
= lttng_trigger_get_owner_uid(trigger
,
38 assert(status
== LTTNG_TRIGGER_STATUS_OK
);
41 * Only add discarded tracer messages count for applicable conditions.
42 * As of 2.13, only "event rule matches" conditions can generate
43 * reportable errors hence why this function is very specific to this
46 if (!lttng_trigger_needs_tracer_notifier(trigger
)) {
47 status
= LTTNG_TRIGGER_STATUS_OK
;
51 error_accounting_status
= event_notifier_error_accounting_get_count(
52 trigger
, &discarded_tracer_messages_count
);
53 if (error_accounting_status
!= EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK
) {
54 ERR("Failed to retrieve tracer discarded messages count for triger: triggger name = '%s', trigger owner uid = %d",
55 trigger_name
, (int) trigger_owner
);
56 status
= LTTNG_TRIGGER_STATUS_ERROR
;
60 discarded_tracer_messages_counter
= lttng_error_query_result_counter_create(
61 "discarded tracer messages",
62 "Count of messages discarded by the tracer due to a communication error with the session daemon",
63 discarded_tracer_messages_count
);
64 if (!discarded_tracer_messages_counter
) {
65 status
= LTTNG_TRIGGER_STATUS_ERROR
;
69 if (lttng_error_query_results_add_result(
70 results
, discarded_tracer_messages_counter
)) {
71 status
= LTTNG_TRIGGER_STATUS_ERROR
;
75 /* Ownership transferred to the results. */
76 discarded_tracer_messages_counter
= NULL
;
78 status
= LTTNG_TRIGGER_STATUS_OK
;
80 lttng_error_query_result_destroy(discarded_tracer_messages_counter
);
85 enum lttng_trigger_status
lttng_trigger_add_action_error_query_results(
86 struct lttng_trigger
*trigger
,
87 struct lttng_error_query_results
*results
)
89 enum lttng_trigger_status status
;
90 const char *trigger_name
;
92 enum lttng_action_status action_status
;
94 status
= lttng_trigger_get_name(trigger
, &trigger_name
);
95 trigger_name
= status
== LTTNG_TRIGGER_STATUS_OK
?
96 trigger_name
: "(anonymous)";
97 status
= lttng_trigger_get_owner_uid(trigger
,
99 assert(status
== LTTNG_TRIGGER_STATUS_OK
);
101 action_status
= lttng_action_add_error_query_results(
102 lttng_trigger_get_action(trigger
), results
);
103 switch (action_status
) {
104 case LTTNG_ACTION_STATUS_OK
:
107 status
= LTTNG_TRIGGER_STATUS_ERROR
;
111 status
= LTTNG_TRIGGER_STATUS_OK
;