fluent-plugin-time-cutoff 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 860bdde6a6a5565e1a616eb997797e1e99327e08844fd81c8477e4c0d8dc5eb8
4
- data.tar.gz: 2ba3321e65c12978715fcbde4f72e08a4fbfe703ccbb69f629a0b0edc3563bcf
3
+ metadata.gz: 77b479a1cb54f5eb1a189032c5c0acfde4a99f0f813afb800ec84d39a4e09e2e
4
+ data.tar.gz: 3d27e8cee579842f6705467ddbd8577f47aa72db134f592a82676c01ef758166
5
5
  SHA512:
6
- metadata.gz: e613c8a76899d5d72e5cb7b1ab477a76019d729324834e2341cc401bd035ef5c1865f3531dc7a10ef1d7fa04d99fc212c1c7015e41c75552971388263ba17367
7
- data.tar.gz: e76aa2dd315073688e674335a6e6386df284f6bde032571287d9ff7ddf455147817b7d9bd303295c63555f324b8db26648ba2d703d417e343ef3bbbab3377186
6
+ metadata.gz: 12ea75e58112114c23637be4f19083324040a64bd1528f9628da85077316c52b285aaafd54162a50421da9eff4df4e02d08754399a20cde5f87f374ec357a258
7
+ data.tar.gz: c4731fb66d9b66fc6778a5a614e5534d2f600f61c15ab26adaa75687fdcede90ebccf9714a97b1be69d27761ecf412d2f66917834e9e46ecbb211d365a09d381
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'fluent-plugin-time-cutoff'
8
- spec.version = '0.1.2'
8
+ spec.version = '0.2.0'
9
9
  spec.authors = ['Qrator Labs', 'Serge Tkatchouk']
10
10
  spec.email = ['devops@qrator.net', 'st@qrator.net']
11
11
 
@@ -82,7 +82,10 @@ module Fluent
82
82
  when :epoch_float
83
83
  time.to_f
84
84
  when :iso8601
85
- time.to_time.strftime(TIME_ISO8601)
85
+ # NOTE: Time.at(int) is used instead of EventTime#to_time, which was
86
+ # only added to Fluentd in v1.8.0. This keeps us compatible with the
87
+ # older Fluentd releases declared in the gemspec.
88
+ Time.at(time.to_i).strftime(TIME_ISO8601)
86
89
  end
87
90
  end
88
91
 
@@ -115,6 +118,38 @@ module Fluent
115
118
  log.warn log_line
116
119
  end
117
120
 
121
+ # Normalize time to Fluent::EventTime if it's plain int or float.
122
+ # @param time [Integer|Float] incoming event time
123
+ # @return [Fluent::EventTime] event time normalized to Fluentd's internal format
124
+ def normalize_time(time)
125
+ case time
126
+ when Integer
127
+ Fluent::EventTime.new(time)
128
+ when Float
129
+ time_int, time_frac = time.divmod(1)
130
+ Fluent::EventTime.new(time_int, (time_frac * 10**9).to_i)
131
+ else
132
+ log.warn "Unknown time format given (#{time.class}): \"#{time.inspect}\"."
133
+ numeric = coerce_to_number(time)
134
+ numeric ? normalize_time(numeric) : Fluent::EventTime.now
135
+ end
136
+ end
137
+
138
+ # Try to coerce an arbitrary value into a number, or return nil.
139
+ # Uses begin/rescue rather than the Integer()/Float() "exception:"
140
+ # keyword (Ruby 2.6+) so the plugin keeps working on older Rubies.
141
+ # @param value the value to coerce
142
+ # @return [Integer,Float,nil] the parsed number, or nil if not numeric
143
+ def coerce_to_number(value)
144
+ Integer(value)
145
+ rescue ArgumentError, TypeError
146
+ begin
147
+ Float(value)
148
+ rescue ArgumentError, TypeError
149
+ nil
150
+ end
151
+ end
152
+
118
153
  # Process the record according to its determined "age"
119
154
  # @param tag [String] log/stream's tag name
120
155
  # @param time [Fluent::EventTime] the original event time
@@ -123,6 +158,9 @@ module Fluent
123
158
  # @param action [Symbol] determined action for this record
124
159
  # @param age [Symbol] detemined age for this record (:old or :new)
125
160
  def process_record(tag, time, record, do_log, action, age) # rubocop:disable Metrics/ParameterLists
161
+ ## Safeguard against rogue integer time.
162
+ time = normalize_time(time) unless time.is_a?(Fluent::EventTime)
163
+
126
164
  log_record(tag, time, record, action, age) if do_log
127
165
 
128
166
  case action
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-time-cutoff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Qrator Labs
8
8
  - Serge Tkatchouk
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2025-04-08 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: fluentd
@@ -92,7 +91,6 @@ homepage: https://github.com/QratorLabs/fluent-plugin-time-cutoff
92
91
  licenses:
93
92
  - MIT
94
93
  metadata: {}
95
- post_install_message:
96
94
  rdoc_options: []
97
95
  require_paths:
98
96
  - lib
@@ -107,8 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
105
  - !ruby/object:Gem::Version
108
106
  version: '0'
109
107
  requirements: []
110
- rubygems_version: 3.4.12
111
- signing_key:
108
+ rubygems_version: 4.0.9
112
109
  specification_version: 4
113
110
  summary: Fluentd time-based filter plugin.
114
111
  test_files: []