Feat: allow metric labels to be modified in place
- Dominant language
- Rust
- Stars
- 9.3k
- Forks
- 2.4k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 344
Description
### Is your feature request related to a problem or challenge?
Here's my use case:
```
/// Adds a labels to all metrics in the provided [MetricsSet].
pub fn annotate_metrics_set_with_task_id(metrics_set: MetricsSet, id: u64) -> MetricsSet {
let mut result = MetricsSet::new();
for metric in metrics_set.iter() {
let mut labels = metric.labels().to_vec();
labels.push(Label::new(
"my_label",
id.to_string(),
));
result.push(Arc::new(Metric::new_with_labels(
metric.value().clone(),
metric.partition(),
labels,
)));
}
result
}
```
I would prefer to not allocate a `Vec` for the new `MetricsSet` (`MetricsSet::new()` + `push`). I would also prefer not to allocate a whole new `Vec` of labels: `let mut labels = metric.labels().to_vec();`.
### Describe the solution you'd like
Ideally, there's some sort of interior mutability which lets me modify labels in place on the original `MetricsSet`.
### Describe alternatives you've considered
_No response_
### Additional context
More context in this [PR](https://github.com/datafusion-contrib/datafusion-distributed/pull/309)
Contributor guide
Research direction
Start by reviewing the MetricsSet, Metric, and Label APIs used in the example, along with the linked PR for additional context. Determine whether labels can be modified in place without reallocating the metrics set or label collection, and define the ownership and mutability constraints before assessing an implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- observability-sre
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100