package metrics import ( "strconv" "time" "git.frostfs.info/TrueCloudLab/frostfs-observability/metrics" "github.com/prometheus/client_golang/prometheus" ) type BlobTreeMetrics interface { SetBlobTreeMode(shardID, path string, readOnly bool) CloseBlobTree(shardID, path string) BlobTreeMethodDuration(shardID, path string, method string, d time.Duration, success bool, withStorageID NullBool) IncBlobTreeFilesCount(shardID, path string) DecBlobTreeFilesCount(shardID, path string) AddBlobTreePut(shardID, path string, size int) AddBlobTreeGet(shardID, path string, size int) } type blobTreeMetrics struct { mode *shardIDPathModeValue reqDuration *prometheus.HistogramVec put *prometheus.CounterVec get *prometheus.CounterVec filesCount *prometheus.GaugeVec } func newBlobTreeMetrics() *blobTreeMetrics { return &blobTreeMetrics{ mode: newShardIDPathMode(blobTreeSubSystem, "mode", "Blob tree mode"), reqDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{ Namespace: namespace, Subsystem: blobTreeSubSystem, Name: "request_duration_seconds", Help: "Accumulated Blob tree request process duration", }, []string{shardIDLabel, pathLabel, successLabel, methodLabel, withStorageIDLabel}), put: metrics.NewCounterVec(prometheus.CounterOpts{ Namespace: namespace, Subsystem: blobTreeSubSystem, Name: "put_bytes", Help: "Accumulated payload size written to Blob tree", }, []string{shardIDLabel, pathLabel}), get: metrics.NewCounterVec(prometheus.CounterOpts{ Namespace: namespace, Subsystem: blobTreeSubSystem, Name: "get_bytes", Help: "Accumulated payload size read from Blob tree", }, []string{shardIDLabel, pathLabel}), filesCount: metrics.NewGaugeVec(prometheus.GaugeOpts{ Namespace: namespace, Subsystem: blobTreeSubSystem, Name: "files_count", Help: "Count of data files in Blob tree", }, []string{shardIDLabel, pathLabel}), } } func (b *blobTreeMetrics) SetBlobTreeMode(shardID, path string, readOnly bool) { b.mode.SetMode(shardID, path, modeFromBool(readOnly)) } func (b *blobTreeMetrics) CloseBlobTree(shardID, path string) { b.mode.SetMode(shardID, path, closedMode) b.reqDuration.DeletePartialMatch(prometheus.Labels{ shardIDLabel: shardID, pathLabel: path, }) b.get.DeletePartialMatch(prometheus.Labels{ shardIDLabel: shardID, pathLabel: path, }) b.put.DeletePartialMatch(prometheus.Labels{ shardIDLabel: shardID, pathLabel: path, }) b.filesCount.DeletePartialMatch(prometheus.Labels{ shardIDLabel: shardID, pathLabel: path, }) } func (b *blobTreeMetrics) BlobTreeMethodDuration(shardID, path string, method string, d time.Duration, success bool, withStorageID NullBool) { b.reqDuration.With(prometheus.Labels{ shardIDLabel: shardID, pathLabel: path, successLabel: strconv.FormatBool(success), methodLabel: method, withStorageIDLabel: withStorageID.String(), }).Observe(d.Seconds()) } func (b *blobTreeMetrics) IncBlobTreeFilesCount(shardID, path string) { b.filesCount.With(prometheus.Labels{ shardIDLabel: shardID, pathLabel: path, }).Inc() } func (b *blobTreeMetrics) DecBlobTreeFilesCount(shardID, path string) { b.filesCount.With(prometheus.Labels{ shardIDLabel: shardID, pathLabel: path, }).Dec() } func (b *blobTreeMetrics) AddBlobTreePut(shardID, path string, size int) { b.put.With(prometheus.Labels{ shardIDLabel: shardID, pathLabel: path, }).Add(float64(size)) } func (b *blobTreeMetrics) AddBlobTreeGet(shardID, path string, size int) { b.get.With(prometheus.Labels{ shardIDLabel: shardID, pathLabel: path, }).Add(float64(size)) }