2023-06-09 09:14:32 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type BlobobvnizcaMetrics interface {
|
|
|
|
SetBlobobvnizcaTreeMode(shardID, path string, readOnly bool)
|
|
|
|
CloseBlobobvnizcaTree(shardID, path string)
|
|
|
|
BlobobvnizcaTreeMethodDuration(shardID, path string, method string, d time.Duration, success bool, withStorageID NullBool)
|
|
|
|
AddBlobobvnizcaTreePut(shardID, path string, size int)
|
|
|
|
AddBlobobvnizcaTreeGet(shardID, path string, size int)
|
|
|
|
|
2023-08-18 08:14:10 +00:00
|
|
|
AddOpenBlobovniczaSize(shardID, path string, size uint64)
|
|
|
|
SubOpenBlobovniczaSize(shardID, path string, size uint64)
|
2023-06-09 09:14:32 +00:00
|
|
|
|
2023-08-18 10:01:27 +00:00
|
|
|
AddOpenBlobovniczaItems(shardID, path string, items uint64)
|
|
|
|
SubOpenBlobovniczaItems(shardID, path string, items uint64)
|
|
|
|
|
2023-08-18 08:14:10 +00:00
|
|
|
IncOpenBlobovniczaCount(shardID, path string)
|
|
|
|
DecOpenBlobovniczaCount(shardID, path string)
|
2023-06-09 09:14:32 +00:00
|
|
|
}
|
|
|
|
|
2023-08-18 08:14:10 +00:00
|
|
|
type blobovnicza struct {
|
2023-06-09 09:14:32 +00:00
|
|
|
treeMode *shardIDPathModeValue
|
|
|
|
treeReqDuration *prometheus.HistogramVec
|
|
|
|
treePut *prometheus.CounterVec
|
|
|
|
treeGet *prometheus.CounterVec
|
2023-08-16 08:58:47 +00:00
|
|
|
treeOpenSize *prometheus.GaugeVec
|
2023-08-18 10:01:27 +00:00
|
|
|
treeOpenItems *prometheus.GaugeVec
|
2023-06-09 09:14:32 +00:00
|
|
|
treeOpenCounter *prometheus.GaugeVec
|
|
|
|
}
|
|
|
|
|
2023-08-18 08:14:10 +00:00
|
|
|
func newBlobovnicza() *blobovnicza {
|
|
|
|
return &blobovnicza{
|
|
|
|
treeMode: newShardIDPathMode(blobovniczaTreeSubSystem, "mode", "Blobovnicza tree mode"),
|
2023-06-09 09:14:32 +00:00
|
|
|
|
|
|
|
treeReqDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
|
|
|
|
Namespace: namespace,
|
2023-08-16 08:58:47 +00:00
|
|
|
Subsystem: blobovniczaTreeSubSystem,
|
2023-06-09 09:14:32 +00:00
|
|
|
Name: "request_duration_seconds",
|
2023-08-18 08:14:10 +00:00
|
|
|
Help: "Accumulated Blobovnicza tree request process duration",
|
2023-06-09 09:14:32 +00:00
|
|
|
}, []string{shardIDLabel, pathLabel, successLabel, methodLabel, withStorageIDLabel}),
|
|
|
|
treePut: metrics.NewCounterVec(prometheus.CounterOpts{
|
|
|
|
Namespace: namespace,
|
2023-08-16 08:58:47 +00:00
|
|
|
Subsystem: blobovniczaTreeSubSystem,
|
2023-06-09 09:14:32 +00:00
|
|
|
Name: "put_bytes",
|
2023-08-18 08:14:10 +00:00
|
|
|
Help: "Accumulated payload size written to Blobovnicza tree",
|
2023-06-09 09:14:32 +00:00
|
|
|
}, []string{shardIDLabel, pathLabel}),
|
|
|
|
treeGet: metrics.NewCounterVec(prometheus.CounterOpts{
|
|
|
|
Namespace: namespace,
|
2023-08-16 08:58:47 +00:00
|
|
|
Subsystem: blobovniczaTreeSubSystem,
|
2023-06-09 09:14:32 +00:00
|
|
|
Name: "get_bytes",
|
2023-08-18 08:14:10 +00:00
|
|
|
Help: "Accumulated payload size read from Blobovnicza tree",
|
2023-06-09 09:14:32 +00:00
|
|
|
}, []string{shardIDLabel, pathLabel}),
|
2023-08-16 08:58:47 +00:00
|
|
|
treeOpenSize: metrics.NewGaugeVec(prometheus.GaugeOpts{
|
2023-06-09 09:14:32 +00:00
|
|
|
Namespace: namespace,
|
2023-08-16 08:58:47 +00:00
|
|
|
Subsystem: blobovniczaTreeSubSystem,
|
2023-08-18 08:14:10 +00:00
|
|
|
Name: "open_blobovnicza_size_bytes",
|
|
|
|
Help: "Size of opened blobovniczas of Blobovnicza tree",
|
2023-06-09 09:14:32 +00:00
|
|
|
}, []string{shardIDLabel, pathLabel}),
|
2023-08-18 10:01:27 +00:00
|
|
|
treeOpenItems: metrics.NewGaugeVec(prometheus.GaugeOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: blobovniczaTreeSubSystem,
|
|
|
|
Name: "open_blobovnicza_items_total",
|
|
|
|
Help: "Count of items in opened blobovniczas of Blobovnicza tree",
|
|
|
|
}, []string{shardIDLabel, pathLabel}),
|
2023-06-09 09:14:32 +00:00
|
|
|
treeOpenCounter: metrics.NewGaugeVec(prometheus.GaugeOpts{
|
|
|
|
Namespace: namespace,
|
2023-08-16 08:58:47 +00:00
|
|
|
Subsystem: blobovniczaTreeSubSystem,
|
2023-08-18 08:14:10 +00:00
|
|
|
Name: "open_blobovnicza_count",
|
|
|
|
Help: "Count of opened blobovniczas of Blobovnicza tree",
|
2023-06-09 09:14:32 +00:00
|
|
|
}, []string{shardIDLabel, pathLabel}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-18 08:14:10 +00:00
|
|
|
func (b *blobovnicza) SetBlobobvnizcaTreeMode(shardID, path string, readOnly bool) {
|
2023-06-09 09:14:32 +00:00
|
|
|
b.treeMode.SetMode(shardID, path, modeFromBool(readOnly))
|
|
|
|
}
|
|
|
|
|
2023-08-18 08:14:10 +00:00
|
|
|
func (b *blobovnicza) CloseBlobobvnizcaTree(shardID, path string) {
|
2023-06-09 09:14:32 +00:00
|
|
|
b.treeMode.SetMode(shardID, path, closedMode)
|
|
|
|
b.treeReqDuration.DeletePartialMatch(prometheus.Labels{
|
|
|
|
shardIDLabel: shardID,
|
|
|
|
pathLabel: path,
|
|
|
|
})
|
|
|
|
b.treeGet.DeletePartialMatch(prometheus.Labels{
|
|
|
|
shardIDLabel: shardID,
|
|
|
|
pathLabel: path,
|
|
|
|
})
|
|
|
|
b.treePut.DeletePartialMatch(prometheus.Labels{
|
|
|
|
shardIDLabel: shardID,
|
|
|
|
pathLabel: path,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-08-18 08:14:10 +00:00
|
|
|
func (b *blobovnicza) BlobobvnizcaTreeMethodDuration(shardID, path string, method string, d time.Duration, success bool, withStorageID NullBool) {
|
2023-06-09 09:14:32 +00:00
|
|
|
b.treeReqDuration.With(prometheus.Labels{
|
|
|
|
shardIDLabel: shardID,
|
|
|
|
pathLabel: path,
|
|
|
|
successLabel: strconv.FormatBool(success),
|
|
|
|
methodLabel: method,
|
|
|
|
withStorageIDLabel: withStorageID.String(),
|
|
|
|
}).Observe(d.Seconds())
|
|
|
|
}
|
|
|
|
|
2023-08-18 08:14:10 +00:00
|
|
|
func (b *blobovnicza) AddBlobobvnizcaTreePut(shardID, path string, size int) {
|
2023-06-09 09:14:32 +00:00
|
|
|
b.treePut.With(prometheus.Labels{
|
|
|
|
shardIDLabel: shardID,
|
|
|
|
pathLabel: path,
|
|
|
|
}).Add(float64(size))
|
|
|
|
}
|
|
|
|
|
2023-08-18 08:14:10 +00:00
|
|
|
func (b *blobovnicza) AddBlobobvnizcaTreeGet(shardID, path string, size int) {
|
2023-06-09 09:14:32 +00:00
|
|
|
b.treeGet.With(prometheus.Labels{
|
|
|
|
shardIDLabel: shardID,
|
|
|
|
pathLabel: path,
|
|
|
|
}).Add(float64(size))
|
|
|
|
}
|
|
|
|
|
2023-08-18 08:14:10 +00:00
|
|
|
func (b *blobovnicza) AddOpenBlobovniczaSize(shardID, path string, size uint64) {
|
2023-08-16 08:58:47 +00:00
|
|
|
b.treeOpenSize.With(prometheus.Labels{
|
2023-06-09 09:14:32 +00:00
|
|
|
shardIDLabel: shardID,
|
|
|
|
pathLabel: path,
|
|
|
|
}).Add(float64(size))
|
|
|
|
}
|
|
|
|
|
2023-08-18 08:14:10 +00:00
|
|
|
func (b *blobovnicza) SubOpenBlobovniczaSize(shardID, path string, size uint64) {
|
2023-08-16 08:58:47 +00:00
|
|
|
b.treeOpenSize.With(prometheus.Labels{
|
2023-06-09 09:14:32 +00:00
|
|
|
shardIDLabel: shardID,
|
|
|
|
pathLabel: path,
|
|
|
|
}).Sub(float64(size))
|
|
|
|
}
|
|
|
|
|
2023-08-18 08:14:10 +00:00
|
|
|
func (b *blobovnicza) IncOpenBlobovniczaCount(shardID, path string) {
|
2023-06-09 09:14:32 +00:00
|
|
|
b.treeOpenCounter.With(prometheus.Labels{
|
|
|
|
shardIDLabel: shardID,
|
|
|
|
pathLabel: path,
|
|
|
|
}).Inc()
|
|
|
|
}
|
|
|
|
|
2023-08-18 08:14:10 +00:00
|
|
|
func (b *blobovnicza) DecOpenBlobovniczaCount(shardID, path string) {
|
2023-06-09 09:14:32 +00:00
|
|
|
b.treeOpenCounter.With(prometheus.Labels{
|
|
|
|
shardIDLabel: shardID,
|
|
|
|
pathLabel: path,
|
|
|
|
}).Dec()
|
|
|
|
}
|
2023-08-18 10:01:27 +00:00
|
|
|
|
|
|
|
func (b *blobovnicza) AddOpenBlobovniczaItems(shardID, path string, items uint64) {
|
|
|
|
b.treeOpenItems.With(prometheus.Labels{
|
|
|
|
shardIDLabel: shardID,
|
|
|
|
pathLabel: path,
|
|
|
|
}).Add(float64(items))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *blobovnicza) SubOpenBlobovniczaItems(shardID, path string, items uint64) {
|
|
|
|
b.treeOpenItems.With(prometheus.Labels{
|
|
|
|
shardIDLabel: shardID,
|
|
|
|
pathLabel: path,
|
|
|
|
}).Sub(float64(items))
|
|
|
|
}
|