[#1410] shard: Provide the default implementation for MetricsWriter
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
6c46044c9c
commit
9206ce5cd2
4 changed files with 42 additions and 37 deletions
|
@ -45,9 +45,7 @@ func (s *Shard) UpdateID() (err error) {
|
|||
}
|
||||
|
||||
shardID := s.info.ID.String()
|
||||
if s.cfg.metricsWriter != nil {
|
||||
s.cfg.metricsWriter.SetShardID(shardID)
|
||||
}
|
||||
if s.writeCache != nil && s.writeCache.GetMetrics() != nil {
|
||||
s.writeCache.GetMetrics().SetShardID(shardID)
|
||||
}
|
||||
|
|
|
@ -45,3 +45,25 @@ type MetricsWriter interface {
|
|||
// SetEvacuationInProgress sets evacuation status
|
||||
SetEvacuationInProgress(value bool)
|
||||
}
|
||||
|
||||
type noopMetrics struct{}
|
||||
|
||||
var _ MetricsWriter = noopMetrics{}
|
||||
|
||||
func (noopMetrics) SetObjectCounter(string, uint64) {}
|
||||
func (noopMetrics) AddToObjectCounter(string, int) {}
|
||||
func (noopMetrics) AddToContainerSize(string, int64) {}
|
||||
func (noopMetrics) AddToPayloadSize(int64) {}
|
||||
func (noopMetrics) IncObjectCounter(string) {}
|
||||
func (noopMetrics) SetShardID(string) {}
|
||||
func (noopMetrics) SetMode(mode.Mode) {}
|
||||
func (noopMetrics) IncErrorCounter() {}
|
||||
func (noopMetrics) ClearErrorCounter() {}
|
||||
func (noopMetrics) DeleteShardMetrics() {}
|
||||
func (noopMetrics) SetContainerObjectsCount(string, string, uint64) {}
|
||||
func (noopMetrics) IncContainerObjectsCount(string, string) {}
|
||||
func (noopMetrics) SubContainerObjectsCount(string, string, uint64) {}
|
||||
func (noopMetrics) IncRefillObjectsCount(string, int, bool) {}
|
||||
func (noopMetrics) SetRefillPercent(string, uint32) {}
|
||||
func (noopMetrics) SetRefillStatus(string, string) {}
|
||||
func (noopMetrics) SetEvacuationInProgress(bool) {}
|
||||
|
|
|
@ -65,9 +65,7 @@ func (s *Shard) setMode(m mode.Mode) error {
|
|||
}
|
||||
|
||||
s.info.Mode = m
|
||||
if s.metricsWriter != nil {
|
||||
s.metricsWriter.SetMode(s.info.Mode)
|
||||
}
|
||||
|
||||
s.log.Info(logs.ShardShardModeSetSuccessfully,
|
||||
zap.Stringer("mode", s.info.Mode))
|
||||
|
|
|
@ -105,6 +105,7 @@ func defaultCfg() *cfg {
|
|||
reportErrorFunc: func(string, string, error) {},
|
||||
zeroSizeContainersCallback: func(context.Context, []cid.ID) {},
|
||||
zeroCountContainersCallback: func(context.Context, []cid.ID) {},
|
||||
metricsWriter: noopMetrics{},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -384,7 +385,7 @@ const (
|
|||
)
|
||||
|
||||
func (s *Shard) updateMetrics(ctx context.Context) {
|
||||
if s.cfg.metricsWriter == nil || s.GetMode().NoMetabase() {
|
||||
if s.GetMode().NoMetabase() {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -439,7 +440,6 @@ func (s *Shard) updateMetrics(ctx context.Context) {
|
|||
// incObjectCounter increment both physical and logical object
|
||||
// counters.
|
||||
func (s *Shard) incObjectCounter(cnrID cid.ID, isUser bool) {
|
||||
if s.cfg.metricsWriter != nil {
|
||||
s.cfg.metricsWriter.IncObjectCounter(physical)
|
||||
s.cfg.metricsWriter.IncObjectCounter(logical)
|
||||
s.cfg.metricsWriter.IncContainerObjectsCount(cnrID.EncodeToString(), physical)
|
||||
|
@ -449,25 +449,20 @@ func (s *Shard) incObjectCounter(cnrID cid.ID, isUser bool) {
|
|||
s.cfg.metricsWriter.IncContainerObjectsCount(cnrID.EncodeToString(), user)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Shard) decObjectCounterBy(typ string, v uint64) {
|
||||
if s.cfg.metricsWriter != nil && v > 0 {
|
||||
if v > 0 {
|
||||
s.cfg.metricsWriter.AddToObjectCounter(typ, -int(v))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Shard) setObjectCounterBy(typ string, v uint64) {
|
||||
if s.cfg.metricsWriter != nil && v > 0 {
|
||||
if v > 0 {
|
||||
s.cfg.metricsWriter.SetObjectCounter(typ, v)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Shard) decContainerObjectCounter(byCnr map[cid.ID]meta.ObjectCounters) {
|
||||
if s.cfg.metricsWriter == nil {
|
||||
return
|
||||
}
|
||||
|
||||
for cnrID, count := range byCnr {
|
||||
if count.Phy > 0 {
|
||||
s.cfg.metricsWriter.SubContainerObjectsCount(cnrID.EncodeToString(), physical, count.Phy)
|
||||
|
@ -482,46 +477,38 @@ func (s *Shard) decContainerObjectCounter(byCnr map[cid.ID]meta.ObjectCounters)
|
|||
}
|
||||
|
||||
func (s *Shard) addToContainerSize(cnr string, size int64) {
|
||||
if s.cfg.metricsWriter != nil && size != 0 {
|
||||
if size != 0 {
|
||||
s.cfg.metricsWriter.AddToContainerSize(cnr, size)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Shard) addToPayloadSize(size int64) {
|
||||
if s.cfg.metricsWriter != nil && size != 0 {
|
||||
if size != 0 {
|
||||
s.cfg.metricsWriter.AddToPayloadSize(size)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Shard) setContainerObjectsCount(cnr string, typ string, v uint64) {
|
||||
if s.cfg.metricsWriter != nil && v > 0 {
|
||||
if v > 0 {
|
||||
s.metricsWriter.SetContainerObjectsCount(cnr, typ, v)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Shard) IncErrorCounter() {
|
||||
if s.cfg.metricsWriter != nil {
|
||||
s.cfg.metricsWriter.IncErrorCounter()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Shard) ClearErrorCounter() {
|
||||
if s.cfg.metricsWriter != nil {
|
||||
s.cfg.metricsWriter.ClearErrorCounter()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Shard) DeleteShardMetrics() {
|
||||
if s.cfg.metricsWriter != nil {
|
||||
s.cfg.metricsWriter.DeleteShardMetrics()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Shard) SetEvacuationInProgress(val bool) {
|
||||
s.m.Lock()
|
||||
defer s.m.Unlock()
|
||||
s.info.EvacuationInProgress = val
|
||||
if s.metricsWriter != nil {
|
||||
s.metricsWriter.SetEvacuationInProgress(val)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue