Skip to content
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

Promtail: Fix timestamp parser for short year format #2708

Merged
merged 1 commit into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/logentry/stages/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func convertDateLayout(predef string, location *time.Location) parser {
return time.Unix(0, i), nil
}
default:
if !strings.Contains(predef, "2006") {
if !strings.Contains(predef, "06") && !strings.Contains(predef, "2006") {
return func(t string) (time.Time, error) {
return parseTimestampWithoutYear(predef, location, t, time.Now())
}
Expand Down
22 changes: 20 additions & 2 deletions pkg/logentry/stages/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,37 @@ func TestConvertDateLayout(t *testing.T) {
timestamp string
expected time.Time
}{
"custom layout with year": {
"custom layout with short year": {
"06 Jan 02 15:04:05",
nil,
"19 Jul 15 01:02:03",
time.Date(2019, 7, 15, 1, 2, 3, 0, time.UTC),
},
"custom layout with long year": {
"2006 Jan 02 15:04:05",
nil,
"2019 Jul 15 01:02:03",
time.Date(2019, 7, 15, 1, 2, 3, 0, time.UTC),
},
"custom layout with short year and location": {
"06 Jan 02 15:04:05",
location,
"19 Jul 15 01:02:03",
time.Date(2019, 7, 15, 1, 2, 3, 0, location),
},
"custom layout with long year and location": {
"2006 Jan 02 15:04:05",
location,
"2019 Jul 15 01:02:03",
time.Date(2019, 7, 15, 1, 2, 3, 0, location),
},
"custom layout without year": {
"Jan 02 15:04:05",
nil,
"Jul 15 01:02:03",
time.Date(time.Now().Year(), 7, 15, 1, 2, 3, 0, time.UTC),
},
"custom layout with year and location": {
"custom layout without year and location": {
"Jan 02 15:04:05",
location,
"Jul 15 01:02:03",
Expand Down