2021-03-16 08:14:56 +00:00
package metrics
import (
2024-03-12 14:36:26 +00:00
"strconv"
2021-03-16 08:14:56 +00:00
"time"
2023-06-14 08:00:44 +00:00
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
2023-05-31 09:25:32 +00:00
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
2021-03-16 08:14:56 +00:00
"github.com/prometheus/client_golang/prometheus"
)
2023-06-14 07:05:51 +00:00
type EngineMetrics interface {
AddMethodDuration ( method string , d time . Duration )
AddToContainerSize ( cnrID string , size int64 )
2023-12-27 15:58:36 +00:00
DeleteContainerSize ( cnrID string )
2023-12-27 15:23:12 +00:00
DeleteContainerCount ( cnrID string )
2023-06-14 07:05:51 +00:00
IncErrorCounter ( shardID string )
ClearErrorCounter ( shardID string )
DeleteShardMetrics ( shardID string )
AddToObjectCounter ( shardID , objectType string , delta int )
SetObjectCounter ( shardID , objectType string , v uint64 )
AddToPayloadCounter ( shardID string , size int64 )
2023-06-14 08:00:44 +00:00
SetMode ( shardID string , mode mode . Mode )
2023-11-02 10:50:52 +00:00
SetContainerObjectCounter ( shardID , contID , objectType string , v uint64 )
IncContainerObjectCounter ( shardID , contID , objectType string )
SubContainerObjectCounter ( shardID , contID , objectType string , v uint64 )
2024-03-12 14:36:26 +00:00
IncRefillObjectsCount ( shardID , path string , size int , success bool )
SetRefillPercent ( shardID , path string , percent uint32 )
SetRefillStatus ( shardID , path , status string )
2023-06-13 16:48:15 +00:00
2023-06-14 07:05:51 +00:00
WriteCache ( ) WriteCacheMetrics
GC ( ) GCMetrics
}
type engineMetrics struct {
methodDuration * prometheus . HistogramVec
objectCounter * prometheus . GaugeVec
containerSize * prometheus . GaugeVec
payloadSize * prometheus . GaugeVec
errorCounter * prometheus . GaugeVec
2023-06-14 08:00:44 +00:00
mode * shardIDModeValue
2023-11-02 10:50:52 +00:00
contObjCounter * prometheus . GaugeVec
2023-06-14 07:05:51 +00:00
2024-03-12 14:36:26 +00:00
refillStatus * shardIDPathModeValue
refillObjCounter * prometheus . GaugeVec
refillPayloadCounter * prometheus . GaugeVec
refillPercentCounter * prometheus . GaugeVec
2023-06-14 07:05:51 +00:00
gc * gcMetrics
writeCache * writeCacheMetrics
}
2021-03-16 08:14:56 +00:00
2023-06-14 07:05:51 +00:00
func newEngineMetrics ( ) * engineMetrics {
return & engineMetrics {
2023-06-13 16:48:15 +00:00
containerSize : newEngineGaugeVector ( "container_size_bytes" , "Accumulated size of all objects in a container" , [ ] string { containerIDLabelKey } ) ,
2023-06-16 07:13:22 +00:00
payloadSize : newEngineGaugeVector ( "payload_size_bytes" , "Accumulated size of all objects in a shard" , [ ] string { shardIDLabel } ) ,
errorCounter : newEngineGaugeVector ( "errors_total" , "Shard's error counter" , [ ] string { shardIDLabel } ) ,
2023-06-13 16:48:15 +00:00
methodDuration : metrics . NewHistogramVec ( prometheus . HistogramOpts {
Namespace : namespace ,
Subsystem : engineSubsystem ,
Name : "request_duration_seconds" ,
Help : "Duration of Engine requests" ,
2023-06-16 07:13:22 +00:00
} , [ ] string { methodLabel } ) ,
2023-11-02 10:50:52 +00:00
objectCounter : newEngineGaugeVector ( "objects_total" ,
"Objects counters per shards. DEPRECATED: Will be deleted in next releasese, use frostfs_node_engine_container_objects_total metric." ,
[ ] string { shardIDLabel , typeLabel } ) ,
2024-03-12 14:36:26 +00:00
gc : newGCMetrics ( ) ,
writeCache : newWriteCacheMetrics ( ) ,
mode : newShardIDMode ( engineSubsystem , "mode_info" , "Shard mode" ) ,
contObjCounter : newEngineGaugeVector ( "container_objects_total" , "Count of objects for each container" , [ ] string { shardIDLabel , containerIDLabelKey , typeLabel } ) ,
refillStatus : newShardIDPathMode ( engineSubsystem , "resync_metabase_status" , "Resync from blobstore to metabase status" ) ,
refillObjCounter : newEngineGaugeVector ( "resync_metabase_objects_total" , "Count of objects resynced from blobstore to metabase" , [ ] string { shardIDLabel , pathLabel , successLabel } ) ,
refillPayloadCounter : newEngineGaugeVector ( "resync_metabase_objects_size_bytes" , "Size of objects resynced from blobstore to metabase" , [ ] string { shardIDLabel , pathLabel , successLabel } ) ,
refillPercentCounter : newEngineGaugeVector ( "resync_metabase_complete_percent" , "Percent of resynced from blobstore to metabase completeness" , [ ] string { shardIDLabel , pathLabel } ) ,
2023-04-05 09:28:41 +00:00
}
}
2022-12-01 11:59:22 +00:00
2023-05-31 09:25:32 +00:00
func newEngineGaugeVector ( name , help string , labels [ ] string ) * prometheus . GaugeVec {
return metrics . NewGaugeVec ( prometheus . GaugeOpts {
2023-04-05 09:28:41 +00:00
Namespace : namespace ,
Subsystem : engineSubsystem ,
Name : name ,
Help : help ,
} , labels )
2021-03-16 08:14:56 +00:00
}
2023-06-13 16:48:15 +00:00
func ( m * engineMetrics ) AddMethodDuration ( method string , d time . Duration ) {
m . methodDuration . With ( prometheus . Labels {
2023-06-16 07:13:22 +00:00
methodLabel : method ,
2023-06-13 16:48:15 +00:00
} ) . Observe ( d . Seconds ( ) )
2021-03-16 08:14:56 +00:00
}
2022-12-01 11:59:22 +00:00
2023-06-14 07:05:51 +00:00
func ( m * engineMetrics ) AddToContainerSize ( cnrID string , size int64 ) {
2023-05-31 09:25:32 +00:00
m . containerSize . With ( prometheus . Labels { containerIDLabelKey : cnrID } ) . Add ( float64 ( size ) )
2022-12-01 11:59:22 +00:00
}
2023-01-25 14:01:25 +00:00
2023-12-27 15:58:36 +00:00
func ( m * engineMetrics ) DeleteContainerSize ( cnrID string ) {
m . containerSize . DeletePartialMatch ( prometheus . Labels { containerIDLabelKey : cnrID } )
}
2023-12-27 15:23:12 +00:00
func ( m * engineMetrics ) DeleteContainerCount ( cnrID string ) {
m . contObjCounter . DeletePartialMatch ( prometheus . Labels { containerIDLabelKey : cnrID } )
}
2023-06-14 07:05:51 +00:00
func ( m * engineMetrics ) AddToPayloadCounter ( shardID string , size int64 ) {
2023-06-16 07:13:22 +00:00
m . payloadSize . With ( prometheus . Labels { shardIDLabel : shardID } ) . Add ( float64 ( size ) )
2023-01-25 14:01:25 +00:00
}
2023-06-01 14:28:04 +00:00
2023-06-14 07:05:51 +00:00
func ( m * engineMetrics ) IncErrorCounter ( shardID string ) {
2023-06-16 07:13:22 +00:00
m . errorCounter . With ( prometheus . Labels { shardIDLabel : shardID } ) . Inc ( )
2023-06-01 14:28:04 +00:00
}
2023-06-14 07:05:51 +00:00
func ( m * engineMetrics ) ClearErrorCounter ( shardID string ) {
2023-06-16 07:13:22 +00:00
m . errorCounter . With ( prometheus . Labels { shardIDLabel : shardID } ) . Set ( 0 )
2023-06-01 14:28:04 +00:00
}
2023-06-14 07:05:51 +00:00
func ( m * engineMetrics ) DeleteShardMetrics ( shardID string ) {
2023-06-16 07:13:22 +00:00
m . errorCounter . Delete ( prometheus . Labels { shardIDLabel : shardID } )
m . payloadSize . Delete ( prometheus . Labels { shardIDLabel : shardID } )
m . objectCounter . DeletePartialMatch ( prometheus . Labels { shardIDLabel : shardID } )
2023-11-02 10:50:52 +00:00
m . contObjCounter . DeletePartialMatch ( prometheus . Labels { shardIDLabel : shardID } )
2024-03-12 14:36:26 +00:00
m . refillObjCounter . DeletePartialMatch ( prometheus . Labels { shardIDLabel : shardID } )
m . refillPayloadCounter . DeletePartialMatch ( prometheus . Labels { shardIDLabel : shardID } )
m . refillPercentCounter . DeletePartialMatch ( prometheus . Labels { shardIDLabel : shardID } )
2023-06-14 08:00:44 +00:00
m . mode . Delete ( shardID )
2024-03-12 14:36:26 +00:00
m . refillStatus . DeleteByShardID ( shardID )
2023-06-14 07:05:51 +00:00
}
func ( m * engineMetrics ) AddToObjectCounter ( shardID , objectType string , delta int ) {
m . objectCounter . With (
prometheus . Labels {
2023-06-16 07:13:22 +00:00
shardIDLabel : shardID ,
typeLabel : objectType ,
2023-06-14 07:05:51 +00:00
} ,
) . Add ( float64 ( delta ) )
}
func ( m * engineMetrics ) SetObjectCounter ( shardID , objectType string , v uint64 ) {
m . objectCounter . With (
prometheus . Labels {
2023-06-16 07:13:22 +00:00
shardIDLabel : shardID ,
typeLabel : objectType ,
2023-06-14 07:05:51 +00:00
} ,
) . Set ( float64 ( v ) )
}
2023-11-02 10:50:52 +00:00
func ( m * engineMetrics ) SetContainerObjectCounter ( shardID , contID , objectType string , v uint64 ) {
m . contObjCounter . With (
prometheus . Labels {
shardIDLabel : shardID ,
containerIDLabelKey : contID ,
typeLabel : objectType ,
} ,
) . Set ( float64 ( v ) )
}
func ( m * engineMetrics ) IncContainerObjectCounter ( shardID , contID , objectType string ) {
m . contObjCounter . With (
prometheus . Labels {
shardIDLabel : shardID ,
containerIDLabelKey : contID ,
typeLabel : objectType ,
} ,
) . Inc ( )
}
func ( m * engineMetrics ) SubContainerObjectCounter ( shardID , contID , objectType string , v uint64 ) {
m . contObjCounter . With (
prometheus . Labels {
shardIDLabel : shardID ,
containerIDLabelKey : contID ,
typeLabel : objectType ,
} ,
) . Sub ( float64 ( v ) )
}
2023-06-14 08:00:44 +00:00
func ( m * engineMetrics ) SetMode ( shardID string , mode mode . Mode ) {
m . mode . SetMode ( shardID , mode . String ( ) )
2023-06-14 07:05:51 +00:00
}
func ( m * engineMetrics ) WriteCache ( ) WriteCacheMetrics {
return m . writeCache
}
func ( m * engineMetrics ) GC ( ) GCMetrics {
return m . gc
2023-06-01 14:28:04 +00:00
}
2024-03-12 14:36:26 +00:00
func ( m * engineMetrics ) IncRefillObjectsCount ( shardID , path string , size int , success bool ) {
m . refillObjCounter . With (
prometheus . Labels {
shardIDLabel : shardID ,
pathLabel : path ,
successLabel : strconv . FormatBool ( success ) ,
} ,
) . Inc ( )
m . refillPayloadCounter . With (
prometheus . Labels {
shardIDLabel : shardID ,
pathLabel : path ,
successLabel : strconv . FormatBool ( success ) ,
} ,
) . Add ( float64 ( size ) )
}
func ( m * engineMetrics ) SetRefillPercent ( shardID , path string , percent uint32 ) {
m . refillPercentCounter . With ( prometheus . Labels {
shardIDLabel : shardID ,
pathLabel : path ,
} ) . Set ( float64 ( percent ) )
}
func ( m * engineMetrics ) SetRefillStatus ( shardID , path , status string ) {
m . refillStatus . SetMode ( shardID , path , status )
}