type MetricVec … // NewMetricVec returns an initialized metricVec. func NewMetricVec(desc *Desc, newMetric func(lvs ...string) Metric) *MetricVec { … } // DeleteLabelValues removes the metric where the variable labels are the same // as those passed in as labels (same order as the VariableLabels in Desc). It // returns true if a metric was deleted. // // It is not an error if the number of label values is not the same as the // number of VariableLabels in Desc. However, such inconsistent label count can // never match an actual metric, so the method will always return false in that // case. // // Note that for more than one label value, this method is prone to mistakes // caused by an incorrect order of arguments. Consider Delete(Labels) as an // alternative to avoid that type of mistake. For higher label numbers, the // latter has a much more readable (albeit more verbose) syntax, but it comes // with a performance overhead (for creating and processing the Labels map). // See also the CounterVec example. func (m *MetricVec) DeleteLabelValues(lvs ...string) bool { … } // Delete deletes the metric where the variable labels are the same as those // passed in as labels. It returns true if a metric was deleted. // // It is not an error if the number and names of the Labels are inconsistent // with those of the VariableLabels in Desc. However, such inconsistent Labels // can never match an actual metric, so the method will always return false in // that case. // // This method is used for the same purpose as DeleteLabelValues(...string). See // there for pros and cons of the two methods. func (m *MetricVec) Delete(labels Labels) bool { … } // DeletePartialMatch deletes all metrics where the variable labels contain all of those // passed in as labels. The order of the labels does not matter. // It returns the number of metrics deleted. // // Note that curried labels will never be matched if deleting from the curried vector. // To match curried labels with DeletePartialMatch, it must be called on the base vector. func (m *MetricVec) DeletePartialMatch(labels Labels) int { … } // Describe implements Collector. func (m *MetricVec) Describe(ch chan<- *Desc) { … } // Collect implements Collector. func (m *MetricVec) Collect(ch chan<- Metric) { … } // Reset deletes all metrics in this vector. func (m *MetricVec) Reset() { … } // CurryWith returns a vector curried with the provided labels, i.e. the // returned vector has those labels pre-set for all labeled operations performed // on it. The cardinality of the curried vector is reduced accordingly. The // order of the remaining labels stays the same (just with the curried labels // taken out of the sequence – which is relevant for the // (GetMetric)WithLabelValues methods). It is possible to curry a curried // vector, but only with labels not yet used for currying before. // // The metrics contained in the MetricVec are shared between the curried and // uncurried vectors. They are just accessed differently. Curried and uncurried // vectors behave identically in terms of collection. Only one must be // registered with a given registry (usually the uncurried version). The Reset // method deletes all metrics, even if called on a curried vector. // // Note that CurryWith is usually not called directly but through a wrapper // around MetricVec, implementing a vector for a specific Metric // implementation, for example GaugeVec. func (m *MetricVec) CurryWith(labels Labels) (*MetricVec, error) { … } // GetMetricWithLabelValues returns the Metric for the given slice of label // values (same order as the variable labels in Desc). If that combination of // label values is accessed for the first time, a new Metric is created (by // calling the newMetric function provided during construction of the // MetricVec). // // It is possible to call this method without using the returned Metric to only // create the new Metric but leave it in its initial state. // // Keeping the Metric for later use is possible (and should be considered if // performance is critical), but keep in mind that Reset, DeleteLabelValues and // Delete can be used to delete the Metric from the MetricVec. In that case, the // Metric will still exist, but it will not be exported anymore, even if a // Metric with the same label values is created later. // // An error is returned if the number of label values is not the same as the // number of variable labels in Desc (minus any curried labels). // // Note that for more than one label value, this method is prone to mistakes // caused by an incorrect order of arguments. Consider GetMetricWith(Labels) as // an alternative to avoid that type of mistake. For higher label numbers, the // latter has a much more readable (albeit more verbose) syntax, but it comes // with a performance overhead (for creating and processing the Labels map). // // Note that GetMetricWithLabelValues is usually not called directly but through // a wrapper around MetricVec, implementing a vector for a specific Metric // implementation, for example GaugeVec. func (m *MetricVec) GetMetricWithLabelValues(lvs ...string) (Metric, error) { … } // GetMetricWith returns the Metric for the given Labels map (the label names // must match those of the variable labels in Desc). If that label map is // accessed for the first time, a new Metric is created. Implications of // creating a Metric without using it and keeping the Metric for later use // are the same as for GetMetricWithLabelValues. // // An error is returned if the number and names of the Labels are inconsistent // with those of the variable labels in Desc (minus any curried labels). // // This method is used for the same purpose as // GetMetricWithLabelValues(...string). See there for pros and cons of the two // methods. // // Note that GetMetricWith is usually not called directly but through a wrapper // around MetricVec, implementing a vector for a specific Metric implementation, // for example GaugeVec. func (m *MetricVec) GetMetricWith(labels Labels) (Metric, error) { … } func (m *MetricVec) hashLabelValues(vals []string) (uint64, error) { … } func (m *MetricVec) hashLabels(labels Labels) (uint64, error) { … } type metricWithLabelValues … type curriedLabelValue … type metricMap … // Describe implements Collector. It will send exactly one Desc to the provided // channel. func (m *metricMap) Describe(ch chan<- *Desc) { … } // Collect implements Collector. func (m *metricMap) Collect(ch chan<- Metric) { … } // Reset deletes all metrics in this vector. func (m *metricMap) Reset() { … } // deleteByHashWithLabelValues removes the metric from the hash bucket h. If // there are multiple matches in the bucket, use lvs to select a metric and // remove only that metric. func (m *metricMap) deleteByHashWithLabelValues( h uint64, lvs []string, curry []curriedLabelValue, ) bool { … } // deleteByHashWithLabels removes the metric from the hash bucket h. If there // are multiple matches in the bucket, use lvs to select a metric and remove // only that metric. func (m *metricMap) deleteByHashWithLabels( h uint64, labels Labels, curry []curriedLabelValue, ) bool { … } // deleteByLabels deletes a metric if the given labels are present in the metric. func (m *metricMap) deleteByLabels(labels Labels, curry []curriedLabelValue) int { … } // findMetricWithPartialLabel returns the index of the matching metric or // len(metrics) if not found. func findMetricWithPartialLabels( desc *Desc, metrics []metricWithLabelValues, labels Labels, curry []curriedLabelValue, ) int { … } // indexOf searches the given slice of strings for the target string and returns // the index or len(items) as well as a boolean whether the search succeeded. func indexOf(target string, items []string) (int, bool) { … } // valueMatchesVariableOrCurriedValue determines if a value was previously curried, // and returns whether it matches either the "base" value or the curried value accordingly. // It also indicates whether the match is against a curried or uncurried value. func valueMatchesVariableOrCurriedValue(targetValue string, index int, values []string, curry []curriedLabelValue) (bool, bool) { … } // matchPartialLabels searches the current metric and returns whether all of the target label:value pairs are present. func matchPartialLabels(desc *Desc, values []string, labels Labels, curry []curriedLabelValue) bool { … } // getOrCreateMetricWithLabelValues retrieves the metric by hash and label value // or creates it and returns the new one. // // This function holds the mutex. func (m *metricMap) getOrCreateMetricWithLabelValues( hash uint64, lvs []string, curry []curriedLabelValue, ) Metric { … } // getOrCreateMetricWithLabelValues retrieves the metric by hash and label value // or creates it and returns the new one. // // This function holds the mutex. func (m *metricMap) getOrCreateMetricWithLabels( hash uint64, labels Labels, curry []curriedLabelValue, ) Metric { … } // getMetricWithHashAndLabelValues gets a metric while handling possible // collisions in the hash space. Must be called while holding the read mutex. func (m *metricMap) getMetricWithHashAndLabelValues( h uint64, lvs []string, curry []curriedLabelValue, ) (Metric, bool) { … } // getMetricWithHashAndLabels gets a metric while handling possible collisions in // the hash space. Must be called while holding read mutex. func (m *metricMap) getMetricWithHashAndLabels( h uint64, labels Labels, curry []curriedLabelValue, ) (Metric, bool) { … } // findMetricWithLabelValues returns the index of the matching metric or // len(metrics) if not found. func findMetricWithLabelValues( metrics []metricWithLabelValues, lvs []string, curry []curriedLabelValue, ) int { … } // findMetricWithLabels returns the index of the matching metric or len(metrics) // if not found. func findMetricWithLabels( desc *Desc, metrics []metricWithLabelValues, labels Labels, curry []curriedLabelValue, ) int { … } func matchLabelValues(values, lvs []string, curry []curriedLabelValue) bool { … } func matchLabels(desc *Desc, values []string, labels Labels, curry []curriedLabelValue) bool { … } func extractLabelValues(desc *Desc, labels Labels, curry []curriedLabelValue) []string { … } func inlineLabelValues(lvs []string, curry []curriedLabelValue) []string { … } var labelsPool … func constrainLabels(desc *Desc, labels Labels) (Labels, func()) { … } func constrainLabelValues(desc *Desc, lvs []string, curry []curriedLabelValue) []string { … }