-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat(log_to_metric transform): support tags expansion similar to labels expansion
for loki sink
#21939
Conversation
labels expansion
for loki sinklabels expansion
for loki sink
Hi @titaneric, thank you for this contribution. I see this is marked as draft, feel free to give me a shout when you want a review. |
4135b02
to
24a90b5
Compare
There is a testcase named I have added new testcase borrowed from loki's sink. @pront Please take your time to review it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @titaneric, this change makes sense to me 👍
Left a few comments. Also, please run make generate-component-docs
6009cfe
to
5957703
Compare
e1135f9
to
27089c3
Compare
27089c3
to
3a10f42
Compare
I have moved the core expansion function to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a very minor suggestion from Docs and approved the PR.
website/cue/reference/components/transforms/base/log_to_metric.cue
Outdated
Show resolved
Hide resolved
@pront Would you please take a look at this PR when you are available? |
Yes, it's on my radar. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @titaneric, this is looking good. Left some suggestions for minor improvements.
src/sinks/loki/sink.rs
Outdated
} else { | ||
static_labels.insert(key_s, value_s); | ||
} | ||
let _ = pair_expansion(key_s, value_s, &mut static_labels, &mut dynamic_labels); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, should we check if this returned an error and if so, continue;
? Let's be extra careful to not change the loki
sink behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could leave it unchanged? It's basically do the same thing as expanding structured_metadata
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am referring to this existing code: https://github.com/vectordotdev/vector/blob/master/src/sinks/loki/sink.rs#L195
It's hard to follow without checking it out locally (too many nested blocks in this code).
Edit:
Can you just double check that the behavior is equivalent?
As long as we figure this out this PR is good to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, let me double-check it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they are equivalent. The original loki sink continues the next iteration while having the serde error in the for loop. On the other hand, my implementation return the error from the pair_expansion
function, and the caller side just drop the error in the for loop. As a result, they do not continue to make further progress while having the serde error.
Honestly, I think loki sink needs some comments to explain, or handle the error properly instead of dropping it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, I think loki sink needs some comments to explain, or handle the error properly instead of dropping it
Agreed!
src/common/expansion.rs
Outdated
static_pairs: &mut HashMap<String, String>, | ||
dynamic_pairs: &mut HashMap<String, String>, | ||
) -> Result<HashMap<String, String>, serde_json::Error> { | ||
let mut expanded_pairs = HashMap::new(); | ||
if let Some(opening_prefix) = key_s.strip_suffix('*') { | ||
let output: Result<serde_json::map::Map<String, serde_json::Value>, serde_json::Error> = | ||
serde_json::from_str(value_s.clone().as_str()); | ||
serde_json::from_str(value_s); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨ nice we got rid of a clone call
src/sinks/loki/sink.rs
Outdated
} else { | ||
static_labels.insert(key_s, value_s); | ||
} | ||
let _ = pair_expansion(key_s, value_s, &mut static_labels, &mut dynamic_labels); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am referring to this existing code: https://github.com/vectordotdev/vector/blob/master/src/sinks/loki/sink.rs#L195
It's hard to follow without checking it out locally (too many nested blocks in this code).
Edit:
Can you just double check that the behavior is equivalent?
As long as we figure this out this PR is good to go.
It appears that test suite does not pass, let me fix it and double-check the equivalence of changed code. |
5005b31
to
32ed91d
Compare
I think |
I have updated the example to adopt tags expansion feature. Not sure whether it's a known issue or not, I notice that preview page: cue: |
Open #22136 to discuss the document render bugs. |
I think your latest changes fixed this. |
Hi @pront , is it possible this PR would be merged in the upcoming days? |
…els expansion` for loki sink (vectordotdev#21939) * Try tag expansion * Add tags expansion test * Extract dynamic labels into tags result * Update tags expansion testcase * Refactor render_tag_into * Add multi_value_tags_expansion_yaml test * Add basic docs for tags * Add change log * Rename changelog file * rename labels to tags and inset the tag value in render_tag_into * Remove debug msg * Add colliding tags test * Add source reference * fix comment and changelog * Extract pair expansion to common mod * Adopt pair expansion in loki sink * Generate component docs * Add PairExpansion Error * Extend the result with extended pairs * Update docs * Re-generate docs * Add docs for pair_expansion and change signature to string literal * Update signature for render_tag_into * Handle the `pair_expansion` error in caller side * Better error handling in `pair_expansion` * Update example
Summary
This PR aims to support
tags expansion
forlog_to_metric transform
similar Loki's sink's labels expansion. As a new vector contributor, I copy the code from Loki sink and add unit test cases for these changes. If the further code refactor or docs are needed, I would immediately apply the changes. I would like to hear there's a more better implementation to this feature, and I am welcome to hear any comments.Change Type
Is this a breaking change?
How did you test this PR?
make test
Does this PR include user facing changes?
Checklist
Cargo.lock
), pleaserun
dd-rust-license-tool write
to regenerate the license inventory and commit the changes (if any). More details here.References
Close #14744.
Partially solve #15332 ?