on-event evaluation: remove trigger name accessor
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 7 Apr 2021 02:05:26 +0000 (22:05 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 7 Apr 2021 03:29:48 +0000 (23:29 -0400)
The trigger name accessor on an on-event evaluation is no longer needed
as the originating trigger is now accessible on a notification.

The tests are adapted to use the name of the trigger as returned by
the lttng_notification received by the client.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I57bd64d7f5ec35f015dfb115ecfadd75806b9a75

include/lttng/condition/on-event-internal.h
include/lttng/condition/on-event.h
src/bin/lttng-sessiond/notification-thread-events.c
src/common/conditions/on-event.c
tests/regression/tools/notification/notification.c
tests/regression/tools/trigger/utils/notification-client.c

index cc8f1cdf9e2eb1afb4eb4f0191d4d0b172902e6b..1ccabf3f4ef04a057d68fce262f5d044712a819b 100644 (file)
@@ -38,7 +38,6 @@ struct lttng_condition_on_event {
 
 struct lttng_evaluation_on_event {
        struct lttng_evaluation parent;
-       char *name;
 
        /* MessagePack-encoded captured event field values. */
        struct lttng_dynamic_buffer capture_payload;
@@ -53,13 +52,6 @@ struct lttng_evaluation_on_event {
        struct lttng_event_field_value *captured_values;
 };
 
-struct lttng_evaluation_on_event_comm {
-       /* Includes the null terminator. */
-       uint32_t trigger_name_length;
-       /* Trigger name. */
-       char payload[];
-} LTTNG_PACKED;
-
 LTTNG_HIDDEN
 ssize_t lttng_condition_on_event_create_from_payload(
                struct lttng_payload_view *view,
@@ -90,7 +82,6 @@ void lttng_condition_on_event_set_error_count(struct lttng_condition *condition,
 LTTNG_HIDDEN
 struct lttng_evaluation *lttng_evaluation_on_event_create(
                const struct lttng_condition_on_event *condition,
-               const char* trigger_name,
                const char *capture_payload, size_t capture_payload_size,
                bool decode_capture_payload);
 
index 5114ec1fc99fccce7f437a074be79150bc439139..18c4155a2c73dd10d1462d088f9beec6a3dbf8e3 100644 (file)
@@ -64,23 +64,10 @@ extern enum lttng_condition_status lttng_condition_on_event_get_rule(
  * allow users to query a number of properties resulting from the evaluation
  * of a condition which evaluated to true.
  *
- * The evaluation of a on event hit yields two different results:
- *    TEMPORARY - The name of the triggers associated with the condition.
- *    TODO - The captured event payload if any
+ * The evaluation of an on event condition contains the captured event
+ * payload fields that were specified by the condition.
  */
 
-/*
- * Get the trigger name property of a on event hit evaluation.
- *
- * Returns LTTNG_EVALUATION_STATUS_OK on success and a trigger name
- * or LTTNG_EVALUATION_STATUS_INVALID if
- * an invalid parameter is passed.
- */
-extern enum lttng_evaluation_status
-lttng_evaluation_on_event_get_trigger_name(
-               const struct lttng_evaluation *evaluation,
-               const char **name);
-
 /*
  * Sets `*field_val` to the array event field value of the on event
  * condition evaluation `evaluation` which contains its captured values.
index 59b10e9db718f82c791abbddd4f8d1e4a8d20ded..6d153f16d84cd715205ada63b64c9d1eaadf64cd 100644 (file)
@@ -4550,7 +4550,6 @@ int dispatch_one_event_notifier_notification(struct notification_thread_state *s
                                                     element->trigger),
                                        struct lttng_condition_on_event,
                                        parent),
-                       trigger_name,
                        notification->capture_buffer,
                        notification->capture_buf_size, false);
 
index fa37a3540172611c491342722b60f1ae214de041..9a9e7620af596837c2c5a839225749847f9122a5 100644 (file)
@@ -1045,12 +1045,7 @@ ssize_t lttng_evaluation_on_event_create_from_payload(
                struct lttng_evaluation **_evaluation)
 {
        ssize_t ret, offset = 0;
-       const char *trigger_name;
        struct lttng_evaluation *evaluation = NULL;
-       const struct lttng_evaluation_on_event_comm *header;
-       const struct lttng_payload_view header_view =
-                       lttng_payload_view_from_view(
-                                       view, 0, sizeof(*header));
        uint32_t capture_payload_size;
        const char *capture_payload = NULL;
 
@@ -1059,37 +1054,6 @@ ssize_t lttng_evaluation_on_event_create_from_payload(
                goto error;
        }
 
-       if (!lttng_payload_view_is_valid(&header_view)) {
-               ERR("Failed to initialize from malformed event rule evaluation: buffer too short to contain header");
-               ret = -1;
-               goto error;
-       }
-
-       header = (typeof(header)) header_view.buffer.data;
-
-       /* Map the originating trigger's name. */
-       offset += sizeof(*header);
-       {
-               const struct lttng_payload_view current_view =
-                               lttng_payload_view_from_view(view, offset,
-                                               header->trigger_name_length);
-
-               if (!lttng_payload_view_is_valid(&current_view)) {
-                       ERR("Failed to initialize from malformed event rule evaluation: buffer too short to contain trigger name");
-                       ret = -1;
-                       goto error;
-               }
-
-               trigger_name = current_view.buffer.data;
-               if (!lttng_buffer_view_contains_string(&current_view.buffer,
-                                   trigger_name, header->trigger_name_length)) {
-                       ERR("Failed to initialize from malformed event rule evaluation: invalid trigger name");
-                       ret = -1;
-                       goto error;
-               }
-       }
-
-       offset += header->trigger_name_length;
        {
                const struct lttng_payload_view current_view =
                                lttng_payload_view_from_view(view, offset, -1);
@@ -1116,7 +1080,7 @@ ssize_t lttng_evaluation_on_event_create_from_payload(
                capture_payload = current_view.buffer.data;
        }
 
-       evaluation = lttng_evaluation_on_event_create(condition, trigger_name,
+       evaluation = lttng_evaluation_on_event_create(condition,
                        capture_payload, capture_payload_size, true);
        if (!evaluation) {
                ret = -1;
@@ -1139,27 +1103,11 @@ static int lttng_evaluation_on_event_serialize(
 {
        int ret = 0;
        struct lttng_evaluation_on_event *hit;
-       struct lttng_evaluation_on_event_comm comm;
        uint32_t capture_payload_size;
 
        hit = container_of(
                        evaluation, struct lttng_evaluation_on_event, parent);
 
-       assert(hit->name);
-       comm.trigger_name_length = strlen(hit->name) + 1;
-
-       ret = lttng_dynamic_buffer_append(
-                       &payload->buffer, &comm, sizeof(comm));
-       if (ret) {
-               goto end;
-       }
-
-       ret = lttng_dynamic_buffer_append(
-                       &payload->buffer, hit->name, comm.trigger_name_length);
-       if (ret) {
-               goto end;
-       }
-
        capture_payload_size = (uint32_t) hit->capture_payload.size;
        ret = lttng_dynamic_buffer_append(&payload->buffer, &capture_payload_size,
                        sizeof(capture_payload_size));
@@ -1229,7 +1177,6 @@ static void lttng_evaluation_on_event_destroy(
 
        hit = container_of(
                        evaluation, struct lttng_evaluation_on_event, parent);
-       free(hit->name);
        lttng_dynamic_buffer_reset(&hit->capture_payload);
        lttng_event_field_value_destroy(hit->captured_values);
        free(hit);
@@ -1517,7 +1464,6 @@ end:
 LTTNG_HIDDEN
 struct lttng_evaluation *lttng_evaluation_on_event_create(
                const struct lttng_condition_on_event *condition,
-               const char *trigger_name,
                const char *capture_payload, size_t capture_payload_size,
                bool decode_capture_payload)
 {
@@ -1529,11 +1475,6 @@ struct lttng_evaluation *lttng_evaluation_on_event_create(
                goto error;
        }
 
-       hit->name = strdup(trigger_name);
-       if (!hit->name) {
-               goto error;
-       }
-
        lttng_dynamic_buffer_init(&hit->capture_payload);
 
        if (capture_payload) {
@@ -1602,24 +1543,6 @@ end:
        return status;
 }
 
-enum lttng_evaluation_status lttng_evaluation_on_event_get_trigger_name(
-               const struct lttng_evaluation *evaluation, const char **name)
-{
-       struct lttng_evaluation_on_event *hit;
-       enum lttng_evaluation_status status = LTTNG_EVALUATION_STATUS_OK;
-
-       if (!evaluation || !is_on_event_evaluation(evaluation) || !name) {
-               status = LTTNG_EVALUATION_STATUS_INVALID;
-               goto end;
-       }
-
-       hit = container_of(
-                       evaluation, struct lttng_evaluation_on_event, parent);
-       *name = hit->name;
-end:
-       return status;
-}
-
 LTTNG_HIDDEN
 enum lttng_error_code
 lttng_condition_on_event_generate_capture_descriptor_bytecode(
index e7101bb9f69f6bc97de662f9df1187aeeb666108..e26c99d033129940128584bca9bcb7b9d18a597f 100644 (file)
@@ -579,33 +579,24 @@ struct capture_base_field_tuple test_capture_base_fields[] = {
 static const char *get_notification_trigger_name(
                struct lttng_notification *notification)
 {
-       const char *name = NULL;
-       enum lttng_evaluation_status status;
-       const struct lttng_evaluation *evaluation;
-       evaluation = lttng_notification_get_evaluation(notification);
-       if (evaluation == NULL) {
-               fail("lttng_notification_get_evaluation");
+       const char *trigger_name = NULL;
+       enum lttng_trigger_status trigger_status;
+       const struct lttng_trigger *trigger;
+
+       trigger = lttng_notification_get_trigger(notification);
+       if (!trigger) {
+               fail("Failed to get trigger from notification");
                goto end;
        }
 
-       switch (lttng_evaluation_get_type(evaluation)) {
-       case LTTNG_CONDITION_TYPE_ON_EVENT:
-       {
-               status = lttng_evaluation_on_event_get_trigger_name(
-                               evaluation, &name);
-               if (status != LTTNG_EVALUATION_STATUS_OK) {
-                       fail("lttng_evaluation_on_event_get_trigger_name");
-                       name = NULL;
-                       goto end;
-               }
-               break;
-       }
-       default:
-               fail("Wrong notification evaluation type \n");
+       trigger_status = lttng_trigger_get_name(trigger, &trigger_name);
+       if (trigger_status != LTTNG_TRIGGER_STATUS_OK) {
+               fail("Failed to get name from notification's trigger");
                goto end;
        }
+
 end:
-       return name;
+       return trigger_name;
 }
 
 static int validator_notification_trigger_name(
index 2c7c896d846a213038589f3580b6b6bb557d459d..688775a6e72b2ab97c4419efac7726fb201281dc 100644 (file)
@@ -56,41 +56,28 @@ static bool action_group_contains_notify(
 static bool is_expected_trigger_name(const char *expected_trigger_name,
                struct lttng_notification *notification)
 {
-       int ret = false;
-       const struct lttng_evaluation *evaluation =
-                       lttng_notification_get_evaluation(notification);
-       const enum lttng_condition_type type =
-                       lttng_evaluation_get_type(evaluation);
-
-       switch (type) {
-       case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE:
-       case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW:
-       case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH:
-       case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING:
-       case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED:
-               break;
-       case LTTNG_CONDITION_TYPE_ON_EVENT:
-       {
-               const char *trigger_name;
-               enum lttng_evaluation_status evaluation_status;
-
-               evaluation_status =
-                               lttng_evaluation_on_event_get_trigger_name(
-                                               evaluation, &trigger_name);
-               if (evaluation_status != LTTNG_EVALUATION_STATUS_OK) {
-                       fprintf(stderr, "Failed to get trigger name of event rule notification\n");
-                       ret = -1;
-                       break;
-               }
+       const char *trigger_name = NULL;
+       enum lttng_trigger_status trigger_status;
+       const struct lttng_trigger *trigger;
+       bool names_match;
 
-               ret = true;
-               break;
+       trigger = lttng_notification_get_trigger(notification);
+       if (!trigger) {
+               fprintf(stderr, "Failed to get trigger from notification\n");
+               names_match = false;
+               goto end;
        }
-       default:
-               fprintf(stderr, "Unknown notification type (%d)\n", type);
+
+       trigger_status = lttng_trigger_get_name(trigger, &trigger_name);
+       if (trigger_status != LTTNG_TRIGGER_STATUS_OK) {
+               fprintf(stderr, "Failed to get name from notification's trigger\n");
+               names_match = false;
+               goto end;
        }
 
-       return ret;
+       names_match = strcmp(expected_trigger_name, trigger_name) == 0;
+end:
+       return names_match;
 }
 
 int main(int argc, char **argv)
This page took 0.044526 seconds and 4 git commands to generate.