Skip to content

Commit

Permalink
log: add caller plugin-id about emitting error events
Browse files Browse the repository at this point in the history
It would be helpful if we could know what plugin emitted the
error event.

fluent#4567

We need to care about the compatibility.
This signature change would not break compatibility.

However, I'm concerned that `caller_plugin_id` has a race
condition, although I don't confirm it.
It looks to me that the id can be another plugin-id running
concurrently...
It is not the issue with this fix, it is the issue of the
existing implementation.

Signed-off-by: Daijiro Fukuda <[email protected]>
  • Loading branch information
daipom committed Nov 27, 2024
1 parent 2d8c9d4 commit df33064
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/fluent/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def add_filter(type, pattern, conf)
end

# For handling invalid record
def emit_error_event(tag, time, record, error)
def emit_error_event(tag, time, record, error, plugin_id: nil)
end

def handle_emits_error(tag, es, error)
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/event_router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def emit_stream(tag, es)
end

def emit_error_event(tag, time, record, error)
@emit_error_handler.emit_error_event(tag, time, record, error)
@emit_error_handler.emit_error_event(tag, time, record, error, plugin_id: @caller_plugin_id)
end

def match?(tag)
Expand Down
4 changes: 2 additions & 2 deletions lib/fluent/label.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def configure(conf)
end
end

def emit_error_event(tag, time, record, e)
@root_agent.emit_error_event(tag, time, record, e)
def emit_error_event(tag, time, record, e, plugin_id: nil)
@root_agent.emit_error_event(tag, time, record, e, plugin_id: plugin_id)
end

def handle_emits_error(tag, es, e)
Expand Down
3 changes: 2 additions & 1 deletion lib/fluent/root_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,9 @@ def find_label(label_name)
end
end

def emit_error_event(tag, time, record, error)
def emit_error_event(tag, time, record, error, plugin_id: nil)
error_info = {error: error, location: (error.backtrace ? error.backtrace.first : nil), tag: tag, time: time}
error_info[:plugin_id] = plugin_id if plugin_id
if @error_collector
# A record is not included in the logs because <@ERROR> handles it. This warn is for the notification
log.warn "send an error event to @ERROR:", error_info
Expand Down

0 comments on commit df33064

Please sign in to comment.