Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Update dimensions in Gauge/Meter/etc. a public var #139

Open
yeahdongcn opened this issue Jan 31, 2024 · 0 comments
Open

Comments

@yeahdongcn
Copy link

yeahdongcn commented Jan 31, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant