Skip to content

Commit

Permalink
filterx: defer filterx_scope_sync() to the latest point possible
Browse files Browse the repository at this point in the history
Signed-off-by: Balazs Scheidler <[email protected]>
  • Loading branch information
bazsi committed Apr 11, 2024
1 parent de2579d commit 9ef96c6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
6 changes: 0 additions & 6 deletions lib/filterx/filterx-eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,3 @@ filterx_eval_exec_statements(FilterXScope *scope, GList *statements, LogMessage
filterx_eval_set_context(NULL);
return success;
}

void
filterx_eval_sync_scope_and_message(FilterXScope *scope, LogMessage *msg)
{
filterx_scope_sync(scope, msg);
}
7 changes: 1 addition & 6 deletions lib/filterx/filterx-pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ log_filterx_pipe_queue(LogPipe *s, LogMessage *msg, const LogPathOptions *path_o

NVTable *payload = nv_table_ref(msg->payload);
res = filterx_eval_exec_statements(scope, self->stmts, msg);
if (res)
{
log_msg_make_writable(&msg, path_options);
filterx_eval_sync_scope_and_message(scope, msg);
}

msg_trace("<<<<<< filterx rule evaluation result",
evt_tag_str("result", res ? "matched" : "unmatched"),
Expand Down Expand Up @@ -120,7 +115,7 @@ log_filterx_pipe_new(GList *stmts, GlobalConfig *cfg)
LogFilterXPipe *self = g_new0(LogFilterXPipe, 1);

log_pipe_init_instance(&self->super, cfg);
self->super.flags |= PIF_CONFIG_RELATED;
self->super.flags = (self->super.flags | PIF_CONFIG_RELATED) & ~PIF_SYNC_SCOPE;
self->super.init = log_filterx_pipe_init;
self->super.queue = log_filterx_pipe_queue;
self->super.free_fn = log_filterx_pipe_free;
Expand Down
9 changes: 7 additions & 2 deletions lib/logmpx.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@ log_multiplexer_queue(LogPipe *s, LogMessage *msg, const LogPathOptions *path_op
log_path_options_push_junction(&local_path_options, &matched, path_options);
if (_has_multiple_arcs(self))
{
log_msg_write_protect(msg);
if (path_options->filterx_scope)
filterx_scope_write_protect(path_options->filterx_scope);
{
log_msg_make_writable(&msg, path_options);
filterx_scope_sync(path_options->filterx_scope, msg);
filterx_scope_write_protect(path_options->filterx_scope);
}
log_msg_write_protect(msg);
}
for (fallback = 0; (fallback == 0) || (fallback == 1 && self->fallback_exists && !delivered); fallback++)
{
Expand Down Expand Up @@ -216,6 +220,7 @@ log_multiplexer_new(GlobalConfig *cfg)
LogMultiplexer *self = g_new0(LogMultiplexer, 1);

log_pipe_init_instance(&self->super, cfg);
self->super.flags = self->super.flags & ~PIF_SYNC_SCOPE;
self->super.init = log_multiplexer_init;
self->super.deinit = log_multiplexer_deinit;
self->super.queue = log_multiplexer_queue;
Expand Down
1 change: 1 addition & 0 deletions lib/logpipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ log_pipe_init_instance(LogPipe *self, GlobalConfig *cfg)
self->queue = NULL;
self->free_fn = log_pipe_free_method;
self->arcs = _arcs;
self->flags = PIF_SYNC_SCOPE;
}

LogPipe *
Expand Down
8 changes: 8 additions & 0 deletions lib/logpipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
/* node created directly by the user */
#define PIF_CONFIG_RELATED 0x0100

#define PIF_SYNC_SCOPE 0x0200

/* private flags range, to be used by other LogPipe instances for their own purposes */

#define PIF_PRIVATE(x) ((x) << 16)
Expand Down Expand Up @@ -456,6 +458,12 @@ log_pipe_queue(LogPipe *s, LogMessage *msg, const LogPathOptions *path_options)
}
}

if (path_options->filterx_scope && (s->flags & PIF_SYNC_SCOPE))
{
log_msg_make_writable(&msg, path_options);
filterx_scope_sync(path_options->filterx_scope, msg);
}

if (G_UNLIKELY(s->flags & (PIF_HARD_FLOW_CONTROL | PIF_JUNCTION_END | PIF_CONDITIONAL_MIDPOINT)))
{
path_options = log_path_options_chain(&local_path_options, path_options);
Expand Down

0 comments on commit 9ef96c6

Please sign in to comment.