logstash-filter-date 3.1.16 → 3.2.1
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 +4 -4
- data/CHANGELOG.md +14 -0
- data/docs/index.asciidoc +68 -60
- data/lib/logstash/filters/date.rb +51 -44
- data/logstash-filter-date.gemspec +1 -1
- data/spec/filters/date_spec.rb +81 -352
- data/spec/fixtures/old_date_filter.rb +38 -39
- data/vendor/jar-dependencies/org/logstash/filters/logstash-filter-date/3.1.6/logstash-filter-date-3.1.6.jar +0 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: acaae4f07bc5115a72912039e65d94e0036d7cb13eb426f5a6da08728db6e347
|
|
4
|
+
data.tar.gz: 5b52406d8576e434a23b4b7a9d30ce9ca4699e8ef16640151964067d7f799a58
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0c6ec611ae7343d02ca09326de16c80d39d6aace82bd7eb159a9ff9e33ff038915dad79cd58760ae83fdeb613e526636cb4274ff948ec8512c96374de43a0ded
|
|
7
|
+
data.tar.gz: b7c9daffcf5364c87f529b4c7e473b50a0b88498777ed33b95e5012cac7770bf33c2d71f4f34ac0d8d5266b126fabd7f7b9613d3cdbd24767799d18dc520535e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## 3.2.1
|
|
2
|
+
- Fix date syntax docs list formatting [#166](https://github.com/logstash-plugins/logstash-filter-date/pull/166)
|
|
3
|
+
|
|
4
|
+
## 3.2.0
|
|
5
|
+
- Add `precision` setting to support nanosecond precision timestamps [#165](https://github.com/logstash-plugins/logstash-filter-date/pull/165)
|
|
6
|
+
- `ms` (default): timestamps are stored with millisecond precision
|
|
7
|
+
- keeps the same behavior as before for backward compatibility
|
|
8
|
+
- fractional seconds are truncated to 3 digits
|
|
9
|
+
- custom parsing formats use `joda-time` library
|
|
10
|
+
- `ns`: timestamps are stored with nanosecond precision
|
|
11
|
+
- fractional seconds support up to 9 digits
|
|
12
|
+
- custom parsing formats use `java.time`
|
|
13
|
+
- `ISO8601` now accepts up to 9 fractional-second digits
|
|
14
|
+
|
|
1
15
|
## 3.1.16
|
|
2
16
|
- Re-packaging the plugin [#163](https://github.com/logstash-plugins/logstash-filter-date/pull/163)
|
|
3
17
|
|
data/docs/index.asciidoc
CHANGED
|
@@ -20,23 +20,11 @@ include::{include_path}/plugin_header.asciidoc[]
|
|
|
20
20
|
|
|
21
21
|
==== Description
|
|
22
22
|
|
|
23
|
-
The date filter is used for parsing dates from fields, and then using that
|
|
24
|
-
|
|
23
|
+
The date filter is used for parsing dates from fields, and then using that date or timestamp as the logstash timestamp for the event.
|
|
24
|
+
Timestamp is stored with millisecond precision. Set `precision => "ns"` to preserve nanoseconds.
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"Apr 17 09:32:01"
|
|
29
|
-
|
|
30
|
-
You would use the date format `MMM dd HH:mm:ss` to parse this.
|
|
31
|
-
|
|
32
|
-
The date filter is especially important for sorting events and for
|
|
33
|
-
backfilling old data. If you don't get the date correct in your
|
|
34
|
-
event, then searching for them later will likely sort out of order.
|
|
35
|
-
|
|
36
|
-
In the absence of this filter, logstash will choose a timestamp based on the
|
|
37
|
-
first time it sees the event (at input time), if the timestamp is not already
|
|
38
|
-
set in the event. For example, with file input, the timestamp is set to the
|
|
39
|
-
time of each read.
|
|
26
|
+
Custom parsing formats use the JVM’s default locale and time zone.
|
|
27
|
+
To override them, configure the `locale` and `timezone` settings.
|
|
40
28
|
|
|
41
29
|
[id="plugins-{type}s-{plugin}-options"]
|
|
42
30
|
==== Date Filter Configuration Options
|
|
@@ -48,6 +36,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
|
|
|
48
36
|
|Setting |Input type|Required
|
|
49
37
|
| <<plugins-{type}s-{plugin}-locale>> |<<string,string>>|No
|
|
50
38
|
| <<plugins-{type}s-{plugin}-match>> |<<array,array>>|No
|
|
39
|
+
| <<plugins-{type}s-{plugin}-precision>> |<<string,string>>|No
|
|
51
40
|
| <<plugins-{type}s-{plugin}-tag_on_failure>> |<<array,array>>|No
|
|
52
41
|
| <<plugins-{type}s-{plugin}-target>> |<<string,string>>|No
|
|
53
42
|
| <<plugins-{type}s-{plugin}-timezone>> |<<string,string>>|No
|
|
@@ -89,11 +78,14 @@ If your time field has multiple possible formats, you can do this:
|
|
|
89
78
|
|
|
90
79
|
The above will match a syslog (rfc3164) or `iso8601` timestamp.
|
|
91
80
|
|
|
92
|
-
|
|
81
|
+
By default, the custom formats use the deprecated https://www.joda.org/joda-time/key_format.html[joda-time] library for parsing and timestamp is stored with millisecond precision.
|
|
82
|
+
If you set `precision => "ns"`, parsing is performed using https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/format/DateTimeFormatter.html[java.time], and timestamps are stored with nanosecond precision.
|
|
83
|
+
Both libraries use similar syntax, but there are some differences in supported features. For example, `java.time` supports time zone IDs with `VV` while `joda-time` uses `ZZZ`.
|
|
84
|
+
|
|
85
|
+
Besides custom formats, the following format literals exist
|
|
93
86
|
to help you save time and ensure correctness of date parsing.
|
|
94
87
|
|
|
95
|
-
* `ISO8601` - should parse any valid ISO8601 timestamp, such as
|
|
96
|
-
`2011-04-19T03:44:01.103Z`
|
|
88
|
+
* `ISO8601` - should parse any valid ISO8601 timestamp, such as `2011-04-19T03:44:01.123456789Z`
|
|
97
89
|
* `UNIX` - will parse *float or int* value expressing unix time in seconds since epoch like 1326149001.132 as well as 1326149001
|
|
98
90
|
* `UNIX_MS` - will parse **int** value expressing unix time in milliseconds since epoch like 1366125117000
|
|
99
91
|
* `TAI64N` - will parse tai64n time values
|
|
@@ -119,65 +111,81 @@ indicate the form of that value (2-digit month, full month name, etc).
|
|
|
119
111
|
|
|
120
112
|
Here's what you can use to parse dates and times:
|
|
121
113
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
114
|
+
* `y`: year
|
|
115
|
+
** `yyyy`: full year number. Example: `2015`.
|
|
116
|
+
** `yy`: two-digit year. Example: `15` for the year 2015.
|
|
117
|
+
|
|
118
|
+
* `M`: month of the year
|
|
119
|
+
** `M`: minimal-digit month. Example: `1` for January and `12` for December.
|
|
120
|
+
** `MM`: two-digit month. zero-padded if needed. Example: `01` for January and `12` for December
|
|
121
|
+
** `MMM`: abbreviated month text. Example: `Jan` for January. Note: The language used depends on your locale. See the `locale` setting for how to change the language.
|
|
122
|
+
** `MMMM`: full month text, Example: `January`. Note: The language used depends on your locale.
|
|
126
123
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
MMM::: abbreviated month text. Example: `Jan` for January. Note: The language used depends on your locale. See the `locale` setting for how to change the language.
|
|
131
|
-
MMMM::: full month text, Example: `January`. Note: The language used depends on your locale.
|
|
124
|
+
* `d`: day of the month
|
|
125
|
+
** `d`: minimal-digit day. Example: `1` for the 1st of the month.
|
|
126
|
+
** `dd`: two-digit day, zero-padded if needed. Example: `01` for the 1st of the month.
|
|
132
127
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
128
|
+
* `H`: hour of the day (24-hour clock)
|
|
129
|
+
** `H`: minimal-digit hour. Example: `0` for midnight.
|
|
130
|
+
** `HH`: two-digit hour, zero-padded if needed. Example: `00` for midnight.
|
|
136
131
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
132
|
+
* `m`: minutes of the hour (60 minutes per hour)
|
|
133
|
+
** `m`: minimal-digit minutes. Example: `0`.
|
|
134
|
+
** `mm`: two-digit minutes, zero-padded if needed. Example: `00`.
|
|
140
135
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
136
|
+
* `s`: seconds of the minute (60 seconds per minute)
|
|
137
|
+
** `s`: minimal-digit seconds. Example: `0`.
|
|
138
|
+
** `ss`: two-digit seconds, zero-padded if needed. Example: `00`.
|
|
144
139
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
140
|
+
* `S`: fraction of a second
|
|
141
|
+
** `S`: tenths of a second. Example: `0` for a subsecond value `012`
|
|
142
|
+
** `SS`: hundredths of a second. Example: `01` for a subsecond value `01`
|
|
143
|
+
** `SSS`: milliseconds. Example: `012` for a subsecond value `012`
|
|
144
|
+
** `SSSSSS`: microseconds. Example: `012345`
|
|
145
|
+
** `SSSSSSSSS`: nanoseconds. Example: `012345678`
|
|
148
146
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
S::: tenths of a second. Example: `0` for a subsecond value `012`
|
|
152
|
-
SS::: hundredths of a second. Example: `01` for a subsecond value `01`
|
|
153
|
-
SSS::: thousandths of a second. Example: `012` for a subsecond value `012`
|
|
147
|
+
* `V`: time-zone ID
|
|
148
|
+
** `VV`: time zone ID. Example: `America/Los_Angeles`. Note: This is only supported by `java.time` parsing.
|
|
154
149
|
|
|
155
|
-
Z
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
150
|
+
* `Z`: time zone offset or identity
|
|
151
|
+
** `Z`: Timezone offset structured as HHmm (hour and minutes offset from Zulu/UTC). Example: `-0700`.
|
|
152
|
+
** `ZZ`: Timezone offset structured as HH:mm (colon in between hour and minute offsets). Example: `-07:00`.
|
|
153
|
+
** `ZZZ`: Timezone identity. Example: `America/Los_Angeles`. Note: Valid IDs are listed on the http://joda-time.sourceforge.net/timezones.html[Joda.org available time zones page].
|
|
159
154
|
|
|
160
|
-
z
|
|
155
|
+
* `z`: time zone names. *Time zone names (`z`) cannot be parsed.*
|
|
161
156
|
|
|
162
|
-
w
|
|
163
|
-
|
|
164
|
-
|
|
157
|
+
* `w`: week of the year
|
|
158
|
+
** `w`: minimal-digit week. Example: `1`.
|
|
159
|
+
** `ww`: two-digit week, zero-padded if needed. Example: `01`.
|
|
165
160
|
|
|
166
|
-
D
|
|
161
|
+
* `D`: day of the year
|
|
167
162
|
|
|
168
|
-
e
|
|
163
|
+
* `e`: day of the week (number)
|
|
169
164
|
|
|
170
|
-
E
|
|
171
|
-
|
|
172
|
-
|
|
165
|
+
* `E`: day of the week (text)
|
|
166
|
+
** `E`, `EE`, `EEE`: Abbreviated day of the week. Example: `Mon`, `Tue`, `Wed`, `Thu`, `Fri`, `Sat`, `Sun`. Note: The actual language of this will depend on your locale.
|
|
167
|
+
** `EEEE`: The full text day of the week. Example: `Monday`, `Tuesday`, ... Note: The actual language of this will depend on your locale.
|
|
173
168
|
|
|
174
169
|
For non-formatting syntax, you'll need to put single-quote characters around the value. For example, if you were parsing ISO8601 time, "2015-01-01T01:12:23" that little "T" isn't a valid time format, and you want to say "literally, a T", your format would be this: "yyyy-MM-dd'T'HH:mm:ss"
|
|
175
170
|
|
|
176
171
|
Other less common date units, such as era (G), century \(C), am/pm (a), and # more, can be learned about on the
|
|
177
|
-
|
|
172
|
+
https://www.joda.org/joda-time/key_format.html[joda-time documentation].
|
|
173
|
+
|
|
174
|
+
[id="plugins-{type}s-{plugin}-precision"]
|
|
175
|
+
===== `precision`
|
|
176
|
+
|
|
177
|
+
* Value type is <<string,string>>
|
|
178
|
+
* Valid values are `ms` and `ns`
|
|
179
|
+
* Default value is `ms`
|
|
180
|
+
|
|
181
|
+
Controls the sub-second precision of the stored timestamp.
|
|
182
|
+
|
|
183
|
+
`ms` stores data in millisecond precision. Custom pattern formats use https://www.joda.org/joda-time/key_format.html[joda-time] parsing rules. For example, `yyyy-MM-dd HH:mm:ss ZZZ`.
|
|
184
|
+
|
|
185
|
+
`ns` stores data in nanosecond precision. Custom pattern formats use https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/format/DateTimeFormatter.html[java.time] parsing rules. For example, `yyyy-MM-dd HH:mm:ss VV`.
|
|
178
186
|
|
|
179
187
|
[id="plugins-{type}s-{plugin}-tag_on_failure"]
|
|
180
|
-
===== `tag_on_failure`
|
|
188
|
+
===== `tag_on_failure`
|
|
181
189
|
|
|
182
190
|
* Value type is <<array,array>>
|
|
183
191
|
* Default value is `["_dateparsefailure"]`
|
|
@@ -57,9 +57,8 @@ class LogStash::Filters::Date < LogStash::Filters::Base
|
|
|
57
57
|
# There are a few special exceptions. The following format literals exist
|
|
58
58
|
# to help you save time and ensure correctness of date parsing.
|
|
59
59
|
#
|
|
60
|
-
# * `ISO8601` - should parse any valid ISO8601 timestamp
|
|
61
|
-
#
|
|
62
|
-
# * `UNIX` - will parse *float or int* value expressing unix time in seconds since epoch like 1326149001.132 as well as 1326149001
|
|
60
|
+
# * `ISO8601` - should parse any valid ISO8601 timestamp with up to 9 fractional-second digits
|
|
61
|
+
# * `UNIX` - will parse *float or int* value expressing unix time in seconds since epoch like 1326149001.123456789 as well as 1326149001
|
|
63
62
|
# * `UNIX_MS` - will parse **int** value expressing unix time in milliseconds since epoch like 1366125117000
|
|
64
63
|
# * `TAI64N` - will parse tai64n time values
|
|
65
64
|
#
|
|
@@ -84,57 +83,57 @@ class LogStash::Filters::Date < LogStash::Filters::Base
|
|
|
84
83
|
#
|
|
85
84
|
# Here's what you can use to parse dates and times:
|
|
86
85
|
#
|
|
87
|
-
#
|
|
88
|
-
#
|
|
89
|
-
#
|
|
90
|
-
# yy::: two-digit year. Example: `15` for the year 2015.
|
|
86
|
+
# * `y`: year
|
|
87
|
+
# ** `yyyy`: full year number. Example: `2015`.
|
|
88
|
+
# ** `yy`: two-digit year. Example: `15` for the year 2015.
|
|
91
89
|
#
|
|
92
|
-
# M
|
|
93
|
-
#
|
|
94
|
-
#
|
|
95
|
-
#
|
|
96
|
-
#
|
|
90
|
+
# * `M`: month of the year
|
|
91
|
+
# ** `M`: minimal-digit month. Example: `1` for January and `12` for December.
|
|
92
|
+
# ** `MM`: two-digit month. zero-padded if needed. Example: `01` for January and `12` for December
|
|
93
|
+
# ** `MMM`: abbreviated month text. Example: `Jan` for January. Note: The language used depends on your locale. See the `locale` setting for how to change the language.
|
|
94
|
+
# ** `MMMM`: full month text, Example: `January`. Note: The language used depends on your locale.
|
|
97
95
|
#
|
|
98
|
-
# d
|
|
99
|
-
#
|
|
100
|
-
#
|
|
96
|
+
# * `d`: day of the month
|
|
97
|
+
# ** `d`: minimal-digit day. Example: `1` for the 1st of the month.
|
|
98
|
+
# ** `dd`: two-digit day, zero-padded if needed. Example: `01` for the 1st of the month.
|
|
101
99
|
#
|
|
102
|
-
# H
|
|
103
|
-
#
|
|
104
|
-
#
|
|
100
|
+
# * `H`: hour of the day (24-hour clock)
|
|
101
|
+
# ** `H`: minimal-digit hour. Example: `0` for midnight.
|
|
102
|
+
# ** `HH`: two-digit hour, zero-padded if needed. Example: `00` for midnight.
|
|
105
103
|
#
|
|
106
|
-
# m
|
|
107
|
-
#
|
|
108
|
-
#
|
|
104
|
+
# * `m`: minutes of the hour (60 minutes per hour)
|
|
105
|
+
# ** `m`: minimal-digit minutes. Example: `0`.
|
|
106
|
+
# ** `mm`: two-digit minutes, zero-padded if needed. Example: `00`.
|
|
109
107
|
#
|
|
110
|
-
# s
|
|
111
|
-
#
|
|
112
|
-
#
|
|
108
|
+
# * `s`: seconds of the minute (60 seconds per minute)
|
|
109
|
+
# ** `s`: minimal-digit seconds. Example: `0`.
|
|
110
|
+
# ** `ss`: two-digit seconds, zero-padded if needed. Example: `00`.
|
|
113
111
|
#
|
|
114
|
-
# S
|
|
115
|
-
#
|
|
116
|
-
#
|
|
117
|
-
#
|
|
118
|
-
#
|
|
112
|
+
# * `S`: fraction of a second
|
|
113
|
+
# ** `S`: tenths of a second. Example: `0` for a subsecond value `012`
|
|
114
|
+
# ** `SS`: hundredths of a second. Example: `01` for a subsecond value `01`
|
|
115
|
+
# ** `SSS`: milliseconds. Example: `012` for a subsecond value `012`
|
|
116
|
+
# ** `SSSSSS`: microseconds.
|
|
117
|
+
# ** `SSSSSSSSS`: nanoseconds.
|
|
119
118
|
#
|
|
120
|
-
# Z
|
|
121
|
-
#
|
|
122
|
-
#
|
|
123
|
-
#
|
|
119
|
+
# * `Z`: time zone offset or identity
|
|
120
|
+
# ** `Z`: Timezone offset structured as HHmm (hour and minutes offset from Zulu/UTC). Example: `-0700`.
|
|
121
|
+
# ** `ZZ`: Timezone offset structured as HH:mm (colon in between hour and minute offsets). Example: `-07:00`.
|
|
122
|
+
# ** `ZZZ`: Timezone identity. Example: `America/Los_Angeles`. Note: Valid IDs are listed on the http://joda-time.sourceforge.net/timezones.html[Joda.org available time zones page].
|
|
124
123
|
#
|
|
125
|
-
# z
|
|
124
|
+
# * `z`: time zone names. *Time zone names (`z`) cannot be parsed.*
|
|
126
125
|
#
|
|
127
|
-
# w
|
|
128
|
-
#
|
|
129
|
-
#
|
|
126
|
+
# * `w`: week of the year
|
|
127
|
+
# ** `w`: minimal-digit week. Example: `1`.
|
|
128
|
+
# ** `ww`: two-digit week, zero-padded if needed. Example: `01`.
|
|
130
129
|
#
|
|
131
|
-
# D
|
|
130
|
+
# * `D`: day of the year
|
|
132
131
|
#
|
|
133
|
-
# e
|
|
132
|
+
# * `e`: day of the week (number)
|
|
134
133
|
#
|
|
135
|
-
# E
|
|
136
|
-
#
|
|
137
|
-
#
|
|
134
|
+
# * `E`: day of the week (text)
|
|
135
|
+
# ** `E`, `EE`, `EEE`: Abbreviated day of the week. Example: `Mon`, `Tue`, `Wed`, `Thu`, `Fri`, `Sat`, `Sun`. Note: The actual language of this will depend on your locale.
|
|
136
|
+
# ** `EEEE`: The full text day of the week. Example: `Monday`, `Tuesday`, ... Note: The actual language of this will depend on your locale.
|
|
138
137
|
#
|
|
139
138
|
# For non-formatting syntax, you'll need to put single-quote characters around the value. For example, if you were parsing ISO8601 time, "2015-01-01T01:12:23" that little "T" isn't a valid time format, and you want to say "literally, a T", your format would be this: "yyyy-MM-dd'T'HH:mm:ss"
|
|
140
139
|
#
|
|
@@ -150,6 +149,14 @@ class LogStash::Filters::Date < LogStash::Filters::Base
|
|
|
150
149
|
# successful match
|
|
151
150
|
config :tag_on_failure, :validate => :array, :default => ["_dateparsefailure"]
|
|
152
151
|
|
|
152
|
+
# Controls the sub-second precision of the stored timestamp.
|
|
153
|
+
#
|
|
154
|
+
# `"ms"` (default):: Stores in millisecond precision. Custom-pattern formats use Joda-Time parsing rules.
|
|
155
|
+
# `"ns"`:: Stores in nanosecond precision. Custom-pattern formats use java.time parsing rules.
|
|
156
|
+
config :precision, :validate => [Java::OrgLogstashFiltersParser::TimestampParserFactory::PRECISION_MS,
|
|
157
|
+
Java::OrgLogstashFiltersParser::TimestampParserFactory::PRECISION_NS],
|
|
158
|
+
:default => Java::OrgLogstashFiltersParser::TimestampParserFactory::PRECISION_MS
|
|
159
|
+
|
|
153
160
|
def register
|
|
154
161
|
# nothing
|
|
155
162
|
end
|
|
@@ -179,13 +186,13 @@ class LogStash::Filters::Date < LogStash::Filters::Base
|
|
|
179
186
|
metric.increment(:failures)
|
|
180
187
|
end
|
|
181
188
|
|
|
182
|
-
@datefilter = org.logstash.filters.DateFilter.new(source, @target, @tag_on_failure, success_block, failure_block)
|
|
189
|
+
@datefilter = org.logstash.filters.DateFilter.new(source, @target, @tag_on_failure, @precision, success_block, failure_block)
|
|
183
190
|
|
|
184
191
|
@match[1..-1].map do |format|
|
|
185
192
|
@datefilter.accept_filter_config(format, @locale, @timezone)
|
|
186
193
|
|
|
187
194
|
# Offer a fallback parser such that if the default system Locale is non-english and that no locale is set,
|
|
188
|
-
# we should try to parse english if the first local parsing fails
|
|
195
|
+
# we should try to parse english if the first local parsing fails.
|
|
189
196
|
if !@locale && "en" != java.util.Locale.getDefault().getLanguage() && (format.include?("MMM") || format.include?("E"))
|
|
190
197
|
@datefilter.accept_filter_config(format, "en-US", @timezone)
|
|
191
198
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
|
|
3
3
|
s.name = 'logstash-filter-date'
|
|
4
|
-
s.version = '3.1
|
|
4
|
+
s.version = '3.2.1'
|
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
|
6
6
|
s.summary = "Parses dates from fields to use as the Logstash timestamp for an 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/logstash-plugin install gemname. This gem is not a stand-alone program"
|
data/spec/filters/date_spec.rb
CHANGED
|
@@ -17,62 +17,6 @@ RUBY_ENGINE == "jruby" and describe LogStash::Filters::Date do
|
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
describe "parsing with ISO8601" do
|
|
21
|
-
config <<-CONFIG
|
|
22
|
-
filter {
|
|
23
|
-
date {
|
|
24
|
-
match => [ "mydate", "ISO8601" ]
|
|
25
|
-
locale => "en"
|
|
26
|
-
timezone => "UTC"
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
CONFIG
|
|
30
|
-
|
|
31
|
-
times = {
|
|
32
|
-
"2001-01-01T00:00:00-0800" => "2001-01-01T08:00:00.000Z",
|
|
33
|
-
"1974-03-02T04:09:09-0800" => "1974-03-02T12:09:09.000Z",
|
|
34
|
-
"2010-05-03T08:18:18+00:00" => "2010-05-03T08:18:18.000Z",
|
|
35
|
-
"2004-07-04T12:27:27-00:00" => "2004-07-04T12:27:27.000Z",
|
|
36
|
-
"2001-09-05T16:36:36+0000" => "2001-09-05T16:36:36.000Z",
|
|
37
|
-
"2001-11-06T20:45:45-0000" => "2001-11-06T20:45:45.000Z",
|
|
38
|
-
"2001-12-07T23:54:54Z" => "2001-12-07T23:54:54.000Z",
|
|
39
|
-
|
|
40
|
-
# TODO: This test assumes PDT
|
|
41
|
-
#"2001-01-01T00:00:00.123" => "2001-01-01T08:00:00.123Z",
|
|
42
|
-
|
|
43
|
-
"2010-05-03T08:18:18.123+00:00" => "2010-05-03T08:18:18.123Z",
|
|
44
|
-
"2004-07-04T12:27:27.123-04:00" => "2004-07-04T16:27:27.123Z",
|
|
45
|
-
"2001-09-05T16:36:36.123+0700" => "2001-09-05T09:36:36.123Z",
|
|
46
|
-
"2001-11-06T20:45:45.123-0000" => "2001-11-06T20:45:45.123Z",
|
|
47
|
-
"2001-12-07T23:54:54.123Z" => "2001-12-07T23:54:54.123Z",
|
|
48
|
-
"2001-12-07T23:54:54,123Z" => "2001-12-07T23:54:54.123Z",
|
|
49
|
-
|
|
50
|
-
#Almost ISO8601 support, with timezone
|
|
51
|
-
|
|
52
|
-
"2001-11-06 20:45:45.123-0000" => "2001-11-06T20:45:45.123Z",
|
|
53
|
-
"2001-12-07 23:54:54.123Z" => "2001-12-07T23:54:54.123Z",
|
|
54
|
-
"2001-12-07 23:54:54,123Z" => "2001-12-07T23:54:54.123Z",
|
|
55
|
-
|
|
56
|
-
#Almost ISO8601 support, without timezone
|
|
57
|
-
|
|
58
|
-
"2001-11-06 20:45:45.123" => "2001-11-06T20:45:45.123Z",
|
|
59
|
-
"2001-11-06 20:45:45,123" => "2001-11-06T20:45:45.123Z",
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
times.each do |input, output|
|
|
64
|
-
sample({"mydate" => input}) do
|
|
65
|
-
begin
|
|
66
|
-
insist { subject.get("mydate") } == input
|
|
67
|
-
insist { subject.get("@timestamp").time } == Time.iso8601(output).utc
|
|
68
|
-
rescue
|
|
69
|
-
#require "pry"; binding.pry
|
|
70
|
-
raise
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end # times.each
|
|
74
|
-
end
|
|
75
|
-
|
|
76
20
|
describe "parsing with java SimpleDateFormat syntax" do
|
|
77
21
|
config <<-CONFIG
|
|
78
22
|
filter {
|
|
@@ -132,44 +76,6 @@ RUBY_ENGINE == "jruby" and describe LogStash::Filters::Date do
|
|
|
132
76
|
end
|
|
133
77
|
end
|
|
134
78
|
|
|
135
|
-
describe "parsing microsecond-precise times with UNIX (#213)" do
|
|
136
|
-
config <<-CONFIG
|
|
137
|
-
filter {
|
|
138
|
-
date {
|
|
139
|
-
match => [ "mydate", "UNIX" ]
|
|
140
|
-
locale => "en"
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
CONFIG
|
|
144
|
-
|
|
145
|
-
sample({"mydate" => "1350414944.123456"}) do
|
|
146
|
-
# Joda time only supports milliseconds :\
|
|
147
|
-
insist { subject.timestamp.time } == Time.iso8601("2012-10-16T12:15:44.123-07:00").utc
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
#Support float values
|
|
151
|
-
sample({"mydate" => 1350414944.123456}) do
|
|
152
|
-
insist { subject.get("mydate") } == 1350414944.123456
|
|
153
|
-
insist { subject.get("@timestamp").time } == Time.iso8601("2012-10-16T12:15:44.123-07:00").utc
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
#Invalid value should not be evaluated to zero (String#to_i madness)
|
|
157
|
-
sample({"mydate" => "%{bad_value}"}) do
|
|
158
|
-
insist { subject.get("mydate") } == "%{bad_value}"
|
|
159
|
-
insist { subject.get("@timestamp").time } != Time.iso8601("1970-01-01T00:00:00.000Z").utc
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
# Regression test
|
|
163
|
-
# Support numeric values that come through the JSON parser. These numbers appear as BigDecimal
|
|
164
|
-
# instead of Float.
|
|
165
|
-
sample(LogStash::Json.load('{ "mydate": 1350414944.123456 }')) do
|
|
166
|
-
# its generally problematic to compare different Floating Point class implementations using equals
|
|
167
|
-
# because they can't always represent a value exactly.
|
|
168
|
-
insist { subject.get("mydate") } == BigDecimal.new("1350414944.123456")
|
|
169
|
-
insist { subject.get("@timestamp").time } == Time.iso8601("2012-10-16T12:15:44.123-07:00").utc
|
|
170
|
-
end
|
|
171
|
-
end
|
|
172
|
-
|
|
173
79
|
describe "parsing with UNIX_MS" do
|
|
174
80
|
config <<-CONFIG
|
|
175
81
|
filter {
|
|
@@ -269,16 +175,9 @@ RUBY_ENGINE == "jruby" and describe LogStash::Filters::Date do
|
|
|
269
175
|
}
|
|
270
176
|
CONFIG
|
|
271
177
|
|
|
272
|
-
# Try without leading "@"
|
|
273
178
|
sample({"t" => "4000000050d506482dbdf024"}) do
|
|
274
179
|
insist { subject.timestamp.time } == Time.iso8601("2012-12-22T01:00:46.767Z").utc
|
|
275
180
|
end
|
|
276
|
-
|
|
277
|
-
# Should still parse successfully if it's a full tai64n time (with leading
|
|
278
|
-
# '@')
|
|
279
|
-
sample({"t" => "@4000000050d506482dbdf024"}) do
|
|
280
|
-
insist { subject.timestamp.time } == Time.iso8601("2012-12-22T01:00:46.767Z").utc
|
|
281
|
-
end
|
|
282
181
|
end
|
|
283
182
|
|
|
284
183
|
describe "accept match config option with hash value (LOGSTASH-735)" do
|
|
@@ -461,189 +360,6 @@ RUBY_ENGINE == "jruby" and describe LogStash::Filters::Date do
|
|
|
461
360
|
end
|
|
462
361
|
end
|
|
463
362
|
|
|
464
|
-
describe "don't fail on next years DST switchover in CET" do
|
|
465
|
-
config <<-CONFIG
|
|
466
|
-
filter {
|
|
467
|
-
date {
|
|
468
|
-
match => [ "message", "yyyy MMM dd HH:mm:ss" ]
|
|
469
|
-
locale => "en"
|
|
470
|
-
timezone => "CET"
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
CONFIG
|
|
474
|
-
|
|
475
|
-
before(:each) do
|
|
476
|
-
logstash_time = Time.utc(2016,03,29,23,59,50)
|
|
477
|
-
allow(Time).to receive(:now).and_return(logstash_time)
|
|
478
|
-
end
|
|
479
|
-
|
|
480
|
-
sample "2016 Mar 26 02:00:37" do
|
|
481
|
-
insist { subject.get("tags") } != ["_dateparsefailure"]
|
|
482
|
-
expect(subject.get("@timestamp")).to be_a_logstash_timestamp_equivalent_to("2016-03-26T01:00:37.000Z")
|
|
483
|
-
end
|
|
484
|
-
end
|
|
485
|
-
|
|
486
|
-
context "Default year handling when parsing with timezone from event" do
|
|
487
|
-
|
|
488
|
-
describe "LOGSTASH-34 - Default year should be this year" do
|
|
489
|
-
config <<-CONFIG
|
|
490
|
-
filter {
|
|
491
|
-
date {
|
|
492
|
-
match => [ "message", "EEE MMM dd HH:mm:ss" ]
|
|
493
|
-
locale => "en"
|
|
494
|
-
timezone => "%{mytz}"
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
CONFIG
|
|
498
|
-
|
|
499
|
-
sample({"message" => "Sun Jun 02 20:38:03", "mytz" => "UTC"}) do
|
|
500
|
-
insist { subject.get("@timestamp").year } == Time.now.year
|
|
501
|
-
end
|
|
502
|
-
end
|
|
503
|
-
|
|
504
|
-
describe "fill last year if december events arrive in january" do
|
|
505
|
-
config <<-CONFIG
|
|
506
|
-
filter {
|
|
507
|
-
date {
|
|
508
|
-
match => [ "message", "MMM dd HH:mm:ss" ]
|
|
509
|
-
locale => "en"
|
|
510
|
-
timezone => "%{mytz}"
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
CONFIG
|
|
514
|
-
|
|
515
|
-
before(:each) do
|
|
516
|
-
logstash_time = Time.utc(2014,1,1,00,30,50)
|
|
517
|
-
allow(Time).to receive(:now).and_return(logstash_time)
|
|
518
|
-
org.logstash.filters.parser.JodaParser.setDefaultClock { org.joda.time.DateTime.new(2014,1,1,00,30,50, org.joda.time.DateTimeZone::UTC ) }
|
|
519
|
-
end
|
|
520
|
-
|
|
521
|
-
sample({"message" => "Dec 31 23:59:00", "mytz" => "UTC"}) do
|
|
522
|
-
insist { subject.get("@timestamp").year } == 2013
|
|
523
|
-
end
|
|
524
|
-
end
|
|
525
|
-
|
|
526
|
-
describe "fill next year if january events arrive in december" do
|
|
527
|
-
config <<-CONFIG
|
|
528
|
-
filter {
|
|
529
|
-
date {
|
|
530
|
-
match => [ "message", "MMM dd HH:mm:ss" ]
|
|
531
|
-
locale => "en"
|
|
532
|
-
timezone => "%{mytz}"
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
CONFIG
|
|
536
|
-
|
|
537
|
-
before(:each) do
|
|
538
|
-
logstash_time = Time.utc(2013,12,31,23,59,50)
|
|
539
|
-
allow(Time).to receive(:now).and_return(logstash_time)
|
|
540
|
-
org.logstash.filters.parser.JodaParser.setDefaultClock { org.joda.time.DateTime.new(2013,12,31,23,59,50, org.joda.time.DateTimeZone::UTC ) }
|
|
541
|
-
end
|
|
542
|
-
|
|
543
|
-
sample({"message" => "Jan 01 01:00:00", "mytz" => "UTC"}) do
|
|
544
|
-
insist { subject.get("@timestamp").year } == 2014
|
|
545
|
-
end
|
|
546
|
-
end
|
|
547
|
-
|
|
548
|
-
describe "do fail on 2016 DST switchover in CET" do
|
|
549
|
-
# This test tries to parse a time that doesn't exist. '02:00:01' is a time that doesn't exist
|
|
550
|
-
# because this DST switch goes from 01:59:59 to 03:00:00, skipping 2am entirely. The last Sunday of March in 2016 was 27th.
|
|
551
|
-
# (Guy Boertje) Fixed the GuessYear logic
|
|
552
|
-
# Joda has a default year for DateTimeFormat of 2000
|
|
553
|
-
# meaning that the initial time parsed was Monday 2000-03-27 02:00:01 and the last Sunday of March in 2000 was the 26th
|
|
554
|
-
# then by adding the year of 2016 creates an invalid time
|
|
555
|
-
# The parser default now takes the year from the DefaultClock in the JodaParser
|
|
556
|
-
config <<-CONFIG
|
|
557
|
-
filter {
|
|
558
|
-
date {
|
|
559
|
-
match => [ "message", "MMM dd HH:mm:ss" ]
|
|
560
|
-
locale => "en"
|
|
561
|
-
timezone => "CET"
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
CONFIG
|
|
565
|
-
|
|
566
|
-
before(:each) do
|
|
567
|
-
logstash_time = Time.utc(2016,03,29,23,59,50)
|
|
568
|
-
allow(Time).to receive(:now).and_return(logstash_time)
|
|
569
|
-
org.logstash.filters.parser.JodaParser.setDefaultClock { org.joda.time.DateTime.new(2016,03,29,23,59,50, org.joda.time.DateTimeZone::UTC ) }
|
|
570
|
-
end
|
|
571
|
-
|
|
572
|
-
sample "Mar 27 01:59:59" do
|
|
573
|
-
expect(subject.get("tags")).to be_nil
|
|
574
|
-
expect(subject.get("@timestamp")).to be_a_logstash_timestamp_equivalent_to("2016-03-27T00:59:59.000Z")
|
|
575
|
-
end
|
|
576
|
-
|
|
577
|
-
sample "Mar 27 02:00:01" do
|
|
578
|
-
expect(subject.get("tags")).to eq ["_dateparsefailure"]
|
|
579
|
-
end
|
|
580
|
-
|
|
581
|
-
sample "Mar 27 03:00:01" do
|
|
582
|
-
expect(subject.get("tags")).to be_nil
|
|
583
|
-
expect(subject.get("@timestamp")).to be_a_logstash_timestamp_equivalent_to("2016-03-27T01:00:01.000Z")
|
|
584
|
-
end
|
|
585
|
-
end
|
|
586
|
-
end
|
|
587
|
-
|
|
588
|
-
describe "LOGSTASH-34 - Default year should be this year" do
|
|
589
|
-
config <<-CONFIG
|
|
590
|
-
filter {
|
|
591
|
-
date {
|
|
592
|
-
match => [ "message", "EEE MMM dd HH:mm:ss" ]
|
|
593
|
-
locale => "en"
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
CONFIG
|
|
597
|
-
|
|
598
|
-
sample "Sun Jun 02 20:38:03" do
|
|
599
|
-
insist { subject.get("@timestamp").year } == Time.now.year
|
|
600
|
-
end
|
|
601
|
-
end
|
|
602
|
-
|
|
603
|
-
describe "fill last year if december events arrive in january" do
|
|
604
|
-
config <<-CONFIG
|
|
605
|
-
filter {
|
|
606
|
-
date {
|
|
607
|
-
match => [ "message", "MMM dd HH:mm:ss" ]
|
|
608
|
-
locale => "en"
|
|
609
|
-
timezone => "UTC"
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
CONFIG
|
|
613
|
-
|
|
614
|
-
before(:each) do
|
|
615
|
-
logstash_time = Time.utc(2014,1,1,00,30,50)
|
|
616
|
-
allow(Time).to receive(:now).and_return(logstash_time)
|
|
617
|
-
org.logstash.filters.parser.JodaParser.setDefaultClock { org.joda.time.DateTime.new(2014,1,1,00,30,50, org.joda.time.DateTimeZone::UTC ) }
|
|
618
|
-
end
|
|
619
|
-
|
|
620
|
-
sample "Dec 31 23:59:00" do
|
|
621
|
-
insist { subject.get("@timestamp").year } == 2013
|
|
622
|
-
end
|
|
623
|
-
end
|
|
624
|
-
|
|
625
|
-
describe "fill next year if january events arrive in december" do
|
|
626
|
-
config <<-CONFIG
|
|
627
|
-
filter {
|
|
628
|
-
date {
|
|
629
|
-
match => [ "message", "MMM dd HH:mm:ss" ]
|
|
630
|
-
locale => "en"
|
|
631
|
-
timezone => "UTC"
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
CONFIG
|
|
635
|
-
|
|
636
|
-
before(:each) do
|
|
637
|
-
logstash_time = Time.utc(2013,12,31,23,59,50)
|
|
638
|
-
allow(Time).to receive(:now).and_return(logstash_time)
|
|
639
|
-
org.logstash.filters.parser.JodaParser.setDefaultClock { org.joda.time.DateTime.new(2013,12,31,15,59,50, org.joda.time.DateTimeZone::UTC ) }
|
|
640
|
-
end
|
|
641
|
-
|
|
642
|
-
sample "Jan 01 01:00:00" do
|
|
643
|
-
insist { subject.get("@timestamp").year } == 2014
|
|
644
|
-
end
|
|
645
|
-
end
|
|
646
|
-
|
|
647
363
|
describe "Supporting locale only" do
|
|
648
364
|
config <<-CONFIG
|
|
649
365
|
filter {
|
|
@@ -731,74 +447,6 @@ RUBY_ENGINE == "jruby" and describe LogStash::Filters::Date do
|
|
|
731
447
|
end
|
|
732
448
|
end
|
|
733
449
|
|
|
734
|
-
context "Default year handling when parsing with english fallback parser" do
|
|
735
|
-
|
|
736
|
-
around do |example|
|
|
737
|
-
default = java.util.Locale.getDefault
|
|
738
|
-
java.util.Locale.setDefault(java.util.Locale.forLanguageTag('fr-FR'))
|
|
739
|
-
example.run
|
|
740
|
-
java.util.Locale.setDefault(default)
|
|
741
|
-
end
|
|
742
|
-
|
|
743
|
-
puts "override locale"
|
|
744
|
-
describe "LOGSTASH-34 - Default year should be this year" do
|
|
745
|
-
config <<-CONFIG
|
|
746
|
-
filter {
|
|
747
|
-
date {
|
|
748
|
-
match => [ "message", "EEE MMM dd HH:mm:ss" ]
|
|
749
|
-
timezone => "UTC"
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
CONFIG
|
|
753
|
-
|
|
754
|
-
sample "Sun Jun 02 20:38:03" do
|
|
755
|
-
insist { subject.get("@timestamp").year } == Time.now.year
|
|
756
|
-
end
|
|
757
|
-
end
|
|
758
|
-
|
|
759
|
-
describe "fill last year if december events arrive in january" do
|
|
760
|
-
config <<-CONFIG
|
|
761
|
-
filter {
|
|
762
|
-
date {
|
|
763
|
-
match => [ "message", "MMM dd HH:mm:ss" ]
|
|
764
|
-
timezone => "UTC"
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
CONFIG
|
|
768
|
-
|
|
769
|
-
before(:each) do
|
|
770
|
-
logstash_time = Time.utc(2014,1,1,00,30,50)
|
|
771
|
-
allow(Time).to receive(:now).and_return(logstash_time)
|
|
772
|
-
org.logstash.filters.parser.JodaParser.setDefaultClock { org.joda.time.DateTime.new(2014,1,1,00,30,50, org.joda.time.DateTimeZone::UTC) }
|
|
773
|
-
end
|
|
774
|
-
|
|
775
|
-
sample "Dec 31 23:59:00" do
|
|
776
|
-
insist { subject.get("@timestamp").year } == 2013
|
|
777
|
-
end
|
|
778
|
-
end
|
|
779
|
-
|
|
780
|
-
describe "fill next year if january events arrive in december" do
|
|
781
|
-
config <<-CONFIG
|
|
782
|
-
filter {
|
|
783
|
-
date {
|
|
784
|
-
match => [ "message", "MMM dd HH:mm:ss" ]
|
|
785
|
-
timezone => "UTC"
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
CONFIG
|
|
789
|
-
|
|
790
|
-
before(:each) do
|
|
791
|
-
logstash_time = Time.utc(2013,12,31,23,59,50)
|
|
792
|
-
allow(Time).to receive(:now).and_return(logstash_time)
|
|
793
|
-
org.logstash.filters.parser.JodaParser.setDefaultClock { org.joda.time.DateTime.new(2013,12,31,23,59,50, org.joda.time.DateTimeZone::UTC) }
|
|
794
|
-
end
|
|
795
|
-
|
|
796
|
-
sample "Jan 01 01:00:00" do
|
|
797
|
-
insist { subject.get("@timestamp").year } == 2014
|
|
798
|
-
end
|
|
799
|
-
end
|
|
800
|
-
end
|
|
801
|
-
|
|
802
450
|
describe "metric counters" do
|
|
803
451
|
subject { described_class.new("match" => [ "message", "yyyy" ]) }
|
|
804
452
|
|
|
@@ -872,4 +520,85 @@ RUBY_ENGINE == "jruby" and describe LogStash::Filters::Date do
|
|
|
872
520
|
end
|
|
873
521
|
end
|
|
874
522
|
end
|
|
523
|
+
|
|
524
|
+
describe "precision => ns, java.time with nanoseconds" do
|
|
525
|
+
config <<-CONFIG
|
|
526
|
+
filter {
|
|
527
|
+
date {
|
|
528
|
+
match => [ "mydate", "yyyy-MM-dd HH:mm:ss.SSSSSSSSS VV" ]
|
|
529
|
+
precision => "ns"
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
CONFIG
|
|
533
|
+
|
|
534
|
+
sample({"mydate" => "2016-11-03 21:10:57.123456789 America/New_York"}) do
|
|
535
|
+
insist { subject.get("@timestamp").time.to_i } == 1478221857
|
|
536
|
+
insist { subject.get("@timestamp").time.nsec } == 123456789
|
|
537
|
+
end
|
|
538
|
+
end
|
|
539
|
+
|
|
540
|
+
describe "precision => ns, ISO8601 with nanoseconds" do
|
|
541
|
+
config <<-CONFIG
|
|
542
|
+
filter {
|
|
543
|
+
date {
|
|
544
|
+
match => [ "mydate", "ISO8601" ]
|
|
545
|
+
precision => "ns"
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
CONFIG
|
|
549
|
+
|
|
550
|
+
sample({"mydate" => "2016-11-03T21:10:57.123456789Z"}) do
|
|
551
|
+
insist { subject.get("@timestamp").time.to_i } == 1478207457
|
|
552
|
+
insist { subject.get("@timestamp").time.nsec } == 123456789
|
|
553
|
+
end
|
|
554
|
+
end
|
|
555
|
+
|
|
556
|
+
describe "precision => ns, UNIX epoch string with nanoseconds" do
|
|
557
|
+
config <<-CONFIG
|
|
558
|
+
filter {
|
|
559
|
+
date {
|
|
560
|
+
match => [ "mydate", "UNIX" ]
|
|
561
|
+
precision => "ns"
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
CONFIG
|
|
565
|
+
|
|
566
|
+
sample({"mydate" => "1478207457.123456789"}) do
|
|
567
|
+
insist { subject.get("@timestamp").time.to_i } == 1478207457
|
|
568
|
+
insist { subject.get("@timestamp").time.nsec } == 123456789
|
|
569
|
+
end
|
|
570
|
+
end
|
|
571
|
+
|
|
572
|
+
describe "precision => ns, TAI64N full nanoseconds" do
|
|
573
|
+
config <<-CONFIG
|
|
574
|
+
filter {
|
|
575
|
+
date {
|
|
576
|
+
match => [ "mydate", "TAI64N" ]
|
|
577
|
+
precision => "ns"
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
CONFIG
|
|
581
|
+
|
|
582
|
+
sample({"mydate" => "4000000050d506482dbdf024"}) do
|
|
583
|
+
# 0x2dbdf024 = 767422500 ns
|
|
584
|
+
insist { subject.get("@timestamp").time.to_i } == 1356138046
|
|
585
|
+
insist { subject.get("@timestamp").time.nsec } == 767422500
|
|
586
|
+
end
|
|
587
|
+
end
|
|
588
|
+
|
|
589
|
+
describe "precision => ms (default) still truncates to milliseconds" do
|
|
590
|
+
config <<-CONFIG
|
|
591
|
+
filter {
|
|
592
|
+
date {
|
|
593
|
+
match => [ "mydate", "TAI64N" ]
|
|
594
|
+
precision => "ms"
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
CONFIG
|
|
598
|
+
|
|
599
|
+
sample({"mydate" => "4000000050d506482dbdf024"}) do
|
|
600
|
+
insist { subject.get("@timestamp").time.to_i } == 1356138046
|
|
601
|
+
insist { subject.get("@timestamp").time.nsec } == 767000000
|
|
602
|
+
end
|
|
603
|
+
end
|
|
875
604
|
end
|
|
@@ -92,57 +92,56 @@ class LogStash::Filters::DateRuby < LogStash::Filters::Base
|
|
|
92
92
|
#
|
|
93
93
|
# Here's what you can use to parse dates and times:
|
|
94
94
|
#
|
|
95
|
-
#
|
|
96
|
-
#
|
|
97
|
-
#
|
|
98
|
-
# yy::: two-digit year. Example: `15` for the year 2015.
|
|
95
|
+
# * `y`: year
|
|
96
|
+
# ** `yyyy`: full year number. Example: `2015`.
|
|
97
|
+
# ** `yy`: two-digit year. Example: `15` for the year 2015.
|
|
99
98
|
#
|
|
100
|
-
# M
|
|
101
|
-
#
|
|
102
|
-
#
|
|
103
|
-
#
|
|
104
|
-
#
|
|
99
|
+
# * `M`: month of the year
|
|
100
|
+
# ** `M`: minimal-digit month. Example: `1` for January and `12` for December.
|
|
101
|
+
# ** `MM`: two-digit month. zero-padded if needed. Example: `01` for January and `12` for December
|
|
102
|
+
# ** `MMM`: abbreviated month text. Example: `Jan` for January. Note: The language used depends on your locale. See the `locale` setting for how to change the language.
|
|
103
|
+
# ** `MMMM`: full month text, Example: `January`. Note: The language used depends on your locale.
|
|
105
104
|
#
|
|
106
|
-
# d
|
|
107
|
-
#
|
|
108
|
-
#
|
|
105
|
+
# * `d`: day of the month
|
|
106
|
+
# ** `d`: minimal-digit day. Example: `1` for the 1st of the month.
|
|
107
|
+
# ** `dd`: two-digit day, zero-padded if needed. Example: `01` for the 1st of the month.
|
|
109
108
|
#
|
|
110
|
-
# H
|
|
111
|
-
#
|
|
112
|
-
#
|
|
109
|
+
# * `H`: hour of the day (24-hour clock)
|
|
110
|
+
# ** `H`: minimal-digit hour. Example: `0` for midnight.
|
|
111
|
+
# ** `HH`: two-digit hour, zero-padded if needed. Example: `00` for midnight.
|
|
113
112
|
#
|
|
114
|
-
# m
|
|
115
|
-
#
|
|
116
|
-
#
|
|
113
|
+
# * `m`: minutes of the hour (60 minutes per hour)
|
|
114
|
+
# ** `m`: minimal-digit minutes. Example: `0`.
|
|
115
|
+
# ** `mm`: two-digit minutes, zero-padded if needed. Example: `00`.
|
|
117
116
|
#
|
|
118
|
-
# s
|
|
119
|
-
#
|
|
120
|
-
#
|
|
117
|
+
# * `s`: seconds of the minute (60 seconds per minute)
|
|
118
|
+
# ** `s`: minimal-digit seconds. Example: `0`.
|
|
119
|
+
# ** `ss`: two-digit seconds, zero-padded if needed. Example: `00`.
|
|
121
120
|
#
|
|
122
|
-
# S
|
|
123
|
-
#
|
|
124
|
-
#
|
|
125
|
-
#
|
|
126
|
-
#
|
|
121
|
+
# * `S`: fraction of a second
|
|
122
|
+
# ** Maximum precision is milliseconds (`SSS`). Beyond that, zeroes are appended.
|
|
123
|
+
# ** `S`: tenths of a second. Example: `0` for a subsecond value `012`
|
|
124
|
+
# ** `SS`: hundredths of a second. Example: `01` for a subsecond value `01`
|
|
125
|
+
# ** `SSS`: thousandths of a second. Example: `012` for a subsecond value `012`
|
|
127
126
|
#
|
|
128
|
-
# Z
|
|
129
|
-
#
|
|
130
|
-
#
|
|
131
|
-
#
|
|
127
|
+
# * `Z`: time zone offset or identity
|
|
128
|
+
# ** `Z`: Timezone offset structured as HHmm (hour and minutes offset from Zulu/UTC). Example: `-0700`.
|
|
129
|
+
# ** `ZZ`: Timezone offset structured as HH:mm (colon in between hour and minute offsets). Example: `-07:00`.
|
|
130
|
+
# ** `ZZZ`: Timezone identity. Example: `America/Los_Angeles`. Note: Valid IDs are listed on the http://joda-time.sourceforge.net/timezones.html[Joda.org available time zones page].
|
|
132
131
|
#
|
|
133
|
-
# z
|
|
132
|
+
# * `z`: time zone names. *Time zone names (`z`) cannot be parsed.*
|
|
134
133
|
#
|
|
135
|
-
# w
|
|
136
|
-
#
|
|
137
|
-
#
|
|
134
|
+
# * `w`: week of the year
|
|
135
|
+
# ** `w`: minimal-digit week. Example: `1`.
|
|
136
|
+
# ** `ww`: two-digit week, zero-padded if needed. Example: `01`.
|
|
138
137
|
#
|
|
139
|
-
# D
|
|
138
|
+
# * `D`: day of the year
|
|
140
139
|
#
|
|
141
|
-
# e
|
|
140
|
+
# * `e`: day of the week (number)
|
|
142
141
|
#
|
|
143
|
-
# E
|
|
144
|
-
#
|
|
145
|
-
#
|
|
142
|
+
# * `E`: day of the week (text)
|
|
143
|
+
# ** `E`, `EE`, `EEE`: Abbreviated day of the week. Example: `Mon`, `Tue`, `Wed`, `Thu`, `Fri`, `Sat`, `Sun`. Note: The actual language of this will depend on your locale.
|
|
144
|
+
# ** `EEEE`: The full text day of the week. Example: `Monday`, `Tuesday`, ... Note: The actual language of this will depend on your locale.
|
|
146
145
|
#
|
|
147
146
|
# For non-formatting syntax, you'll need to put single-quote characters around the value. For example, if you were parsing ISO8601 time, "2015-01-01T01:12:23" that little "T" isn't a valid time format, and you want to say "literally, a T", your format would be this: "yyyy-MM-dd'T'HH:mm:ss"
|
|
148
147
|
#
|
|
Binary file
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: logstash-filter-date
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.1
|
|
4
|
+
version: 3.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Elastic
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-
|
|
10
|
+
date: 2026-05-07 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: logstash-core-plugin-api
|