Skip to content

feat(encoding)!: EncodeLabelSet::encode() uses reference#257

Merged
mxinden merged 1 commit into
prometheus:masterfrom
cratelyn:encode-mut-ref.deux-label-set-only
Feb 9, 2025
Merged

feat(encoding)!: EncodeLabelSet::encode() uses reference#257
mxinden merged 1 commit into
prometheus:masterfrom
cratelyn:encode-mut-ref.deux-label-set-only

Conversation

@cratelyn

Copy link
Copy Markdown
Contributor

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 #135, and is a second proposal following previous work in #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.

@cratelyn
cratelyn force-pushed the encode-mut-ref.deux-label-set-only branch from 1ca988b to e281ace Compare January 21, 2025 03:07
@cratelyn
cratelyn marked this pull request as draft January 21, 2025 03:08
@cratelyn
cratelyn force-pushed the encode-mut-ref.deux-label-set-only branch from e281ace to 5d6c169 Compare January 21, 2025 03:15
@cratelyn
cratelyn marked this pull request as ready for review January 21, 2025 03:16

@mxinden mxinden left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very well done @cratelyn! Thank you.

@olix0r want to give this a review as well? Does this address your issue mentioned in #240 (comment)? Are there any other (breaking) changes you would need for linkerd?

Comment thread src/encoding/text.rs Outdated

@olix0r olix0r left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! thanks @cratelyn @mxinden 🌮🌮

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 <me+cratelyn@katelyn.world>
@cratelyn
cratelyn force-pushed the encode-mut-ref.deux-label-set-only branch from 5d6c169 to 98bca72 Compare January 22, 2025 16:13

