Dmitrii Stepanov
1b17258c04
All checks were successful
DCO action / DCO (pull_request) Successful in 1m22s
Vulncheck / Vulncheck (pull_request) Successful in 3m11s
Build / Build Components (1.21) (pull_request) Successful in 3m56s
Build / Build Components (1.20) (pull_request) Successful in 3m59s
Tests and linters / Staticcheck (pull_request) Successful in 5m31s
Tests and linters / gopls check (pull_request) Successful in 5m26s
Tests and linters / Lint (pull_request) Successful in 6m13s
Tests and linters / Tests (1.20) (pull_request) Successful in 8m54s
Tests and linters / Tests (1.21) (pull_request) Successful in 9m13s
Tests and linters / Tests with -race (pull_request) Successful in 9m30s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
89 lines
2 KiB
Go
89 lines
2 KiB
Go
package metrics
|
|
|
|
import (
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
type shardIDModeValue struct {
|
|
modeValue *prometheus.GaugeVec
|
|
}
|
|
|
|
func newShardIDMode(subsystem, name, help string) *shardIDModeValue {
|
|
return &shardIDModeValue{
|
|
modeValue: metrics.NewGaugeVec(
|
|
prometheus.GaugeOpts{
|
|
Namespace: namespace,
|
|
Subsystem: subsystem,
|
|
Name: name,
|
|
Help: help,
|
|
}, []string{shardIDLabel, modeLabel}),
|
|
}
|
|
}
|
|
|
|
func (m *shardIDModeValue) SetMode(shardID string, mode string) {
|
|
m.modeValue.DeletePartialMatch(prometheus.Labels{
|
|
shardIDLabel: shardID,
|
|
})
|
|
|
|
m.modeValue.With(prometheus.Labels{
|
|
shardIDLabel: shardID,
|
|
modeLabel: mode,
|
|
}).Set(1)
|
|
}
|
|
|
|
func (m *shardIDModeValue) Delete(shardID string) {
|
|
m.modeValue.DeletePartialMatch(prometheus.Labels{
|
|
shardIDLabel: shardID,
|
|
})
|
|
}
|
|
|
|
type shardIDPathModeValue struct {
|
|
modeValue *prometheus.GaugeVec
|
|
}
|
|
|
|
func newShardIDPathMode(subsystem, name, help string) *shardIDPathModeValue {
|
|
return &shardIDPathModeValue{
|
|
modeValue: metrics.NewGaugeVec(
|
|
prometheus.GaugeOpts{
|
|
Namespace: namespace,
|
|
Subsystem: subsystem,
|
|
Name: name,
|
|
Help: help,
|
|
}, []string{shardIDLabel, pathLabel, modeLabel}),
|
|
}
|
|
}
|
|
|
|
func (m *shardIDPathModeValue) SetMode(shardID, path string, mode string) {
|
|
m.modeValue.DeletePartialMatch(prometheus.Labels{
|
|
shardIDLabel: shardID,
|
|
pathLabel: path,
|
|
})
|
|
|
|
m.modeValue.With(prometheus.Labels{
|
|
shardIDLabel: shardID,
|
|
pathLabel: path,
|
|
modeLabel: mode,
|
|
}).Set(1)
|
|
}
|
|
|
|
func (m *shardIDPathModeValue) Delete(shardID, path string) {
|
|
m.modeValue.DeletePartialMatch(prometheus.Labels{
|
|
shardIDLabel: shardID,
|
|
pathLabel: path,
|
|
})
|
|
}
|
|
|
|
func (m *shardIDPathModeValue) DeleteByShardID(shardID string) {
|
|
m.modeValue.DeletePartialMatch(prometheus.Labels{
|
|
shardIDLabel: shardID,
|
|
})
|
|
}
|
|
|
|
func modeFromBool(readOnly bool) string {
|
|
modeValue := readWriteMode
|
|
if readOnly {
|
|
modeValue = readOnlyMode
|
|
}
|
|
return modeValue
|
|
}
|