-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
487 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# | ||
# Fluentd | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
require 'fluent/plugin_helper/compat_parameters' | ||
|
||
module Fluent | ||
module Compat | ||
module FormatterUtils | ||
INJECT_PARAMS = Fluent::PluginHelper::CompatParameters::INJECT_PARAMS | ||
FORMATTER_PARAMS = Fluent::PluginHelper::CompatParameters::FORMATTER_PARAMS | ||
|
||
module InjectMixin | ||
def format(tag, time, record) | ||
r = owner.inject_record(tag, time, record) | ||
super(tag, time, r) | ||
end | ||
end | ||
|
||
def self.convert_formatter_conf(conf) | ||
return if conf.elements(name: 'inject').first || conf.elements(name: 'format').first | ||
|
||
inject_params = {} | ||
INJECT_PARAMS.each do |older, newer| | ||
next unless newer | ||
if conf.has_key?(older) | ||
inject_params[newer] = conf[older] | ||
end | ||
end | ||
|
||
if conf.has_key?('include_time_key') && Fluent::Config.bool_value(conf['include_time_key']) | ||
inject_params['time_key'] ||= 'time' | ||
inject_params['time_type'] ||= 'string' | ||
end | ||
if conf.has_key?('time_as_epoch') && Fluent::Config.bool_value(conf['time_as_epoch']) | ||
inject_params['time_type'] = 'unixtime' | ||
end | ||
if conf.has_key?('localtime') || conf.has_key?('utc') | ||
if conf.has_key?('localtime') && Fluent::Config.bool_value(conf['localtime']) | ||
inject_params['localtime'] = true | ||
elsif conf.has_key?('utc') && Fluent::Config.bool_value(conf['utc']) | ||
inject_params['localtime'] = false | ||
inject_params['timezone'] ||= "+0000" | ||
else | ||
log.warn "both of localtime and utc are specified as false" | ||
end | ||
end | ||
|
||
if conf.has_key?('include_tag_key') && Fluent::Config.bool_value(conf['include_tag_key']) | ||
inject_params['tag_key'] ||= 'tag' | ||
end | ||
|
||
unless inject_params.empty? | ||
conf.elements << Fluent::Config::Element.new('inject', '', inject_params, []) | ||
end | ||
|
||
formatter_params = {} | ||
FORMATTER_PARAMS.each do |older, newer| | ||
next unless newer | ||
if conf.has_key?(older) | ||
formatter_params[newer] = conf[older] | ||
end | ||
end | ||
unless formatter_params.empty? | ||
conf.elements << Fluent::Config::Element.new('format', '', formatter_params, []) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# | ||
# Fluentd | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
module Fluent | ||
module Compat | ||
module HandleTagAndTimeMixin | ||
def self.included(klass) | ||
klass.instance_eval { | ||
config_param :include_time_key, :bool, default: false | ||
config_param :time_key, :string, default: 'time' | ||
config_param :time_format, :string, default: nil | ||
config_param :time_as_epoch, :bool, default: false | ||
config_param :include_tag_key, :bool, default: false | ||
config_param :tag_key, :string, default: 'tag' | ||
config_param :localtime, :bool, default: true | ||
config_param :timezone, :string, default: nil | ||
} | ||
end | ||
|
||
def configure(conf) | ||
super | ||
|
||
if conf['utc'] | ||
@localtime = false | ||
end | ||
@timef = Fluent::TimeFormatter.new(@time_format, @localtime, @timezone) | ||
if @time_as_epoch && !@include_time_key | ||
log.warn "time_as_epoch will be ignored because include_time_key is false" | ||
end | ||
end | ||
|
||
def filter_record(tag, time, record) | ||
if @include_tag_key | ||
record[@tag_key] = tag | ||
end | ||
if @include_time_key | ||
if @time_as_epoch | ||
record[@time_key] = time.to_i | ||
else | ||
record[@time_key] = @timef.format(time) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# | ||
# Fluentd | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
require 'fluent/plugin_helper/compat_parameters' | ||
|
||
module Fluent | ||
module Compat | ||
module ParserUtils | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# | ||
# Fluentd | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
require 'fluent/plugin_helper/compat_parameters' | ||
|
||
module Fluent | ||
module Compat | ||
module ParserUtils | ||
PARSER_PARAMS = Fluent::PluginHelper::CompatParameters::PARSER_PARAMS | ||
|
||
def self.convert_parser_conf(conf) | ||
return if conf.elements(name: 'parse').first | ||
|
||
parser_params = {} | ||
PARSER_PARAMS.each do |older, newer| | ||
next unless newer | ||
if conf.has_key?(older) | ||
parser_params[newer] = conf[older] | ||
end | ||
end | ||
unless parser_params.empty? | ||
conf.elements << Fluent::Config::Element.new('parse', '', parser_params, []) | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.