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 #2193

Closed
flixr opened this issue Jun 7, 2020 · 0 comments · Fixed by #2301
Closed

promtail: support unix timestamps with fractional seconds #2193

flixr opened this issue Jun 7, 2020 · 0 comments · Fixed by #2301

Comments

@flixr
Copy link
Contributor

flixr commented Jun 7, 2020

Is your feature request related to a problem? Please describe.

Basically all of our logs contain timestamps like 1591375232, 1591375232.833 or 1591375232.833587995 (in the same logfile) and it would be a pity to loose the fractions.

Describe the solution you'd like
The Unix format in the timestamp stage should also accept fractional seconds.

Describe alternatives you've considered
Current alternative is to write a regex that only extracts the full seconds, but this is clearly not very nice.

Additional context

Maybe something like this in util.go:

	case "Unix":
		return func(t string) (time.Time, error) {
			if strings.Contains(t, ".") {
				f, err := strconv.ParseFloat(t, 64)
				if err != nil {
					return time.Time{}, err
				}
				sec, dec := math.Modf(f)
				return time.Unix(int64(sec), int64(dec*(1e9))), nil
			}
			i, err := strconv.ParseInt(t, 10, 64)
			if err != nil {
				return time.Time{}, err
			}
			return time.Unix(i, 0), nil
		}
flixr added a commit to flixr/loki that referenced this issue Jul 6, 2020
cyriltovena added a commit that referenced this issue Jul 6, 2020
* support unix timestamps with fractional seconds

see #2193

* add test for parsing unix timestamp with fractions

* mention Unix timestamp with fractions in docs

* return error if timestamp is not split into two parts

* don't capitalize error

Co-authored-by: Cyril Tovena <cyril.tovena@gmail.com>

Co-authored-by: Cyril Tovena <cyril.tovena@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant