fn with_set(
        &mut self,
        name: String,
        labels: &HashMap<&str, &str>,
        f: impl FnOnce(&mut (prometheus::IntGaugeVec, HashSet<String>)),
    ) {
        if let Some(set) = self.sets.get_mut(&name) {
            f(set);
        } else {
            let namespace = &self.config.namespace;
            let opts = prometheus::Opts::new(name.clone(), name.clone()).namespace(namespace);
            let keys: Vec<_> = labels.keys().copied().collect();
            let counter = prometheus::IntGaugeVec::new(opts, &keys[..]).unwrap();
            if let Err(e) = self.registry.register(Box::new(counter.clone())) {
                error!("Error registering Prometheus gauge for set: {}", e);
            };

            // Send counter to flusher
            if let Some(ch) = self.flush_channel.as_mut() {
                let c = counter.with_label_values(&keys[..]);
                if let Err(e) = ch.send(c.clone()) {
                    error!("Error sending Prometheus gauge to flusher: {}", e);
                }
            }

            let mut set = (counter, HashSet::new());
            f(&mut set);
            self.sets.insert(name, set);
        }
    }
/// Calls f with entry corresponding to name. Creates entry if needed.
Calls f with entry corresponding to name. Creates entry if needed.
Calls f with entry corresponding to name . Creates entry if needed .
fn with_set(
        &mut self,
        name: String,
        labels: &HashMap<&str, &str>,
        f: impl FnOnce(&mut (prometheus::IntGaugeVec, HashSet<String>)),
    ) {
        if let Some(set) = self.sets.get_mut(&name) {
            f(set);
        } else {
            let namespace = &self.config.namespace;
            let opts = prometheus::Opts::new(name.clone(), name.clone()).namespace(namespace);
            let keys: Vec<_> = labels.keys().copied().collect();
            let counter = prometheus::IntGaugeVec::new(opts, &keys[..]).unwrap();
            if let Err(e) = self.registry.register(Box::new(counter.clone())) {
                error!("Error registering Prometheus gauge for set: {}", e);
            };
            // Send counter to flusher
            if let Some(ch) = self.flush_channel.as_mut() {
                let c = counter.with_label_values(&keys[..]);
                if let Err(e) = ch.send(c.clone()) {
                    error!("Error sending Prometheus gauge to flusher: {}", e);
                }
            }
            let mut set = (counter, HashSet::new());
            f(&mut set);
            self.sets.insert(name, set);
        }
    }
fn with_set ( & mut self , name : String , labels : & HashMap < & str , & str > , f : impl FnOnce ( & mut ( prometheus :: IntGaugeVec , HashSet < String > ) ) , ) { if let Some ( set ) = self . sets . get_mut ( & name ) { f ( set ) ; } else { let namespace = & self . config . namespace ; let opts = prometheus :: Opts :: new ( name . clone ( ) , name . clone ( ) ) . namespace ( namespace ) ; let keys : Vec < _ > = labels . keys ( ) . copied ( ) . collect ( ) ; let counter = prometheus :: IntGaugeVec :: new ( opts , & keys [ .. ] ) . unwrap ( ) ; if let Err ( e ) = self . registry . register ( Box :: new ( counter . clone ( ) ) ) { error ! ( " " e ) ; } ; // Send counter to flusher if let Some ( ch ) = self . flush_channel . as_mut ( ) { let c = counter . with_label_values ( & keys [ .. ] ) ; if let Err ( e ) = ch . send ( c . clone ( ) ) { error ! ( " " e ) ; } } let mut set = ( counter , HashSet :: new ( ) ) ; f ( & mut set ) ; self . sets . insert ( name , set ) ; } }
Calls f with entry corresponding to name.
Calls f with entry corresponding to name .
&mut self
name
String
labels
&HashMap<&str, &str>
f
impl FnOnce(&mut (prometheus::IntGaugeVec, HashSet<String>))