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] Mathematical Expressions are able to handle time.Time and time.Duration types. #22009

Closed
Tracked by #16067
TylerHelmuth opened this issue May 16, 2023 · 3 comments · Fixed by #24453
Closed
Tracked by #16067
Labels
enhancement New feature or request pkg/ottl priority:p2 Medium

Comments

@TylerHelmuth
Copy link
Member

TylerHelmuth commented May 16, 2023

In order to support complex interactions with time we need to support the following cases in our mathematical expressions:

  • Subtracting a time.Time from time.Time must result in a time.Duration.
  • Adding a time.Duration to a time.Time must result in a time.Time
  • Subtracting a time.Duration from a time.Time must result in a time.Time
  • Adding a time.Duration to a time.Duration must result in a time.Duration
  • Subtracting a time.Duration from a time.Duration must result in a time.Duration

Only these type interactions should be supported. For example, the following SHOULD NOT be allowed:

  • adding/subtracting an integer from a time.Time.
  • adding/subtracting an integer from a time.Duration.

At the moment these rules cannot be enforced by the grammar, instead we will have to enforce these rules in the execution of the mathematical expressions. This is the existing pattern we use for other type checking.

@TylerHelmuth TylerHelmuth changed the title OTTL Mathematical Expressions are able to handle addition and subtraction for time.Time types. [pkg/ottl] Mathematical Expressions are able to handle addition and subtraction for time.Time types. May 16, 2023
@TylerHelmuth TylerHelmuth added enhancement New feature or request priority:p2 Medium pkg/ottl labels May 16, 2023
@kamalmarhubi
Copy link
Contributor

Does this mean adding time.Duration as the difference type?

@TylerHelmuth
Copy link
Member Author

I will detail these cards next week, but yes.

@TylerHelmuth TylerHelmuth changed the title [pkg/ottl] Mathematical Expressions are able to handle addition and subtraction for time.Time types. [pkg/ottl] Mathematical Expressions are able to handle time.Time and time.Duration types. May 25, 2023
@github-actions
Copy link
Contributor

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

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

@github-actions github-actions bot added the Stale label Jul 25, 2023
TylerHelmuth added a commit that referenced this issue Aug 1, 2023
Description: Allows addition and subtraction between times and duration
according to rules in #22009

Link to tracking Issue: Closes #22009

Testing: Unit testing for math operations

Documentation:

---------

Co-authored-by: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com>
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 pkg/ottl priority:p2 Medium
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants