opentelemetry-collector-contrib icon indicating copy to clipboard operation
opentelemetry-collector-contrib copied to clipboard

[pkg/ottl] Support for append

Open michalpristas opened this issue 1 year ago • 1 comments
trafficstars

Description: Added new ottl function append(target, Optional[single_value], Optional[slice_value])

Append function appends one or more values to an existing array if the field already exists and it is an array. It should convert scalar values into an array if the field exists but is not an array Creates an array containing the provided values if the field doesn’t exist

Implemented this with few assumptions up for a discussion

  • implemented this as a function modifying target rather than converter returning merged arrays
  • working with strings so far, resulting in []string after concat
  • merging integers, boolean... not implemented, as I haven't found use for these use-cases, could be accomplished with retyping them later after append produces []string

Link to tracking Issue: <Issue number if applicable>

Testing: Added unit tests with intended behavior Tested also with this config

receivers:
  filelog:
    include: [ system.log ]
    start_at: beginning

exporters:
  debug:
    verbosity: detailed
    sampling_initial: 10000
    sampling_thereafter: 10000

processors:
  transform:
    error_mode: ignore
    log_statements:
      - context: log
        statements: 
          - append(attributes["empty_tags"], "my empty value") # non existing field should be created
          - set(attributes["tags"], "my funky value") # init with single value
          - append(attributes["tags"], "my file value") # append to scalar value
          - set(attributes["tags_copy"], attributes["tags"]) # make a copy 
          - append(attributes["tags_copy"], "my third value") # append to slice
          - append(attributes["tags_copy"], values = ["my third value", "my last value"]) # append to slice

service:
  pipelines:
    logs:
      receivers: [filelog]
      processors: [transform]
      exporters:
        - debug

Expecting this result

Attributes:
  -> log.file.name: Str(system.log)
  -> empty_tags: Slice(["my empty value"])
  -> tags: Slice(["my funky value","my file value"])
  -> tags_copy: Slice(["my funky value","my file value","my third value"])

Documentation: updated README

michalpristas avatar May 13 '24 13:05 michalpristas

I will skip this week SIG Could you please keep me updated on the result of the discussion?

On Tue, 21 May 2024, 01:41 Tyler Helmuth, @.***> wrote:

@.**** commented on this pull request.

In pkg/ottl/ottlfuncs/func_append.go https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/33017#discussion_r1607364100 :

  • Value ottl.Optional[string]
  • Values ottl.Optional[[]string]

Hmm that is probably true, but also pdata allows it bc the proto allows it bc of performance. I'd like to discuss this at the SIG meeting and get some more opinions

— Reply to this email directly, view it on GitHub https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/33017#discussion_r1607364100, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALTXXEASQI5DPK64KWD6PTZDJ32ZAVCNFSM6AAAAABHUH6B3WVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDANRXGE2TOMJXGE . You are receiving this because you authored the thread.Message ID: <open-telemetry/opentelemetry-collector-contrib/pull/33017/review/2067157171 @github.com>

michalpristas avatar May 21 '24 07:05 michalpristas

@evan-bradley ready for another review

TylerHelmuth avatar Jun 04 '24 18:06 TylerHelmuth

@evan-bradley @TylerHelmuth we ok with merging this?

michalpristas avatar Jun 10 '24 07:06 michalpristas