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

Consider a Timestamp() or similar Converter in OTTL #36870

Open
bixu opened this issue Dec 17, 2024 · 2 comments
Open

Consider a Timestamp() or similar Converter in OTTL #36870

bixu opened this issue Dec 17, 2024 · 2 comments
Labels
enhancement New feature or request pkg/ottl

Comments

@bixu
Copy link

bixu commented Dec 17, 2024

Component(s)

pkg/ottl

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

Consider a use-case where we want to normalize too-old timestamps on incoming telemetry. For debugging purposes, we might want to keep a copy of the original timestamp. Since the original timestamp data is in nanoseconds since the epoch, the raw value can be hard for humans to interpret.

Describe the solution you'd like

We could consider adding a Converter to translate the nanosecond epoch back to a human-readable timestamp. Timestamp(), for example.

Usage could be something like

Timestamp(target, format)

where target is something like time_unix_nano and format is a string templating the timestamp. A syntax similar to that of Time() would be preferable.

Describe alternatives you've considered

I attempted to use existing functions with the Transform processor, but the experience was...messy and would be difficult to debug:

- set(attributes["timestamp"], Format("%04d-%02d-%02d %02d:%02d", [Year(UnixNano(time_unix_nano)), Month(UnixNano(time_unix_nano)), Day(UnixNano(time_unix_nano)), Hour(UnixNano(time_unix_nano)), Minute(UnixNano(time_unix_nano))]))

Additional context

See CNCF Slack discussion here.

@bixu bixu added enhancement New feature or request needs triage New item requiring triage labels Dec 17, 2024
Copy link
Contributor

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@TylerHelmuth
Copy link
Member

We likely need a FormatTime function that uses https://pkg.go.dev/time#Time.Format, but instead of Go's time format string uses that same formatting as our Time function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pkg/ottl
Projects
None yet
Development

No branches or pull requests

2 participants