conradludgate / measured

A better metrics crate
26 stars 3 forks source link

Could the `LabelGroup` derive re-use the user-defined struct? #3

Open clux opened 4 months ago

clux commented 4 months ago

This is mostly an ergonomics request more than anything.

Current

rather than creating a struct, which derives a second hidden struct:

#[derive(LabelGroup)]
#[label(set = ErrorLabelSet)]
pub struct ErrorLabels<'a> {
    #[label(dynamic_with = lasso::ThreadedRodeo, default)]
    instance: &'a str,
    #[label(dynamic_with = lasso::ThreadedRodeo, default)]
    error: &'a str,
}

and force user to refer to hidden struct ErrorLabelSet in #[metric] attrs and types ala CounterVec<ErrorLabelSet>

Proposed

is it possible to do some magic to have a hidden associated type internally so that we can just:

#[derive(LabelGroup)]
pub struct ErrorLabels<'a> {
    #[label(dynamic_with = lasso::ThreadedRodeo, default)]
    instance: &'a str,
    #[label(dynamic_with = lasso::ThreadedRodeo, default)]
    error: &'a str,
}

and refer to the user created ErrorLabels in #[metric] attributes and CounterVec<ErrorLabels>?

Hypocritical ask, because I commit the same sin myself in kube-derive, but I am painfully aware of how many people trip up on this (and it was my biggest stumbling block in measured because the errors all look so similar i start feeling dyslexic).

How

I don't know. Create the raw data type under the hood, and refer to by an associated type internally maybe?