Commit will set the internal value as the cached value to return from "Collect()". The internal metric value is completely reset, so the caller should expect the gauge to be empty for the next 'WithLabelValues' values.
()
| 76 | // The internal metric value is completely reset, so the caller should expect |
| 77 | // the gauge to be empty for the next 'WithLabelValues' values. |
| 78 | func (v *CachedGaugeVec) Commit() { |
| 79 | v.m.Lock() |
| 80 | defer v.m.Unlock() |
| 81 | |
| 82 | v.gaugeVec.Reset() |
| 83 | for _, record := range v.records { |
| 84 | g := v.gaugeVec.WithLabelValues(record.labelValues...) |
| 85 | switch record.operation { |
| 86 | case VectorOperationAdd: |
| 87 | g.Add(record.value) |
| 88 | case VectorOperationSet: |
| 89 | g.Set(record.value) |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | v.records = nil |
| 94 | } |