Skip to content

Commit

Permalink
feat: Support ts as time field (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihai22125 committed Sep 8, 2023
1 parent aa8e0d3 commit 40a5d31
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions internal/pkg/source/entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ func TestParseLogEntry(t *testing.T) {
assert.Equal(t, "1", logEntry.Time)
},
}, {
Name: "ts_number",
JSON: `{"ts":1}`,
Assert: func(tb testing.TB, logEntry source.LogEntry) {
tb.Helper()

assert.Equal(t, "1", logEntry.Time)
},
}, {
Name: "time_text",
JSON: `{"time":"1970-01-01T00:00:00.00"}`,
Assert: func(tb testing.TB, logEntry source.LogEntry) {
Expand All @@ -60,6 +68,14 @@ func TestParseLogEntry(t *testing.T) {
assert.Equal(t, "1970-01-01T00:00:00.00", logEntry.Time)
},
}, {
Name: "ts_text",
JSON: `{"ts":"1970-01-01T00:00:00.00"}`,
Assert: func(tb testing.TB, logEntry source.LogEntry) {
tb.Helper()

assert.Equal(t, "1970-01-01T00:00:00.00", logEntry.Time)
},
}, {
Name: "message",
JSON: `{"message":"message"}`,
Assert: func(tb testing.TB, logEntry source.LogEntry) {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/source/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func extractTime(value *fastjson.Value) string {
timeValue := extractValue(value, "timestamp", "time", "t")
timeValue := extractValue(value, "timestamp", "time", "t", "ts")
if timeValue != "" {
return formatMessage(strings.TrimSpace(timeValue))
}
Expand Down

0 comments on commit 40a5d31

Please sign in to comment.