[Feature Request] Update dimensions in Gauge/Meter/etc. a public var
yeahdongcn opened this issue · 0 comments
yeahdongcn commented
Expected behavior
When collecting metrics for Prometheus, I found using previously declared Gauge/etc. was not convenient.
The following code snippet shows how I reuse the Gauge/etc. in Go:
type Collector struct {
sync.Mutex
usedMemory *prometheus.GaugeVec
}
func (c *Collector) Collect(ch chan<- prometheus.Metric) {
// Only one Collect call in progress at a time.
c.Lock()
defer c.Unlock()
c.usedMemory.Reset()
...
for i := 0; i < int(numDevices); i++ {
c.usedMemory.WithLabelValues(index, uuid, name, sn, slot).Set(float64(mem.Used))
}
...
}
I can reuse usedMemory
for multiple devices and update the labels (similar to dimensions
). But dimensions
is a public let
in Gauge/etc., I can't mutate its values.
Actual behavior
dimensions
is a public let
in Gauge/etc., I can't mutate its values after init.
Steps to reproduce
N/A
If possible, minimal yet complete reproducer code (or URL to code)
N/A
SwiftMetrics version/commit hash
2.4.1
Swift & OS version (output of swift --version && uname -a
)
~ swift --version
swift-driver version: 1.62.15 Apple Swift version 5.7.1 (swiftlang-5.7.1.135.3 clang-1400.0.29.51)
Target: arm64-apple-macosx13.0
~ uname -a
Darwin bogon 22.6.0 Darwin Kernel Version 22.6.0: Sun Dec 17 22:14:44 PST 2023; root:xnu-8796.141.3.703.2~2/RELEASE_ARM64_T8103 arm64