Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate exec plugins to v0.14 api #1297

Merged
merged 41 commits into from
Nov 11, 2016
Merged

Conversation

tagomoris
Copy link
Member

@tagomoris tagomoris commented Oct 26, 2016

This change is to migrate out_exec_filter to v0.14 API, and make in/out_exec plugins free from Fluent::ExecUtil::* classes.

This change includes the changes to:

  • make all (built-in or 3rd party) formatter/parser plugins available in exec plugins
  • make inject/extract plugin helpers available in exec plugins
  • add a method to return parser/formatter type for data handling (binary, text or text-per-line)
  • add methods to pass io or partial data to parsers to parse binary or multiline text data in consistent way
  • add options of child_process plugin helper to wait process exits and callback for exit status

This change is successor of #1048.

@tagomoris tagomoris self-assigned this Oct 26, 2016
@tagomoris tagomoris force-pushed the migrate-exec-plugins-to-v0.14-api branch 3 times, most recently from 618069b to a15583e Compare November 1, 2016 11:07
@tagomoris tagomoris force-pushed the migrate-exec-plugins-to-v0.14-api branch from a15583e to 853342e Compare November 2, 2016 13:58
@tagomoris tagomoris changed the title [WIP] Migrate exec plugins to v0.14 api Migrate exec plugins to v0.14 api Nov 2, 2016
@tagomoris
Copy link
Member Author

@repeatedly Could you review this change?

@tagomoris tagomoris force-pushed the migrate-exec-plugins-to-v0.14-api branch from 8fcb357 to 046c787 Compare November 4, 2016 10:36
@tagomoris
Copy link
Member Author

Rebased on #1305.
@repeatedly ping?

@repeatedly
Copy link
Member

@tagomoris I will review it. You pushed some changes after previous comment, so I waited to finish your additional commit ;p

@tagomoris
Copy link
Member Author

:)
And... currently, CI on Windows is failing. It's problem about just test code, and I'll push some commits for that. Please review the code anyway.

@tagomoris
Copy link
Member Author

Hmm, test_out_exec.rb is also unstable a little.

@repeatedly
Copy link
Member

@sonots Could you also check this PR? This patch is very large so need more reviewers.

class TSVFormatter < Formatter
Plugin.register_formatter('tsv', self)

desc 'Names of fields included in each lines'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Field names" is more simpler than "Names of fields"


def on_record(time, record)
tag = nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is not needed.

router.emit(tag, time, record)
rescue => e
log.error "exec failed to emit", error: e, tag: tag, record: Yajl.dump(record)
log.error "exec failed to emit", tag: tag, record: Yajl.dump(record), error: e
router.emit_error_event(tag, time, record, "exec failed to emit")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4th error argument should be an exception object.

prog = "#{@command} #{chunk.path}"
record = inject_values_to_record(tag, time, record)
if @formatter.formatter_type == :text_per_line
@formatter.format(tag, time, record).chomp + "\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using constant value for "\n" is better for reducing temporary object allocation.

prog = if chunk.respond_to?(:path)
"#{@command} #{chunk.path}"
else
tmpfile = Tempfile.new("fluent-plugin-exec-")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"fluent-plugin-out-exec-" is more better.

chunk_id = chunk.unique_id
callback = ->(status){
begin
if tmpfile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code should be moved to enusre in try_write instead of here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. ensure of #try_write doesn't take care about child process status.
This callback is called after child process plugin helper find the child process's exit status. So here is the only place to delete tmpfile.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... what happen if exception happens before calling callback?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, temp files will leak.
But all exceptions about child process status must be rescued by child process plugin helper code. Only bugs should be able to raise errors before callback.


def on_record(time, record)
tag = nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

tag = nil
tag = extract_tag_from_record(record)
tag = @added_prefix_string + tag if tag && @add_prefix
tag ||= @tag
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Off topic. We should care extrated result and @tag is nil case.

@next_log_time = Time.now.to_i + @suppress_error_log_interval
end
router.emit_error_event(tag, time, record, "exec_filter failed to emit") if tag && time && record
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto. 4th argument should be an error object.

end
alias parse_partial_data parse

def parse_io(io)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be use parse_io(io, &block) for API signature?

@@ -77,10 +79,20 @@ module CompatParameters
"utc" => nil,
}

EXTRACT_PARAMS = {
"time_key" => "time_key",
"time_format" => "time_format",
Copy link
Member

@repeatedly repeatedly Nov 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More spaces than expected.

@tagomoris tagomoris force-pushed the migrate-exec-plugins-to-v0.14-api branch from 046c787 to 4686902 Compare November 7, 2016 08:40
@tagomoris
Copy link
Member Author

I've pushed commits for review comments.

@tagomoris tagomoris force-pushed the migrate-exec-plugins-to-v0.14-api branch 2 times, most recently from 555e7a2 to d96b08f Compare November 8, 2016 07:20
@tagomoris tagomoris force-pushed the migrate-exec-plugins-to-v0.14-api branch from d96b08f to 9d8b6e7 Compare November 8, 2016 07:30
@tagomoris
Copy link
Member Author

@repeatedly ping

tag = tag_remove_prefix(tag)
record = inject_values_to_record(tag, time, record)
if @formatter.formatter_type == :text_per_line
@formatter.format(tag, time, record).chomp + "\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use NEWLINE = "\n" like above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh

@repeatedly
Copy link
Member

LGTM.

But my code review doesn't guarantee new process handling code has no problem on actual workloads.
So merging it and test by users is better.

@tagomoris tagomoris merged commit e3edf3e into master Nov 11, 2016
@tagomoris tagomoris deleted the migrate-exec-plugins-to-v0.14-api branch November 11, 2016 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants