Fix: JUL filtering done on the UST level
authorDavid Goulet <dgoulet@efficios.com>
Wed, 7 May 2014 17:53:36 +0000 (13:53 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Mon, 12 May 2014 14:03:16 +0000 (10:03 -0400)
This is to support enabling all events with different loglevels in two
different sessions.

For this, if any loglevel have been defined, the 'int_loglevel' filter
is added to the UST event. The liblttng-ust-jul library has been
modified to stop filtering loglevel in the agent.

This commit adds two tests, one for a back to back session that are
destroyed and a second one for multi loglevel session.

Signed-off-by: David Goulet <dgoulet@efficios.com>
src/lib/lttng-ctl/lttng-ctl.c
tests/regression/ust/java-jul/test_java_jul

index 272c70299b089fe79fda1ab17369f10d69eb9b26..38fe271b09b6ee4e112d8080f40c4b886a2786e8 100644 (file)
@@ -749,9 +749,8 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle,
         * filtering by logger name.
         */
        if (exclusion_count == 0 && filter_expression == NULL &&
-                       (handle->domain.type != LTTNG_DOMAIN_JUL || ev->name[0] == '*')) {
-               ret = lttng_ctl_ask_sessiond(&lsm, NULL);
-               return ret;
+                       handle->domain.type != LTTNG_DOMAIN_JUL) {
+               goto ask_sessiond;
        }
 
        /*
@@ -760,22 +759,52 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle,
         */
 
        /* Parse filter expression */
-       if (filter_expression != NULL ||
-                       (handle->domain.type == LTTNG_DOMAIN_JUL && ev->name[0] != '*')) {
+       if (filter_expression != NULL || handle->domain.type == LTTNG_DOMAIN_JUL) {
                if (handle->domain.type == LTTNG_DOMAIN_JUL) {
                        int err;
 
-                       if (filter_expression) {
-                               err = asprintf(&jul_filter, "%s && logger_name == \"%s\"",
-                                               filter_expression, ev->name);
-                       } else {
-                               err = asprintf(&jul_filter, "logger_name == \"%s\"", ev->name);
+                       if (ev->name[0] != '*') {
+                               if (filter_expression) {
+                                       err = asprintf(&jul_filter, "%s && logger_name == \"%s\"",
+                                                       filter_expression, ev->name);
+                               } else {
+                                       err = asprintf(&jul_filter, "logger_name == \"%s\"",
+                                                       ev->name);
+                               }
+                               if (err < 0) {
+                                       PERROR("asprintf");
+                                       return -LTTNG_ERR_NOMEM;
+                               }
+                               filter_expression = jul_filter;
+                       }
+
+                       /* Add loglevel filtering if any for the JUL domain. */
+                       if (ev->loglevel_type != LTTNG_EVENT_LOGLEVEL_ALL) {
+                               char *op;
+
+                               if (ev->loglevel_type == LTTNG_EVENT_LOGLEVEL_RANGE) {
+                                       op = ">=";
+                               } else {
+                                       op = "==";
+                               }
+
+                               if (filter_expression) {
+                                       err = asprintf(&jul_filter, "%s && int_loglevel %s %d",
+                                                       filter_expression, op, ev->loglevel);
+                               } else {
+                                       err = asprintf(&jul_filter, "int_loglevel %s %d", op,
+                                                       ev->loglevel);
+                               }
+                               if (err < 0) {
+                                       PERROR("asprintf");
+                                       return -LTTNG_ERR_NOMEM;
+                               }
+                               filter_expression = jul_filter;
                        }
-                       if (err < 0) {
-                               PERROR("asprintf");
-                               return -LTTNG_ERR_NOMEM;
+
+                       if (!filter_expression) {
+                               goto ask_sessiond;
                        }
-                       filter_expression = jul_filter;
                }
 
                /*
@@ -910,6 +939,10 @@ filter_alloc_error:
        }
        free(jul_filter);
        return ret;
+
+ask_sessiond:
+       ret = lttng_ctl_ask_sessiond(&lsm, NULL);
+       return ret;
 }
 
 /*
index 50452023b55e49538a0df3f60cdae1198d48e3d8..a91904af4b28f1323a9f5a04aad4e2d97d2c4151 100755 (executable)
@@ -29,9 +29,7 @@ EVENT_NAME="JTestLTTng"
 EVENT_NAME2="JTestLTTng2"
 JAVA_CP="$CURDIR:/usr/local/lib/lttng/java/liblttng-ust-jul.jar:/usr/lib/lttng/java/liblttng-ust-jul.jar"
 
-TRACE_PATH=$(mktemp -d)
-
-NUM_TESTS=66
+NUM_TESTS=92
 
 source $TESTDIR/utils/utils.sh
 
@@ -51,6 +49,24 @@ function wait_apps
        pass "Wait for applications to end"
 }
 
+function enable_jul_loglevel_only()
+{
+       sess_name=$1
+       event_name="$2"
+       loglevel=$3
+       channel_name=$4
+
+       if [ -z $channel_name ]; then
+               # default channel if none specified
+               chan=""
+       else
+               chan="-c $channel_name"
+       fi
+
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel-only $loglevel "$event_name" $chan -s $sess_name -j >/dev/null 2>&1
+       ok $? "Enable JUL event $event_name for session $sess_name with loglevel-only $loglevel"
+}
+
 # MUST set TESTDIR before calling those functions
 
 function test_jul_before_start ()
@@ -201,6 +217,40 @@ function test_jul_loglevel_multiple ()
        fi
 }
 
+function test_jul_multi_session_loglevel()
+{
+       diag "Test JUL with multiple session"
+
+       create_lttng_session $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
+       enable_jul_loglevel_only $SESSION_NAME-1 '*' "JUL_INFO"
+       start_lttng_tracing $SESSION_NAME-1
+
+       create_lttng_session $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
+       enable_jul_loglevel_only $SESSION_NAME-2 '*' "JUL_FINEST"
+       start_lttng_tracing $SESSION_NAME-2
+
+       # Run 5 times with a 1 second delay and fire second TP.
+       run_app 1 1
+       wait_apps
+
+       stop_lttng_tracing $SESSION_NAME-1
+       stop_lttng_tracing $SESSION_NAME-2
+       destroy_lttng_session $SESSION_NAME-1
+       destroy_lttng_session $SESSION_NAME-2
+
+       # Expecting 6 events being the main event plus the second tp.
+       trace_matches $EVENT_NAME $(($NR_ITER + 1)) $TRACE_PATH/$SESSION_NAME-1
+       if [ $? -ne 0 ]; then
+               return $?
+       fi
+
+       # Expectin 5 events being the finest TP.
+       trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2
+       if [ $? -ne 0 ]; then
+               return $?
+       fi
+}
+
 function test_jul_multi_session()
 {
        diag "Test JUL with multiple session"
@@ -235,6 +285,44 @@ function test_jul_multi_session()
        fi
 }
 
+function test_jul_destroy_session()
+{
+       diag "Test JUL two session with destroy"
+
+       create_lttng_session $SESSION_NAME $TRACE_PATH/first-sess
+       enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
+       start_lttng_tracing $SESSION_NAME
+
+       # Run 5 times with a 1 second delay
+       run_app 0 1
+
+       sleep 1
+
+       stop_lttng_tracing $SESSION_NAME
+       destroy_lttng_session $SESSION_NAME
+
+       # Validate test. Expecting at least one event num 1
+       validate_trace $EVENT_NAME $TRACE_PATH/first-sess
+       if [ $? -ne 0 ]; then
+               return $?
+       fi
+
+       create_lttng_session $SESSION_NAME $TRACE_PATH/second-sess
+       enable_jul_lttng_event $SESSION_NAME $EVENT_NAME2
+       start_lttng_tracing $SESSION_NAME
+
+       wait_apps
+
+       stop_lttng_tracing $SESSION_NAME
+       destroy_lttng_session $SESSION_NAME
+
+       # Validate test. Expecting only one event num 2
+       trace_matches $EVENT_NAME2 1 $TRACE_PATH/second-sess
+       if [ $? -ne 0 ]; then
+               return $?
+       fi
+}
+
 plan_tests $NUM_TESTS
 
 print_test_banner "$TEST_DESC"
@@ -250,6 +338,8 @@ skip $withapp "JUL support is needed. Skipping all tests." $NUM_TESTS ||
        start_lttng_sessiond
 
        tests=(
+               test_jul_multi_session_loglevel
+               test_jul_destroy_session
                test_jul_loglevel
                test_jul_loglevel_multiple
                test_jul_before_start
@@ -259,6 +349,8 @@ skip $withapp "JUL support is needed. Skipping all tests." $NUM_TESTS ||
 
        for fct_test in ${tests[@]};
        do
+               TRACE_PATH=$(mktemp -d)
+
                ${fct_test}
                if [ $? -ne 0 ]; then
                        break;
This page took 0.04043 seconds and 4 git commands to generate.