forked from TrueCloudLab/frostfs-node
[#2022] Add metric readonly
to get shards mode
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
e5c304536b
commit
edb1428248
7 changed files with 59 additions and 3 deletions
|
@ -13,6 +13,7 @@ Changelog for NeoFS Node
|
||||||
- Fix NNS hash parsing in morph client (#2063)
|
- Fix NNS hash parsing in morph client (#2063)
|
||||||
- `neofs-cli neofs-cli acl basic/extended print` commands (#2012)
|
- `neofs-cli neofs-cli acl basic/extended print` commands (#2012)
|
||||||
- `neofs_node_object_*_req_count_success` prometheus metrics for tracking successfully executed requests (#1984)
|
- `neofs_node_object_*_req_count_success` prometheus metrics for tracking successfully executed requests (#1984)
|
||||||
|
- Metric 'readonly' to get shards mode (#2022)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- `object lock` command reads CID and OID the same way other commands do (#1971)
|
- `object lock` command reads CID and OID the same way other commands do (#1971)
|
||||||
|
|
|
@ -19,6 +19,8 @@ type MetricRegister interface {
|
||||||
|
|
||||||
SetObjectCounter(shardID, objectType string, v uint64)
|
SetObjectCounter(shardID, objectType string, v uint64)
|
||||||
AddToObjectCounter(shardID, objectType string, delta int)
|
AddToObjectCounter(shardID, objectType string, delta int)
|
||||||
|
|
||||||
|
SetReadonly(shardID string, readonly bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
func elapsed(addFunc func(d time.Duration)) func() {
|
func elapsed(addFunc func(d time.Duration)) func() {
|
||||||
|
|
|
@ -45,6 +45,10 @@ func (m *metricsWithID) DecObjectCounter(objectType string) {
|
||||||
m.mw.AddToObjectCounter(m.id, objectType, -1)
|
m.mw.AddToObjectCounter(m.id, objectType, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *metricsWithID) SetReadonly(readonly bool) {
|
||||||
|
m.mw.SetReadonly(m.id, readonly)
|
||||||
|
}
|
||||||
|
|
||||||
// AddShard adds a new shard to the storage engine.
|
// AddShard adds a new shard to the storage engine.
|
||||||
//
|
//
|
||||||
// Returns any error encountered that did not allow adding a shard.
|
// Returns any error encountered that did not allow adding a shard.
|
||||||
|
@ -60,6 +64,10 @@ func (e *StorageEngine) AddShard(opts ...shard.Option) (*shard.ID, error) {
|
||||||
return nil, fmt.Errorf("could not add %s shard: %w", sh.ID().String(), err)
|
return nil, fmt.Errorf("could not add %s shard: %w", sh.ID().String(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if e.cfg.metrics != nil {
|
||||||
|
e.cfg.metrics.SetReadonly(sh.ID().String(), sh.GetMode() != mode.ReadWrite)
|
||||||
|
}
|
||||||
|
|
||||||
return sh.ID(), nil
|
return sh.ID(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
meta "github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
meta "github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
||||||
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/pilorama"
|
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/pilorama"
|
||||||
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
||||||
|
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
||||||
"github.com/TrueCloudLab/frostfs-sdk-go/object"
|
"github.com/TrueCloudLab/frostfs-sdk-go/object"
|
||||||
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
|
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -50,13 +51,27 @@ func (m metricsStore) DecObjectCounter(objectType string) {
|
||||||
m.AddToObjectCounter(objectType, -1)
|
m.AddToObjectCounter(objectType, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m metricsStore) SetReadonly(r bool) {
|
||||||
|
if r {
|
||||||
|
m.s[readonly] = 1
|
||||||
|
} else {
|
||||||
|
m.s[readonly] = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const physical = "phy"
|
const physical = "phy"
|
||||||
const logical = "logic"
|
const logical = "logic"
|
||||||
|
const readonly = "readonly"
|
||||||
|
|
||||||
func TestCounters(t *testing.T) {
|
func TestCounters(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
sh, mm := shardWithMetrics(t, dir)
|
sh, mm := shardWithMetrics(t, dir)
|
||||||
|
|
||||||
|
sh.SetMode(mode.ReadOnly)
|
||||||
|
require.Equal(t, mm.s[readonly], uint64(1))
|
||||||
|
sh.SetMode(mode.ReadWrite)
|
||||||
|
require.Equal(t, mm.s[readonly], uint64(0))
|
||||||
|
|
||||||
const objNumber = 10
|
const objNumber = 10
|
||||||
oo := make([]*object.Object, objNumber)
|
oo := make([]*object.Object, objNumber)
|
||||||
for i := 0; i < objNumber; i++ {
|
for i := 0; i < objNumber; i++ {
|
||||||
|
@ -151,6 +166,7 @@ func shardWithMetrics(t *testing.T, path string) (*shard.Shard, *metricsStore) {
|
||||||
s: map[string]uint64{
|
s: map[string]uint64{
|
||||||
"phy": 0,
|
"phy": 0,
|
||||||
"logic": 0,
|
"logic": 0,
|
||||||
|
"readonly": 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,9 @@ func (s *Shard) setMode(m mode.Mode) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
s.info.Mode = m
|
s.info.Mode = m
|
||||||
|
if s.metricsWriter != nil {
|
||||||
|
s.metricsWriter.SetReadonly(s.info.Mode != mode.ReadWrite)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,8 @@ type MetricsWriter interface {
|
||||||
// SetShardID must set (update) the shard identifier that will be used in
|
// SetShardID must set (update) the shard identifier that will be used in
|
||||||
// metrics.
|
// metrics.
|
||||||
SetShardID(id string)
|
SetShardID(id string)
|
||||||
|
// SetReadonly must set shard readonly state.
|
||||||
|
SetReadonly(readonly bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
type cfg struct {
|
type cfg struct {
|
||||||
|
|
|
@ -36,6 +36,7 @@ type (
|
||||||
getPayload prometheus.Counter
|
getPayload prometheus.Counter
|
||||||
|
|
||||||
shardMetrics *prometheus.GaugeVec
|
shardMetrics *prometheus.GaugeVec
|
||||||
|
shardsReadonly *prometheus.GaugeVec
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -158,6 +159,15 @@ func newObjectServiceMetrics() objectServiceMetrics {
|
||||||
},
|
},
|
||||||
[]string{shardIDLabelKey, counterTypeLabelKey},
|
[]string{shardIDLabelKey, counterTypeLabelKey},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
shardsReadonly = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: objectSubsystem,
|
||||||
|
Name: "readonly",
|
||||||
|
Help: "Shard state",
|
||||||
|
},
|
||||||
|
[]string{shardIDLabelKey},
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return objectServiceMetrics{
|
return objectServiceMetrics{
|
||||||
|
@ -178,6 +188,7 @@ func newObjectServiceMetrics() objectServiceMetrics {
|
||||||
putPayload: putPayload,
|
putPayload: putPayload,
|
||||||
getPayload: getPayload,
|
getPayload: getPayload,
|
||||||
shardMetrics: shardsMetrics,
|
shardMetrics: shardsMetrics,
|
||||||
|
shardsReadonly: shardsReadonly,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,6 +213,7 @@ func (m objectServiceMetrics) register() {
|
||||||
prometheus.MustRegister(m.getPayload)
|
prometheus.MustRegister(m.getPayload)
|
||||||
|
|
||||||
prometheus.MustRegister(m.shardMetrics)
|
prometheus.MustRegister(m.shardMetrics)
|
||||||
|
prometheus.MustRegister(m.shardsReadonly)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m objectServiceMetrics) IncGetReqCounter(success bool) {
|
func (m objectServiceMetrics) IncGetReqCounter(success bool) {
|
||||||
|
@ -285,3 +297,15 @@ func (m objectServiceMetrics) SetObjectCounter(shardID, objectType string, v uin
|
||||||
},
|
},
|
||||||
).Set(float64(v))
|
).Set(float64(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m objectServiceMetrics) SetReadonly(shardID string, readonly bool) {
|
||||||
|
var flag float64
|
||||||
|
if readonly {
|
||||||
|
flag = 1
|
||||||
|
}
|
||||||
|
m.shardsReadonly.With(
|
||||||
|
prometheus.Labels{
|
||||||
|
shardIDLabelKey: shardID,
|
||||||
|
},
|
||||||
|
).Set(flag)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue