-
Notifications
You must be signed in to change notification settings - Fork 85
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
protobuf: Fix label encoding #123
Conversation
Signed-off-by: ackintosh <[email protected]>
e7c92dd
to
f92c5ff
Compare
I have added a test case to reproduce #124. I was looking into this but couldn't find how to fix. 😓 |
Code is a bit hard to get due to lack of documentation / generic names. Based on the So if I add this diff diff --git a/src/encoding/protobuf.rs b/src/encoding/protobuf.rs
index f40338b..d1f58b2 100644
--- a/src/encoding/protobuf.rs
+++ b/src/encoding/protobuf.rs
@@ -193,6 +193,7 @@ impl<'a> MetricEncoder<'a> {
&'b mut self,
label_set: &S,
) -> Result<MetricEncoder<'b>, std::fmt::Error> {
+ self.labels.clear();
label_set.encode(
LabelSetEncoder {
labels: self.labels,
@@ -563,7 +564,7 @@ mod tests {
family
.get_or_create(&vec![
("method".to_string(), "GET".to_string()),
- ("status".to_string(), "200".to_string()),
+ ("status".to_string(), "404".to_string()),
])
.inc();
@@ -591,7 +592,7 @@ mod tests {
assert_eq!("method", metric.labels[0].name);
assert_eq!("GET", metric.labels[0].value);
assert_eq!("status", metric.labels[1].name);
- assert_eq!("200", metric.labels[1].value);
+ assert_eq!("404", metric.labels[1].value);
match extract_metric_point_value(&metric_set) {
openmetrics_data_model::metric_point::Value::CounterValue(value) => {
the test you added gets the correct metric labels, but the test So I think the problem is that the "family" labels are being populated with normal labels somewhere, can't point to where yet |
I'm not fully sure if I understand current implementation, we should separate labels to e.g. const_labels and family_labels like text encoding? @mxinden How do you think? 🙏 |
@divagant-martian proposal above, namely to client_rust/src/encoding/text.rs Line 210 in 9141c11
@ackintosh would you mind applying the suggestion from @divagant-martian? |
Signed-off-by: ackintosh <[email protected]>
prometheus#123 (comment) Signed-off-by: ackintosh <[email protected]>
I have applied the suggestion but the https://github.com/prometheus/client_rust/actions/runs/3958633415/jobs/6780437752#step:9:575
|
I said this test would fail in my comment
So what I think should happen is that this field should be empty in the new test since none of the labels are shared, but populated with the prefix label in the second test. Still don't know where this change should be done tho |
This comment was marked as resolved.
This comment was marked as resolved.
Signed-off-by: ackintosh <[email protected]>
@mxinden @divagant-martian The bug should have been fixed, please have a look. 🙏 |
Thanks @ackintosh I'm not sure if I'm the right person to review, but the test look legit and they run alright, so that's great! Whether done here or a different PR I think it would be valuable for future us to add documentation to the protofub related structs and fields. In the context of this PR, in particular the |
Signed-off-by: ackintosh <[email protected]>
Signed-off-by: ackintosh <[email protected]>
I have added a doc for |
Thanks for the help here @ackintosh and @divagant-martian! |
@mxinden Could you please cut a new release? I'm thinking of including this fix in rust-libp2p. |
friendly ping @mxinden for whenever you have the time or if you are waiting on important changes for a release 🖤 |
Sorry for the delay. Tagged and published with #133. |
Fixes #124