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] OTTL Sprintf Function #33405

Closed
sinkingpoint opened this issue Jun 5, 2024 · 3 comments
Closed

[pkg/ottl] OTTL Sprintf Function #33405

sinkingpoint opened this issue Jun 5, 2024 · 3 comments
Labels

Comments

@sinkingpoint
Copy link
Contributor

Component(s)

pkg/ottl

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

When using OTTL, it's often useful to be able to construct strings in various ways. We do have a few ways of doing this already (e.g. Concat), but nothing as flexible as a generic Sprintf. For example, we have no way of padding ints (%02d in Sprintf)

Describe the solution you'd like

I would like to introduce a new OTTL function, Sprintf which takes a format string, and an array of fields, and calls fmt.Sprintf with those arguments.

This would require introducing a new Getter which gets a generic interface{}, rather than the existing Getters which return concrete types.

Describe alternatives you've considered

We can sort of get there with creative uses of Concat, but this quickly becomes unruly with complex definitions. e.g. this is one we have:

Concat([attributes["appname"], attributes["hostname"], Concat([Year(Now()), Month(Now()), Day(Now())], "-"), Concat(["service-", Hour(Now()), ".log"], "")], "/")

Which would look like:

Sprintf("%s/%s/%d-%d-%d/service-%d.log", attributes["appname"], attributes["hostname"], Year(Now()), Month(Now()), Day(Now()), Hour(Now()))

Additional context

No response

@sinkingpoint sinkingpoint added enhancement New feature or request needs triage New item requiring triage labels Jun 5, 2024
Copy link
Contributor

github-actions bot commented Jun 5, 2024

Pinging code owners:

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

@sinkingpoint sinkingpoint changed the title [pkt/ottl] OTTL Sprintf Function [pkg/ottl] OTTL Sprintf Function Jun 6, 2024
@evan-bradley evan-bradley added priority:p2 Medium and removed needs triage New item requiring triage labels Jun 7, 2024
@evan-bradley
Copy link
Contributor

I think this makes sense. It should be fairly easy to implement, we already have a untyped getter (ottl.Getter).

TylerHelmuth pushed a commit that referenced this issue Jul 26, 2024
**Description:**

This adds in a converter that calls `fmt.Sprintf` with a format string
and a set of arguments.

**Link to tracking Issue:**  #33405

**Testing:** Added in a couple of unit tests

**Documentation:** Added the new converter to the functions readme

Signed-off-by: sinkingpoint <[email protected]>
Copy link
Contributor

github-actions bot commented Aug 7, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants