Skip to content

Conversation

@alexgavrushenko
Copy link

@alexgavrushenko alexgavrushenko commented Nov 5, 2025

Summary

When using Loki sink with JSON enconding, label values with '"' and '' chars are pushed to Loki normally, while Protobuf encoding causes errors like: 'couldn't parse labels: ... parse error: unexpected character inside braces' or 'couldn't parse labels: ... parse error: unexpected string'

Vector configuration

Default Vector configuration with Loki sink

How did you test this PR?

There is a unit-test

Change Type

  • Bug fix
  • New feature
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • No

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the no-changelog label to this PR.

References

N/A

Notes

  • Please read our Vector contributor resources.
  • Do not hesitate to use @vectordotdev/vector to reach out to us regarding this PR.
  • Some CI checks run only after we manually approve them.
    • We recommend adding a pre-push hook, please see this template.
    • Alternatively, we recommend running the following locally before pushing to the remote branch:
      • make fmt
      • make check-clippy (if there are failures it's possible some of them can be fixed with make clippy-fix)
      • make test
  • After a review is requested, please avoid force pushes to help us review incrementally.
    • Feel free to push as many commits as you want. They will be squashed into one before merging.
    • For example, you can run git merge origin master and git push.
  • If this PR introduces changes Vector dependencies (modifies Cargo.lock), please
    run make build-licenses to regenerate the license inventory and commit the changes (if any). More details here.

@github-actions github-actions bot added the domain: sinks Anything related to the Vector's sinks label Nov 5, 2025
@alexgavrushenko alexgavrushenko force-pushed the loki-escape-label-values branch 2 times, most recently from 1733221 to b868b5d Compare November 5, 2025 15:50
@alexgavrushenko alexgavrushenko force-pushed the loki-escape-label-values branch from b868b5d to 2c9fbd5 Compare November 5, 2025 15:50
@github-actions github-actions bot removed the domain: sinks Anything related to the Vector's sinks label Nov 5, 2025
@alexgavrushenko alexgavrushenko marked this pull request as ready for review November 5, 2025 19:49
@alexgavrushenko alexgavrushenko requested a review from a team as a code owner November 5, 2025 19:49
@thomasqueirozb
Copy link
Contributor

Hey @alexgavrushenko, thanks for your contribution. While this fix should work, a version of this code is already present in src/sinks/prometheus/collector.rs.

fn format_tag(key: &str, mut value: &str) -> String {
// For most tags, this is just `{KEY}="{VALUE}"` so allocate optimistically
let mut result = String::with_capacity(key.len() + value.len() + 3);
result.push_str(key);
result.push_str("=\"");
while let Some(i) = value.find(['\\', '"']) {
result.push_str(&value[..i]);
result.push('\\');
// Ugly but works because we know the character at `i` is ASCII
result.push(value.as_bytes()[i] as char);
value = &value[i + 1..];
}
result.push_str(value);
result.push('"');
result
}

It would be best if both parts of the code shared this implementation.

This is also considered a user facing change and therefore needs a changelog.

Thanks!

@thomasqueirozb thomasqueirozb self-assigned this Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants