-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Symmetric time parse and format #1207
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
028228d
move TimeParser to time.rb about symmetricity with TimeFormatter
tagomoris 90c6341
show arguments can be nil explicitly
tagomoris 38354a7
add localtime/timezone feature to parse time string as expected timezone
tagomoris 48fa0f2
move tests for TimeParser
tagomoris 6e2043f
merge with_timezone test helper method
tagomoris 2e27826
move assertion defined in horrible file...
tagomoris bcd67ef
fix tests for new path and namespace
tagomoris 293eaf2
fix to show diff this lines
tagomoris a3339d2
fix to use diff directly (UTC is delayed from the area of positive ut…
tagomoris 6dfa6f0
add mixin to introduce time format / timezone parameters into any plu…
tagomoris 8374fe6
add test for time formatter / timezone mixin
tagomoris ff4169b
fix to use time_parser_create / time_formatter_create
tagomoris 5d97807
fix to use shared TIME_PARAMETER to make parameters common between pa…
tagomoris fe2b6d1
add missing requirement
tagomoris 09cdb28
add #call (equals to #parse) for symmetric methods w/ TimeFormatter
tagomoris 79643c8
add extract plugin helper to extract tag/time from records with confi…
tagomoris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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,90 @@ | ||
# | ||
# 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/event' | ||
require 'fluent/time' | ||
require 'fluent/configurable' | ||
|
||
module Fluent | ||
module PluginHelper | ||
module Extract | ||
def extract_tag_from_record(record) | ||
return nil unless @_extract_enabled | ||
|
||
if @_extract_tag_key && record.has_key?(@_extract_tag_key) | ||
return record[@_extract_tag_key].to_s | ||
end | ||
|
||
nil | ||
end | ||
|
||
def extract_time_from_record(record) | ||
return nil unless @_extract_enabled | ||
|
||
if @_extract_time_key && record.has_key?(@_extract_time_key) | ||
return @_extract_time_parser.call(record[@_extract_time_key]) | ||
end | ||
|
||
nil | ||
end | ||
|
||
module ExtractParams | ||
include Fluent::Configurable | ||
config_section :extract, required: false, multi: false, param_name: :extract_config do | ||
config_param :tag_key, :string, default: nil | ||
config_param :time_key, :string, default: nil | ||
config_param :time_type, :enum, list: [:float, :unixtime, :string], default: :float | ||
|
||
Fluent::TimeMixin::TIME_PARAMETERS.each do |name, type, opts| | ||
config_param name, type, opts | ||
end | ||
end | ||
end | ||
|
||
def self.included(mod) | ||
mod.include ExtractParams | ||
end | ||
|
||
def initialize | ||
super | ||
@_extract_enabled = false | ||
@_extract_tag_key = nil | ||
@_extract_time_key = nil | ||
@_extract_time_parser = nil | ||
end | ||
|
||
def configure(conf) | ||
super | ||
|
||
if @extract_config | ||
@_extract_tag_key = @extract_config.tag_key | ||
@_extract_time_key = @extract_config.time_key | ||
if @_extract_time_key | ||
@_extract_time_parser = case @extract_config.time_type | ||
when :float then ->(v){ Fluent::EventTime.new(v.to_i, ((v.to_f - v.to_i) * 1_000_000_000).to_i) } | ||
when :unixtime then ->(v){ Fluent::EventTime.new(v.to_i, 0) } | ||
else | ||
localtime = @extract_config.localtime && !@extract_config.utc | ||
Fluent::TimeParser.new(@extract_config.time_format, localtime, @extract_config.timezone) | ||
end | ||
end | ||
|
||
@_extract_enabled = @_extract_tag_key || @_extract_time_key | ||
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why don't you use
include Fluent::TimeMixin::TimeParameters
?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.
Because that mixin adds parameters on the top namespace, not in
<extract>
sections.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.
I see. implementation limitation...