logstash-filter-date 2.1.5 → 2.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7e2d12c0916f9c311953e2306d722ec3f2a4c93
4
- data.tar.gz: 805e03dcbaba174eca7cdd32d55335a38a8b8022
3
+ metadata.gz: b55acd38d75625d5aad84145a3ba0543b967e7c2
4
+ data.tar.gz: 468b66d39fe5bb0e766787f222618b76191d2a07
5
5
  SHA512:
6
- metadata.gz: 07d32fb6f83437c27d232353d5f16a5f74c5c267f67f7a33bdc2b6a63082fa232c8c134c505d8733a211e5f3e7250e23158191ab26f4c8d992fc7d8b9f3e8a46
7
- data.tar.gz: 410341d8a4c5d285c29281ef176fc31b49efef7aa94243a95bb57c81ea341533888f538a8cc0226e3923af3930f93e4e1c3c41fb758c85c65bd6ebb0bb9a6ac5
6
+ metadata.gz: 086fc7bf00a6c5e7346ee65b20ba5d998f9aaba9a9995ed30af065c8e7957c51a34bae96af80d127c7d2c95122c63d52f8bdb51b74649e47b6fee48f32f36dcf
7
+ data.tar.gz: 5e3521439c348673c5ad1d23dacbe770690db36a84cbd739ae2f37f0cd1c34a4d7041101ae3436319f80cde3916b3e71ad37560ddd16f394260f057e3a925fe0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,5 @@
1
+ # 2.1.6
2
+ - bugfix: Fails to parse a timestamp without year that falls in DST switchover for CET #63 (fix for #62)
1
3
  # 2.1.5
2
4
  - doc: Include formatting syntax documentation in match config #60 (fix for #38)
3
5
  - internal: correct dependencies scope
@@ -24,6 +24,10 @@ class LogStash::Filters::Date < LogStash::Filters::Base
24
24
  if RUBY_ENGINE == "jruby"
25
25
  JavaException = java.lang.Exception
26
26
  UTC = org.joda.time.DateTimeZone.forID("UTC")
27
+ java_import org.joda.time.LocalDateTime
28
+ class LocalDateTime
29
+ java_alias :to_datetime_with_tz, :toDateTime, [Java::org.joda.time.DateTimeZone]
30
+ end
27
31
  end
28
32
 
29
33
  config_name "date"
@@ -185,22 +189,35 @@ class LogStash::Filters::Date < LogStash::Filters::Base
185
189
  setupMatcher(@config["match"].shift, locale, @config["match"] )
186
190
  end
187
191
 
188
- def parseWithJodaParser(joda_parser, date, format_has_year)
192
+ def parseWithJodaParser(joda_parser, date, format_has_year, format_has_timezone)
189
193
  return joda_parser.parseMillis(date) if format_has_year
190
194
  now = Time.now
191
195
  now_month = now.month
192
- result = joda_parser.parseDateTime(date)
196
+ if (format_has_timezone)
197
+ result = joda_parser.parseDateTime(date)
198
+ else
199
+ # Parse date in UTC, Timezone correction later
200
+ result = joda_parser.withZone(UTC).parseLocalDateTime(date)
201
+ end
202
+
193
203
  event_month = result.getMonthOfYear
194
204
 
195
205
  if (event_month == now_month)
196
- result.with_year(now.year)
206
+ result = result.with_year(now.year)
197
207
  elsif (event_month == 12 && now_month == 1)
198
- result.with_year(now.year-1)
208
+ result = result.with_year(now.year-1)
199
209
  elsif (event_month == 1 && now_month == 12)
200
- result.with_year(now.year+1)
210
+ result = result.with_year(now.year+1)
201
211
  else
202
- result.with_year(now.year)
203
- end.get_millis
212
+ result = result.with_year(now.year)
213
+ end
214
+
215
+ if (format_has_timezone)
216
+ return result.get_millis
217
+ else
218
+ #Timezone correction
219
+ return result.to_datetime_with_tz(joda_parser.getZone()).get_millis
220
+ end
204
221
  end
205
222
 
206
223
  def setupMatcher(field, locale, value)
@@ -248,6 +265,7 @@ class LogStash::Filters::Date < LogStash::Filters::Base
248
265
  else
249
266
  begin
250
267
  format_has_year = format.match(/y|Y/)
268
+ format_has_timezone = format.match(/Z/)
251
269
  joda_parser = org.joda.time.format.DateTimeFormat.forPattern(format)
