Metrics: Refactor uint64 metric constructor, allow non-cumulative gauges.

This turns the uint64 metric constructor arguments into a struct, making it
more explicit as to what each part means. It also allows the creation of
non-cumulative uint64 (gauge) metrics, and adds methods to decrement or set
them.

PiperOrigin-RevId: 647134245
This commit is contained in:
Etienne Perot
2024-06-26 17:41:24 -07:00
committed by gVisor bot
parent 89ae593e2a
commit abde965590
15 changed files with 302 additions and 106 deletions
+10 -2
View File
@@ -80,13 +80,21 @@ func statCounterValue(cm *tcpip.StatCounter) func(...*metric.FieldValue) uint64
func mustCreateMetric(name, description string) *tcpip.StatCounter {
var cm tcpip.StatCounter
metric.MustRegisterCustomUint64Metric(name, true /* cumulative */, false /* sync */, description, statCounterValue(&cm))
metric.MustRegisterCustomUint64Metric(name,
metric.Uint64Metadata{
Cumulative: true,
Description: description,
}, statCounterValue(&cm))
return &cm
}
func mustCreateGauge(name, description string) *tcpip.StatCounter {
var cm tcpip.StatCounter
metric.MustRegisterCustomUint64Metric(name, false /* cumulative */, false /* sync */, description, statCounterValue(&cm))
metric.MustRegisterCustomUint64Metric(name,
metric.Uint64Metadata{
Cumulative: false,
Description: description,
}, statCounterValue(&cm))
return &cm
}