Support microsecond timestamp format (#1426)

Adds microsecond timestamp support.

https://github.com/grafana/loki/issues/1407
pull/1448/head
wphan 6 years ago committed by Cyril Tovena
parent a2c2a90907
commit d627cda848
  1. 2
      docs/clients/promtail/configuration.md
  2. 3
      docs/clients/promtail/stages/timestamp.md
  3. 1
      pkg/logentry/stages/timestamp.go
  4. 11
      pkg/logentry/stages/timestamp_test.go
  5. 8
      pkg/logentry/stages/util.go

@ -410,7 +410,7 @@ timestamp:
# Determines how to parse the time string. Can use
# pre-defined formats by name: [ANSIC UnixDate RubyDate RFC822
# RFC822Z RFC850 RFC1123 RFC1123Z RFC3339 RFC3339Nano Unix
# UnixMs UnixNs].
# UnixMs UnixUs UnixNs].
format: <string>
# IANA Timezone Database string.

@ -14,7 +14,7 @@ timestamp:
# Determines how to parse the time string. Can use
# pre-defined formats by name: [ANSIC UnixDate RubyDate RFC822
# RFC822Z RFC850 RFC1123 RFC1123Z RFC3339 RFC3339Nano Unix
# UnixMs UnixNs].
# UnixMs UnixUs UnixNs].
format: <string>
# IANA Timezone Database string.
@ -46,6 +46,7 @@ Additionally, support for common Unix timestamps is supported with the following
- `Unix`: `1562708916`
- `UnixMs`: `1562708916414`
- `UnixUs`: `1562708916414123`
- `UnixNs`: `1562708916000000123`
Custom formats are passed directly to the layout parameter in Go's

@ -26,6 +26,7 @@ const (
Unix = "Unix"
UnixMs = "UnixMs"
UnixUs = "UnixUs"
UnixNs = "UnixNs"
TimestampActionOnFailureSkip = "skip"

@ -203,6 +203,17 @@ func TestTimestampStage_Process(t *testing.T) {
},
time.Date(2019, 7, 9, 21, 48, 36, 414*1000000, time.UTC),
},
"unix microsecond success": {
TimestampConfig{
Source: "ts",
Format: "UnixUs",
},
map[string]interface{}{
"somethigelse": "notimportant",
"ts": "1562708916414123",
},
time.Date(2019, 7, 9, 21, 48, 36, 414123*1000, time.UTC),
},
"unix nano success": {
TimestampConfig{
Source: "ts",

@ -78,6 +78,14 @@ func convertDateLayout(predef string, location *time.Location) parser {
}
return time.Unix(0, i*int64(time.Millisecond)), nil
}
case "UnixUs":
return func(t string) (time.Time, error) {
i, err := strconv.ParseInt(t, 10, 64)
if err != nil {
return time.Time{}, err
}
return time.Unix(0, i*int64(time.Microsecond)), nil
}
case "UnixNs":
return func(t string) (time.Time, error) {
i, err := strconv.ParseInt(t, 10, 64)

Loading…
Cancel
Save