252
270
  if @timezone && !@sprintf_timezone
253
271
  joda_parser = joda_parser.withZone(org.joda.time.DateTimeZone.forID(@timezone))
@@ -259,11 +277,11 @@ class LogStash::Filters::Date < LogStash::Filters::Base
259
277
  end
260
278
  if @sprintf_timezone
261
279
  parsers << lambda { |date , tz|
262
- return parseWithJodaParser(joda_parser.withZone(org.joda.time.DateTimeZone.forID(tz)), date, format_has_year)
280
+ return parseWithJodaParser(joda_parser.withZone(org.joda.time.DateTimeZone.forID(tz)), date, format_has_year, format_has_timezone)
263
281
  }
264
282
  end
265
283
  parsers << lambda do |date|
266
- return parseWithJodaParser(joda_parser, date, format_has_year)
284
+ return parseWithJodaParser(joda_parser, date, format_has_year, format_has_timezone)
267
285
  end
268
286
 
269
287
  #Include a fallback parser to english when default locale is non-english
@@ -271,7 +289,7 @@ class LogStash::Filters::Date < LogStash::Filters::Base
271
289
  "en" != java.util.Locale.getDefault().getLanguage() &&
272
290
  (format.include?("MMM") || format.include?("E"))
273
291
  en_joda_parser = joda_parser.withLocale(java.util.Locale.forLanguageTag('en-US'))
274
- parsers << lambda { |date| parseWithJodaParser(en_joda_parser, date, format_has_year) }
292
+ parsers << lambda { |date| parseWithJodaParser(en_joda_parser, date, format_has_year, format_has_timezone) }
275
293
  end
276
294
  rescue JavaException => e
277
295
  raise LogStash::ConfigurationError, I18n.t("logstash.agent.configuration.invalid_plugin_register",
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-date'
4
- s.version = '2.1.5'
4
+ s.version = '2.1.6'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "The date filter is used for parsing dates from fields, and then using that date or timestamp as the logstash timestamp for the event."
7
7
  s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
@@ -386,6 +386,28 @@ RUBY_ENGINE == "jruby" and describe LogStash::Filters::Date do
386
386
  end # times.each
387
387
  end
388
388
 
389
+ describe "don't fail on next years DST switchover in CET" do
390
+ config <<-CONFIG
391
+ filter {
392
+ date {
393
+ match => [ "message", "yyyy MMM dd HH:mm:ss" ]
394
+ locale => "en"
395
+ timezone => "CET"
396
+ }
397
+ }
398
+ CONFIG
399
+
400
+ before(:each) do
401
+ logstash_time = Time.utc(2016,03,29,23,59,50)
402
+ allow(Time).to receive(:now).and_return(logstash_time)
403
+ end
404
+
405
+ sample "2016 Mar 26 02:00:37" do
406
+ insist { subject["tags"] } != ["_dateparsefailure"]
407
+ insist { subject["@timestamp"].to_s } == "2016-03-26T01:00:37.000Z"
408
+ end
409
+ end
410
+
389
411
  context "Default year handling when parsing with timezone from event" do
390
412
 
391
413
  describe "LOGSTASH-34 - Default year should be this year" do
@@ -445,6 +467,28 @@ RUBY_ENGINE == "jruby" and describe LogStash::Filters::Date do
445
467
  insist { subject["@timestamp"].year } == 2014
446
468
  end
447
469
  end
470
+
471
+ describe "don't fail on next years DST switchover in CET" do
472
+ config <<-CONFIG
473
+ filter {
474
+ date {
475
+ match => [ "message", "MMM dd HH:mm:ss" ]
476
+ locale => "en"
477
+ timezone => "CET"
478
+ }
479
+ }
480
+ CONFIG
481
+
482
+ before(:each) do
483
+ logstash_time = Time.utc(2016,03,29,23,59,50)
484
+ allow(Time).to receive(:now).and_return(logstash_time)
485
+ end
486
+
487
+ sample "Mar 26 02:00:37" do
488
+ insist { subject["tags"] } != ["_dateparsefailure"]
489
+ insist { subject["@timestamp"].to_s } == "2016-03-26T01:00:37.000Z"
490
+ end
491
+ end
448
492
  end
449
493
 
450
494
  describe "LOGSTASH-34 - Default year should be this year" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-date
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.5
4
+ version: 2.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-29 00:00:00.000000000 Z
11
+ date: 2016-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement