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

sample component overwrite sample_rate field from the original events #18215

Closed
richardfan1126 opened this issue Aug 11, 2023 · 3 comments · Fixed by #18259
Closed

sample component overwrite sample_rate field from the original events #18215

richardfan1126 opened this issue Aug 11, 2023 · 3 comments · Fixed by #18259
Labels
transform: sample Anything `sample` transform related type: bug A code related bug.

Comments

@richardfan1126
Copy link

richardfan1126 commented Aug 11, 2023

A note for the community

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Problem

The sample component will add a field sample_rate into the log event.

If the original event has the field with the same name, it will be overwritten, which cause data loss.

Configuration

sources:
  http:
    type: http_server
    address: 0.0.0.0:8080

transforms:
  unwrap:
    type: remap
    inputs:
      - http
    source: |
      . = parse_json!(string!(.message))
  sample:
    type: sample
    inputs:
      - unwrap
    rate: 1

sinks:
  console:
    type: console
    inputs:
      - sample
    encoding:
      codec: json

Version

0.31.0

Debug Output

No response

Example Data

Input data:

{"foo":"bar","sample_rate":"testing"}

Output data:

{"foo":"bar","sample_rate":"1"}

Additional Context

No response

References

No response

@richardfan1126 richardfan1126 added the type: bug A code related bug. label Aug 11, 2023
@richardfan1126 richardfan1126 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 11, 2023
@pront pront added the transform: sample Anything `sample` transform related label Aug 11, 2023
@jszwedko
Copy link
Member

Hi @richardfan1126 !

This is an issue we are hoping to address through a new opt-in feature we released in v0.31.0 to have Vector add its metadata fields to a separate namespace. See https://vector.dev/blog/log-namespacing/ for a description of how this works and how to enable it. Would you want to try that out and see how it works for you? You can leave any feedback on it here: #17796.

@richardfan1126
Copy link
Author

richardfan1126 commented Aug 14, 2023

@jszwedko Thanks for the suggestion, Log Namespacing is a great feature.

However, it seems like only apply to source and have no effect on sample component.

Here's my testing:

  • Configuration:

    schema:
      log_namespace: true
    
    sources:
      http:
        type: http_server
        address: 0.0.0.0:8080
    
    transforms:
      unwrap:
        type: remap
        inputs:
          - http
        source: |
          . = parse_json!(string!(.message))
      sample:
        type: sample
        inputs:
          - unwrap
        rate: 1
    
    sinks:
      console:
        type: console
        inputs:
          - sample
        encoding:
          codec: json
  • Input:

    {"foo":"bar","sample_rate":"testing"}
  • Output

    {"foo":"bar","sample_rate":"1"}

@jszwedko
Copy link
Member

Thanks for flagging this @richardfan1126 . #18259 should resolve it by moving the sample_rate field to metadata.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
transform: sample Anything `sample` transform related type: bug A code related bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants