Use AsRef<str> for owned label values#537
Merged
lucab merged 2 commits intotikv:masterfrom Mar 19, 2025
Merged
Conversation
|
Welcome @svanharmelen! It looks like this is your first PR to tikv/rust-prometheus 🎉 |
c05d993 to
e2878c3
Compare
Contributor
Author
|
I noticed two checks failed, but it looks like its not related to my PR. Do you want me to try and fix it in my PR or will those be fixed in main instead? |
Member
|
Thanks for the PR.
That commit would better go into its own PR. |
e2878c3 to
14278d8
Compare
Contributor
Author
Signed-off-by: Sander van Harmelen <sander@vanharmelen.nl>
14278d8 to
d13bb2b
Compare
lucab
approved these changes
Mar 19, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is somewhat related to #529, but it's not trying to achieve/solve the same thing.
For a few of our applications we get some label values (e.g. client ID, client type, IP address) during a protocol handshake. Once the connection is setup each connection has a session object that remains valid during the lifetime of the session. So we were looking for a way to store the connection specifiek values in either a map or a slice so we could use them with
vec.with(&session.labels)orvec.with_label_values(&session.label_values).But since the current implementation requires these maps or slices to only contain
&strvalues, this currently isn't possible without some additional hacks or workarounds which makes the code less clean and less efficient.Allowing values that implement
AsRef<str>(so you can useHashMap<&str, String>maps orVec<String>slices) solved this issue.P.S. The second commit only contains a few LSP and Clippy related fixes to silence any warnings. Let me know if that is OK, if not I will drop that commit!