-
Notifications
You must be signed in to change notification settings - Fork 34
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 to v0.14 API #44
Changes from 7 commits
248a791
9737119
0b822df
6d1016d
a80211c
2e9efb9
6737bd5
e2ec50f
700c11e
413ee69
98f2090
acee35e
6cc70c8
3ce9b4e
9860d1c
17f18fe
c038f44
111f309
e36aabb
2af4fc6
2ac760e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,76 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
require 'net/http' | ||
require 'time' | ||
require 'webhdfs' | ||
require 'tempfile' | ||
require 'fluent/plugin/output' | ||
|
||
require 'fluent/mixin/config_placeholders' | ||
require 'fluent/mixin/plaintextformatter' | ||
|
||
class Fluent::WebHDFSOutput < Fluent::TimeSlicedOutput | ||
class Fluent::Plugin::WebHDFSOutput < Fluent::Plugin::Output | ||
Fluent::Plugin.register_output('webhdfs', self) | ||
|
||
config_set_default :buffer_type, 'memory' | ||
config_set_default :time_slice_format, '%Y%m%d' | ||
helpers :compat_parameters | ||
|
||
# For fluentd v0.12.16 or earlier | ||
class << self | ||
unless method_defined?(:desc) | ||
def desc(description) | ||
end | ||
end | ||
config_section :buffer do | ||
config_set_default :@type, 'memory' | ||
end | ||
|
||
desc 'WebHDFS/HttpFs host' | ||
config_param :host, :string, :default => nil | ||
config_param :host, :string, default: nil | ||
desc 'WebHDFS/HttpFs port' | ||
config_param :port, :integer, :default => 50070 | ||
config_param :port, :integer, default: 50070 | ||
desc 'Namenode (host:port)' | ||
config_param :namenode, :string, :default => nil # host:port | ||
config_param :namenode, :string, default: nil # host:port | ||
desc 'Standby namenode for Namenode HA (host:port)' | ||
config_param :standby_namenode, :string, :default => nil # host:port | ||
config_param :standby_namenode, :string, default: nil # host:port | ||
|
||
desc 'Ignore errors on start up' | ||
config_param :ignore_start_check_error, :bool, :default => false | ||
config_param :ignore_start_check_error, :bool, default: false | ||
|
||
include Fluent::Mixin::ConfigPlaceholders | ||
|
||
desc 'Output file path on HDFS' | ||
config_param :path, :string | ||
desc 'User name for pseudo authentication' | ||
config_param :username, :string, :default => nil | ||
config_param :username, :string, default: nil | ||
|
||
desc 'Store data over HttpFs instead of WebHDFS' | ||
config_param :httpfs, :bool, :default => false | ||
config_param :httpfs, :bool, default: false | ||
|
||
desc 'Number of seconds to wait for the connection to open' | ||
config_param :open_timeout, :integer, :default => 30 # from ruby net/http default | ||
config_param :open_timeout, :integer, default: 30 # from ruby net/http default | ||
desc 'Number of seconds to wait for one block to be read' | ||
config_param :read_timeout, :integer, :default => 60 # from ruby net/http default | ||
config_param :read_timeout, :integer, default: 60 # from ruby net/http default | ||
|
||
desc 'Retry automatically when known errors of HDFS are occurred' | ||
config_param :retry_known_errors, :bool, :default => false | ||
config_param :retry_known_errors, :bool, default: false | ||
desc 'Retry interval' | ||
config_param :retry_interval, :integer, :default => nil | ||
config_param :retry_interval, :integer, default: nil | ||
desc 'The number of retries' | ||
config_param :retry_times, :integer, :default => nil | ||
config_param :retry_times, :integer, default: nil | ||
|
||
# how many times of write failure before switch to standby namenode | ||
# by default it's 11 times that costs 1023 seconds inside fluentd, | ||
# which is considered enough to exclude the scenes that caused by temporary network fail or single datanode fail | ||
desc 'How many times of write failure before switch to standby namenode' | ||
config_param :failures_before_use_standby, :integer, :default => 11 | ||
config_param :failures_before_use_standby, :integer, default: 11 | ||
|
||
include Fluent::Mixin::PlainTextFormatter | ||
|
||
config_param :default_tag, :string, :default => 'tag_missing' | ||
config_param :default_tag, :string, default: 'tag_missing' | ||
|
||
desc 'Append data or not' | ||
config_param :append, :bool, :default => true | ||
config_param :append, :bool, default: true | ||
|
||
desc 'Use SSL or not' | ||
config_param :ssl, :bool, :default => false | ||
config_param :ssl, :bool, default: false | ||
desc 'OpenSSL certificate authority file' | ||
config_param :ssl_ca_file, :string, :default => nil | ||
config_param :ssl_ca_file, :string, default: nil | ||
desc 'OpenSSL verify mode (none,peer)' | ||
config_param :ssl_verify_mode, :default => nil do |val| | ||
config_param :ssl_verify_mode, default: nil do |val| | ||
case val | ||
when 'none' | ||
:none | ||
|
@@ -83,11 +82,11 @@ def desc(description) | |
end | ||
|
||
desc 'Use kerberos authentication or not' | ||
config_param :kerberos, :bool, :default => false | ||
config_param :kerberos, :bool, default: false | ||
|
||
SUPPORTED_COMPRESS = ['gzip', 'bzip2', 'snappy', 'lzo_command', 'text'] | ||
desc "Compress method (#{SUPPORTED_COMPRESS.join(',')})" | ||
config_param :compress, :default => nil do |val| | ||
config_param :compress, default: nil do |val| | ||
unless SUPPORTED_COMPRESS.include? val | ||
raise Fluent::ConfigError, "unsupported compress: #{val}" | ||
end | ||
|
@@ -100,28 +99,18 @@ def desc(description) | |
|
||
def initialize | ||
super | ||
require 'net/http' | ||
require 'time' | ||
require 'webhdfs' | ||
|
||
@compressor = nil | ||
end | ||
|
||
# Define `log` method for v0.10.42 or earlier | ||
unless method_defined?(:log) | ||
define_method("log") { $log } | ||
end | ||
|
||
def configure(conf) | ||
if conf['path'] | ||
if conf['path'].index('%S') | ||
conf['time_slice_format'] = '%Y%m%d%H%M%S' | ||
elsif conf['path'].index('%M') | ||
conf['time_slice_format'] = '%Y%m%d%H%M' | ||
elsif conf['path'].index('%H') | ||
conf['time_slice_format'] = '%Y%m%d%H' | ||
end | ||
end | ||
conf["time_slice_format"] = case conf["path"] | ||
when /%S/ then "%Y%m%d%H%M%S" | ||
when /%M/ then "%Y%m%d%H%M" | ||
when /%H/ then "%Y%m%d%H" | ||
else "%Y%m%d" | ||
end | ||
|
||
compat_parameters_convert(conf, :buffer) | ||
|
||
super | ||
|
||
|
@@ -234,8 +223,8 @@ def shutdown | |
super | ||
end | ||
|
||
def path_format(chunk_key) | ||
Time.strptime(chunk_key, @time_slice_format).strftime(@path) | ||
def path_format(metadata) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this method still needed? (instead of using |
||
extract_placeholders(@path, metadata) | ||
end | ||
|
||
def is_standby_exception(e) | ||
|
@@ -269,9 +258,9 @@ def send_data(path, data) | |
|
||
def generate_path(chunk) | ||
hdfs_path = if @append | ||
path_format(chunk.key) | ||
path_format(chunk.metadata) | ||
else | ||
path_format(chunk.key).gsub(CHUNK_ID_PLACE_HOLDER, chunk_unique_id_to_str(chunk.unique_id)) | ||
path_format(chunk.metadata).gsub(CHUNK_ID_PLACE_HOLDER, chunk_unique_id_to_str(chunk.unique_id)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fluentd v0.14 has |
||
end | ||
hdfs_path = "#{hdfs_path}#{@compressor.ext}" | ||
hdfs_path | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way of v0.14 API is to set
<buffer> timekey </buffer>
ifarg
of<buffer>
includes "time" andtimekey
is not set.