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: support unix timestamps with fractional seconds #2301

Merged
merged 5 commits into from
Jul 6, 2020
Merged
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions pkg/logentry/stages/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package stages

import (
"fmt"
"math"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -64,6 +65,19 @@ func convertDateLayout(predef string, location *time.Location) parser {
}
case "Unix":
return func(t string) (time.Time, error) {
if strings.Count(t, ".") == 1 {
split := strings.Split(t, ".")
cyriltovena marked this conversation as resolved.
Show resolved Hide resolved
sec, err := strconv.ParseInt(split[0], 10, 64)
if err != nil {
return time.Time{}, err
}
frac, err := strconv.ParseInt(split[1], 10, 64)
if err != nil {
return time.Time{}, err
}
nsec := int64(float64(frac) * math.Pow(10, float64(9-len(split[1]))))
return time.Unix(sec, nsec), nil
}
i, err := strconv.ParseInt(t, 10, 64)
if err != nil {
return time.Time{}, err
Expand Down