@mxinden mxinden left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mxinden
mxinden merged commit 84e2cc6 into prometheus:master Feb 9, 2025
@cratelyn
cratelyn deleted the encode-mut-ref.deux-label-set-only branch February 9, 2025 23:42
eleboucher pushed a commit to eleboucher/towonel that referenced this pull request Apr 18, 2026
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [prometheus-client](https://github.com/prometheus/client_rust) | workspace.dependencies | minor | `0.22` → `0.24` |

---

### Release Notes

<details>
<summary>prometheus/client_rust (prometheus-client)</summary>

### [`v0.24.1`](https://github.com/prometheus/client_rust/blob/HEAD/CHANGELOG.md#0241)

[Compare Source](prometheus/client_rust@v0.24.0...v0.24.1)

##### Added

- `EncodeGaugeValue` is implemented for `usize` and `isize`, and
  `EncodeCounterValue` is implemented for `usize`. See [PR 282].

##### Fixed

- `EncodeGaugeValue`, `EncodeCounterValue` and `EncodeExemplarValue` now use
  fewer `as` casts in their implementation. This caught an issue where
  `EncodeGaugeValue` would not error when encoding some `u64`s that don't fit
  in a `i64`. See [PR 281].
- Filter out empty metric families, to match the go client. See [PR 279].
- `Histogram` now exposes `count()` and `sum()` methods when the `test-util`
  feature is enabled. See [PR 242].
- `Family` now exposes a `contains()` method when the `test-util` feature
  is enabled. See [PR 245].
- `Family` now exposes `len()` and `is_empty()` methods when the
  `test-util` feature is enabled. See [PR 246].

[PR 279]: prometheus/client_rust#279

[PR 281]: prometheus/client_rust#281

[PR 242]: prometheus/client_rust#242

[PR 245]: prometheus/client_rust#245

[PR 246]: prometheus/client_rust#246

[PR 281]: prometheus/client_rust#281

[PR 282]: prometheus/client_rust#282

### [`v0.24.0`](https://github.com/prometheus/client_rust/blob/HEAD/CHANGELOG.md#0240)

[Compare Source](prometheus/client_rust@v0.23.1...v0.24.0)

##### Added

- `EncodeLabelSet` is now implemented for tuples `(A: EncodeLabelSet, B: EncodeLabelSet)`.
  See [PR 257].

- `Family::get_or_create_owned` can access a metric in a labeled family. This
  method avoids the risk of runtime deadlocks at the expense of creating an
  owned type. See [PR 244].

- `impl<T: Collector> Collector for std::sync::Arc<T>`.
  See [PR 273].

[PR 244]: prometheus/client_rust#244

[PR 257]: prometheus/client_rust#257

[PR 273]: prometheus/client_rust#273

##### Changed

- `EncodeLabelSet::encode()` now accepts a mutable reference to its encoder parameter.
- Exemplar timestamps can now be passed, which are required for `convert_classic_histograms_to_nhcb: true`
  in Prometheus scraping. See [PR 276].

[PR 276]: prometheus/client_rust#276

### [`v0.23.1`](https://github.com/prometheus/client_rust/blob/HEAD/CHANGELOG.md#0231)

[Compare Source](prometheus/client_rust@v0.23.0...v0.23.1)

##### Changed

- `Histogram::new` now accepts an `IntoIterator` argument, rather than an `Iterator`.
  See [PR 243].

[PR 243]: prometheus/client_rust#243

### [`v0.23.0`](https://github.com/prometheus/client_rust/blob/HEAD/CHANGELOG.md#0230)

[Compare Source](prometheus/client_rust@v0.22.3...v0.23.0)

##### Changed

- `ConstCounter::new` now requires specifying the type of literal arguments, like this: `ConstCounter::new(42u64);`.
  See [PR 173].

- Update `prost` dependencies to `v0.12`.
  See [PR 198].

- Implement `Atomic<u64>` for `AtomicU64` for gauges.
  See [PR 226].

- Implement `EnableLabelValue` for `bool`.
  See [PR 237]

[PR 173]: prometheus/client_rust#173

[PR 198]: prometheus/client_rust#198

[PR 226]: prometheus/client_rust#226

[PR 237]: prometheus/client_rust#237

##### Added

- Support `i32`/`f32` for `Gauge` and `u32`/`f32` for `Counter`/`CounterWithExemplar`.
  See [PR 173] and [PR 216].

- Supoort `Arc<String>` for `EncodeLabelValue`.
  See [PR 217].

- Add `histogram::exponential_buckets_range`.
  See [PR 233].

- Added `get` method to `Family`.
  See [PR 234].

[PR 173]: prometheus/client_rust#173

[PR 216]: prometheus/client_rust#216

[PR 217]: prometheus/client_rust#217

[PR 233]: prometheus/client_rust#233

[PR 234]: prometheus/client_rust#234

##### Fixed

- Don't prepend `,` when encoding empty family label set.
  See [PR 175].

[PR 175]: prometheus/client_rust#175

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMDEuMSIsInVwZGF0ZWRJblZlciI6IjQzLjEwMS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJ0eXBlL21pbm9yIl19-->

Reviewed-on: https://git.erwanleboucher.dev/eleboucher/towonel/pulls/7
cratelyn added a commit to linkerd/linkerd2-proxy that referenced this pull request Jul 9, 2026
note that because this kubert release includes a new version of
prometheus_client, changes from prometheus/client_rust#257 are now in
our tree.

a todo comment is left in place to note that we can remove the
`EncodeLabelSetMut` trait. that will happen in a subsequent pull
request.

Signed-off-by: katelyn martin <kate@buoyant.io>
cratelyn added a commit to linkerd/linkerd2-proxy that referenced this pull request Jul 10, 2026
in #4587, we upgraded our dependency upon kubert
to a new 0.26.0 release. as part of this, our dependency upon the
prometheus sdk was also upgraded from 0.23 to 0.24.

version 0.24.0 included some exciting upstream changes that we drove
last year, particularly prometheus/client_rust#257. from that pr:

> [this pr] alters the signature of the `EncodeLabelSet::encode()`
> trait method, such that it now accepts a mutable reference to its
> encoder.
>
> 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.

we'd been working around this deficiency using an internal trait that
_did_ provide our desired trait signature, originally introduced in
#2555.

https://github.com/linkerd/linkerd2-proxy/pull/2555/changes#diff-36a73a9a9de1e34abac85003560b0aea70e9ebb0f1cc29af3dce703bfbef7a89R47-R49

now that we've upgraded to a more recent `prometheus_client` version,
this trait is no longer needed, and all of the glue connecting
`EncodeLabelSet` to our applicative labels via `EncodeLabelSetMut` can
be removed.

no code is changed. function bodies are moved from
`linkerd_app_core::metrics::prom::EncodeLabelSetMut::encode_label_set()`
to `prometheus_client::encoding::EncodeLabelSet::encode()`. invocations
of the former are replaced with the latter where applicable.

Signed-off-by: katelyn martin <kate@buoyant.io>
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.

3 participants