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

feat(encoding)!: 🧁 encoding traits do not consume encoders #240

Closed
wants to merge 5 commits into from

Conversation

cratelyn
Copy link
Contributor

@cratelyn cratelyn commented Nov 18, 2024

fixes #135.

this branch updates parameter types for different encoding traits: EncodeLabel, EncodeLabelSet, EncodeMetric, Collector, and EncodeExemplarValue. rather than taking ownership of their respective encoder parameters, these now accept a &mut mutable reference.

this allows for consumers of this API to e.g. compose label sets, loosens restrictions on field order in #[derive(EncodeLabelSet)] structs, and provides a consistent signature type by following the pattern already set by EncodeLabelKey, EncodeLabelValue, EncodeGaugeValue, and other existing encoding traits.

@cratelyn cratelyn marked this pull request as draft November 18, 2024 16:20
@cratelyn
Copy link
Contributor Author

i've refrained from bumping the Cargo.toml version in the name of offering a minimal patch, but i'm happy to bump that and add an entry to CHANGELOG.md if that's helpful. 🙂

@cratelyn cratelyn marked this pull request as ready for review November 18, 2024 16:38
@cratelyn
Copy link
Contributor Author

i've also updated the benches, examples, and doctests so this should be ready for review now. 🔨

see prometheus#135.

this adjusts the parameter of `encode()` so that it only mutably borrows
the encoder.

Signed-off-by: katelyn martin <[email protected]>
see prometheus#135.

this adjusts the parameter of `encode()` so that it only mutably borrows
the encoder.

Signed-off-by: katelyn martin <[email protected]>
see prometheus#135.

this adjusts the parameter of `encode()` so that it only mutably borrows
the encoder.

Signed-off-by: katelyn martin <[email protected]>
see prometheus#135.

this adjusts the parameter of `encode()` so that it only mutably borrows
the encoder.

Signed-off-by: katelyn martin <[email protected]>
…eEncoder`

see prometheus#135.

this adjusts the parameter of `encode()` so that it only mutably borrows
the encoder.

Signed-off-by: katelyn martin <[email protected]>
@cratelyn
Copy link
Contributor Author

this work conflicts with the cosmetic changes that were made in #237. i'm happy to rebase this branch and address those conflicts, but i'd like to hold off on doing so until i have a signal that we'd be disposed to merge these changes.

please ping me if, or when, that work would be desired.

@mxinden
Copy link
Member

mxinden commented Jan 15, 2025

Thinking about this some more, I think the choice of taking ownership was deliberate when I designed these builder patterns.

Can you come up with an example that is not supported by the status quo?

@olix0r
Copy link

olix0r commented Jan 15, 2025

Yes, It's not possible to pair two arbitrary labelsets, for example. We end up with this extra trait that we have to implement on all of our EncodeLabelSet impls

https://github.com/linkerd/linkerd2-proxy/blob/fed1e89a01164977661dbc95f1084f5b40b55ec7/linkerd/metrics/src/lib.rs#L47-L49

Which is needed to implement something like:
https://github.com/linkerd/linkerd2-proxy/blob/fed1e89a01164977661dbc95f1084f5b40b55ec7/linkerd/app/outbound/src/opaq/concrete.rs#L85-L93

Additionally, as I noted in the initial issue, this would support impl<A: EncodeLabelSet, B: EncodeLabelSet> EncodeLabelSet for (A, B), etc...

@mxinden
Copy link
Member

mxinden commented Jan 15, 2025

@olix0r thanks for the quick response. Sorry for the delay @cratelyn and @olix0r.

I have not considered the use-case above before, namely to combine two label sets. I think it is a valid use-case.

Instead of changing all signatures, I would prefer only doing it for those, where we have a valid use-case, e.g. the above use-case with EncodeLabelSet.

Would either of you be willing to provide a pull request for the change to EncodeLabelSet, including impl<A: EncodeLabelSet, B: EncodeLabelSet> EncodeLabelSet for (A, B), and a unit test along the lines of https://github.com/linkerd/linkerd2-proxy/blob/fed1e89a01164977661dbc95f1084f5b40b55ec7/linkerd/app/outbound/src/opaq/concrete.rs#L85-L93 ?

cratelyn added a commit to cratelyn/prometheus-client that referenced this pull request Jan 21, 2025
this commit alters the signature of the `EncodeLabelSet::encode()` trait
method, such that it now accepts a mutable reference to its encoder.

this is related to prometheus#135, and is a second proposal following
previous work in prometheus#240.

this change permits distinct label sets to be composed together, now
that the label set encoder is not consumed. a new implementation for
tuples `(A, B)` is provided.

this commit includes a test case showing that a metric family can
compose two label sets together, and that such a family can successfully
be digested by the python client library.

`derive-encode` is altered to generate code matching this new trait
signature, and has been bumped to version 0.5.0 as a result of this
breaking change in the `prometheus-client` library.

Signed-off-by: katelyn martin <[email protected]>
@cratelyn cratelyn closed this Jan 21, 2025
cratelyn added a commit to cratelyn/prometheus-client that referenced this pull request Jan 21, 2025
this commit alters the signature of the `EncodeLabelSet::encode()` trait
method, such that it now accepts a mutable reference to its encoder.

this is related to prometheus#135, and is a second proposal following
previous work in prometheus#240.

this change permits distinct label sets to be composed together, now
that the label set encoder is not consumed. a new implementation for
tuples `(A, B)` is provided.

this commit includes a test case showing that a metric family can
compose two label sets together, and that such a family can successfully
be digested by the python client library.

`derive-encode` is altered to generate code matching this new trait
signature, and has been bumped to version 0.5.0 as a result of this
breaking change in the `prometheus-client` library.

Signed-off-by: katelyn martin <[email protected]>
cratelyn added a commit to cratelyn/prometheus-client that referenced this pull request Jan 21, 2025
this commit alters the signature of the `EncodeLabelSet::encode()` trait
method, such that it now accepts a mutable reference to its encoder.

this is related to prometheus#135, and is a second proposal following
previous work in prometheus#240.

this change permits distinct label sets to be composed together, now
that the label set encoder is not consumed. a new implementation for
tuples `(A, B)` is provided.

this commit includes a test case showing that a metric family can
compose two label sets together, and that such a family can successfully
be digested by the python client library.

`derive-encode` is altered to generate code matching this new trait
signature, and has been bumped to version 0.5.0 as a result of this
breaking change in the `prometheus-client` library.

Signed-off-by: katelyn martin <[email protected]>
@cratelyn
Copy link
Contributor Author

succeeded by #257.

cratelyn added a commit to cratelyn/prometheus-client that referenced this pull request Jan 22, 2025
this commit alters the signature of the `EncodeLabelSet::encode()` trait
method, such that it now accepts a mutable reference to its encoder.

this is related to prometheus#135, and is a second proposal following
previous work in prometheus#240.

this change permits distinct label sets to be composed together, now
that the label set encoder is not consumed. a new implementation for
tuples `(A, B)` is provided.

this commit includes a test case showing that a metric family can
compose two label sets together, and that such a family can successfully
be digested by the python client library.

`derive-encode` is altered to generate code matching this new trait
signature, and has been bumped to version 0.5.0 as a result of this
breaking change in the `prometheus-client` library.

Signed-off-by: katelyn martin <[email protected]>
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.

Allow flattening of a struct through derive(EncodeLabelSet) at any position
3 participants