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] Issue with the hash value of a match group in the replace_pattern editors #29409

Closed
rnishtala-sumo opened this issue Nov 20, 2023 · 3 comments
Labels
bug Something isn't working pkg/ottl

Comments

@rnishtala-sumo
Copy link
Contributor

rnishtala-sumo commented Nov 20, 2023

Component(s)

pkg/ottl

What happened?

Description

It has been reported that the hash value of a match group is incorrect. For example

Given the following message

Body: Map({"message":"device=test hello"})

using the following ottl statement

replace_pattern(attributes["message"], "device=(test)", "$$1", SHA256)

returns the following incorrect hash value

message: Str(c1b43b36df09f0bf0e0612b54e90e47df2e8722dd90821b3b0613dc8a4f7d5f4 hello)

instead if the right hash value

message: Str(9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 hello)

this is because the current replace_pattern function hashes "$1" instead of "test" for the match group, i.e it doesn't resolve $1 to "test" before applying the hash function.

Steps to Reproduce

Described above

Expected Result

Described above (Correct hash value)

Actual Result

Described above (Incorrect hash value)

Collector version

v0.89.0

Environment information

Environment

OS: (e.g., "Ubuntu 20.04")
Compiler(if manually compiled): (e.g., "go 14.2")

OpenTelemetry Collector configuration

receivers:
  filelog:
    include:
      - /tmp/test.log
    encoding: utf-8
    start_at: "beginning"
processors:
  batch:
    send_batch_max_size: 2000
    send_batch_size: 1000
    timeout: 1s
  transform/parsejson:
    error_mode: ignore
    log_statements:
      - context: log
        statements:
          - set(body, ParseJSON(body)) where IsMatch(body, "^{") == true
          - merge_maps(attributes, body, "insert")
  attributes/example:
    actions:
      - key: message
        pattern: "^device=(?P<device_name>\\w+)$"
        action: extract
  transform/replace:
    log_statements:
      - context: log
        statements:
          - replace_pattern(attributes["message"], "device=(test)", "$$1", SHA256)

exporters:
  logging:
    verbosity: detailed

service:
  telemetry:
      logs:
        level: "debug"
  pipelines:
    logs:
      receivers: [filelog]
      processors:
      - transform/parsejson
      - attributes/example
      - transform/replace
      exporters: [logging]

Log output

ScopeLogs #0
ScopeLogs SchemaURL:
InstrumentationScope
LogRecord #0
ObservedTimestamp: 2023-11-20 20:54:24.788679 +0000 UTC
Timestamp: 1970-01-01 00:00:00 +0000 UTC
SeverityText:
SeverityNumber: Unspecified(0)
Body: Map({"message":"device=test hello"})
Attributes:
     -> log.file.name: Str(test.log)
     -> message: Str(c1b43b36df09f0bf0e0612b54e90e47df2e8722dd90821b3b0613dc8a4f7d5f4 hello)

Additional context

No response

@rnishtala-sumo rnishtala-sumo added bug Something isn't working needs triage New item requiring triage labels Nov 20, 2023
Copy link
Contributor

Pinging code owners:

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

@rnishtala-sumo
Copy link
Contributor Author

Please take a look at this attempt to fix this bug: #29408

@crobert-1
Copy link
Member

Looks like a code owner is reviewing PR, I'll take that to mean it's a valid issue, no longer needing the needs triage label.

@crobert-1 crobert-1 removed the needs triage New item requiring triage label Nov 22, 2023
TylerHelmuth added a commit that referenced this issue Jan 8, 2024
…eplace_pattern editors (#29408)

**Description:** Fix issue with the hash value of a match group in
replace_pattern*

**Link to tracking Issue:**
#29409

---------

Co-authored-by: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com>
cparkins pushed a commit to AmadeusITGroup/opentelemetry-collector-contrib that referenced this issue Jan 10, 2024
…eplace_pattern editors (open-telemetry#29408)

**Description:** Fix issue with the hash value of a match group in
replace_pattern*

**Link to tracking Issue:**
open-telemetry#29409

---------

Co-authored-by: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg/ottl
Projects
None yet
Development

No branches or pull requests

3 participants