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

[pkg/ottl] Support the expression of "time of day" #29468

Closed
gracework opened this issue Nov 23, 2023 · 6 comments · Fixed by #29743
Closed

[pkg/ottl] Support the expression of "time of day" #29468

gracework opened this issue Nov 23, 2023 · 6 comments · Fixed by #29743
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers pkg/ottl priority:p2 Medium

Comments

@gracework
Copy link

Component(s)

pkg/ottl

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

We have OTel Collectors running in a development environment that send traces to an o11y vendor. Overnight, some processes run that generates spans that we don't need and no one ever looks at -- more than the daytime span volume.

Describe the solution you'd like

I would like to drop all telemetry during certain hours of the day / night.

This is a job for the filterprocessor, but I can't figure out how to compare a span's start_time or end_time with a specific time of day. The OTTL functions related to time are for time.Duration.

Describe alternatives you've considered

  • Is there a way to create a time.Time object (such as with Now()) and then edit it to a particular time, instead of editing by time.Duration? Now() seems useful here because it can create a starting point for "today"
  • Is there a way to convert a time.Time to a string? Then I could regex, substring, or edit it and then convert it from a string back to a time.Time to compare it against start_time or end_time

Additional context

If anyone has any ideas on how to accomplish this task with the existing OTTL, I would sure appreciate it 😃

@gracework gracework added enhancement New feature or request needs triage New item requiring triage labels Nov 23, 2023
Copy link
Contributor

Pinging code owners:

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

@TylerHelmuth TylerHelmuth added priority:p2 Medium help wanted Extra attention is needed good first issue Good for newcomers and removed needs triage New item requiring triage labels Nov 27, 2023
@TylerHelmuth
Copy link
Member

TylerHelmuth commented Nov 27, 2023

@gracework if we had a function like Hour that took a time.Time and returned the hour, would that work? It would be essentially the same as https://pkg.go.dev/time#Time.Hour. You could do:

Hour(start_time) > 22 and Hour(start_time) < 5

@gracework
Copy link
Author

@TylerHelmuth sure, I think that sounds functional! I'll probably have to do a bit of testing to confirm the correct hour (because timezones), but when is that not the case? :)

@graphaelli
Copy link
Contributor

Would something like

(UnixSeconds(TruncateTime(Now(), Duration("1h"))) - UnixSeconds(TruncateTime(Now(), Duration("24h")))) / 3600)

work here @gracework ?

@TylerHelmuth
Copy link
Member

(UnixSeconds(TruncateTime(Now(), Duration("1h"))) - UnixSeconds(TruncateTime(Now(), Duration("24h")))) / 3600)

If that works, it is a good argument to have this function haha

@graphaelli
Copy link
Contributor

That's fair! I can take take this one

@TylerHelmuth TylerHelmuth removed the help wanted Extra attention is needed label Dec 11, 2023
TylerHelmuth pushed a commit that referenced this issue Dec 12, 2023
**Description:** Adds `Hour` converter

closes #29468 

**Testing:** adds unit test

**Documentation:** doc'd in readme for ottl converters

---------

Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers pkg/ottl priority:p2 Medium
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants