From fb8fee0c8edd3cca1d9aaa40bf7334df46400964 Mon Sep 17 00:00:00 2001 From: Alejandro Lopez Date: Tue, 13 Jun 2023 14:19:33 +0300 Subject: [PATCH] [#442] Use strconv.FormatBool instead of untyped conversion Signed-off-by: Alejandro Lopez --- pkg/metrics/gc.go | 6 +++--- pkg/metrics/morphcache.go | 7 ++++--- pkg/metrics/treeservice.go | 8 ++++---- pkg/metrics/writecache.go | 5 +++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/pkg/metrics/gc.go b/pkg/metrics/gc.go index 2457c0c6..9c00d872 100644 --- a/pkg/metrics/gc.go +++ b/pkg/metrics/gc.go @@ -1,7 +1,7 @@ package metrics import ( - "fmt" + "strconv" "time" "git.frostfs.info/TrueCloudLab/frostfs-observability/metrics" @@ -64,7 +64,7 @@ func newGCMetrics() *gcMetrics { func (m *gcMetrics) AddRunDuration(shardID string, d time.Duration, success bool) { m.runDuration.With(prometheus.Labels{ gcShardID: shardID, - gcSuccess: fmt.Sprintf("%v", success), + gcSuccess: strconv.FormatBool(success), }).Add(d.Seconds()) } @@ -84,7 +84,7 @@ func (m *gcMetrics) AddDeletedCount(shardID string, deleted, failed uint64) { func (m *gcMetrics) AddExpiredObjectCollectionDuration(shardID string, d time.Duration, success bool, objectType string) { m.expCollectDuration.With(prometheus.Labels{ gcShardID: shardID, - gcSuccess: fmt.Sprintf("%v", success), + gcSuccess: strconv.FormatBool(success), gcObjectType: objectType, }).Add(d.Seconds()) } diff --git a/pkg/metrics/morphcache.go b/pkg/metrics/morphcache.go index 7f6f2d7d..2440adcf 100644 --- a/pkg/metrics/morphcache.go +++ b/pkg/metrics/morphcache.go @@ -2,6 +2,7 @@ package metrics import ( "fmt" + "strconv" "time" "git.frostfs.info/TrueCloudLab/frostfs-observability/metrics" @@ -46,7 +47,7 @@ func newMorphCacheMetrics() *morphCacheMetrics { func (m *morphCacheMetrics) AddNNSContractHashDuration(success bool, d time.Duration) { m.nnsContractHashDuration.With( prometheus.Labels{ - mcSuccess: fmt.Sprintf("%v", success), + mcSuccess: strconv.FormatBool(success), }, ).Observe(float64(d)) } @@ -54,7 +55,7 @@ func (m *morphCacheMetrics) AddNNSContractHashDuration(success bool, d time.Dura func (m *morphCacheMetrics) AddGroupKeyDuration(success bool, d time.Duration) { m.groupKeyDuration.With( prometheus.Labels{ - mcSuccess: fmt.Sprintf("%v", success), + mcSuccess: strconv.FormatBool(success), }, ).Observe(float64(d)) } @@ -62,7 +63,7 @@ func (m *morphCacheMetrics) AddGroupKeyDuration(success bool, d time.Duration) { func (m *morphCacheMetrics) AddTxHeightDuration(hash util.Uint256, success bool, d time.Duration) { m.txHeightDuration.With( prometheus.Labels{ - mcSuccess: fmt.Sprintf("%v", success), + mcSuccess: strconv.FormatBool(success), }, ).Observe(float64(d)) } diff --git a/pkg/metrics/treeservice.go b/pkg/metrics/treeservice.go index 48a450c7..ae24c41b 100644 --- a/pkg/metrics/treeservice.go +++ b/pkg/metrics/treeservice.go @@ -1,7 +1,7 @@ package metrics import ( - "fmt" + "strconv" "time" "git.frostfs.info/TrueCloudLab/frostfs-observability/metrics" @@ -50,18 +50,18 @@ func newTreeServiceMetrics() *treeServiceMetrics { func (m *treeServiceMetrics) AddReplicateTaskDuration(d time.Duration, success bool) { m.replicateTaskDuration.With(prometheus.Labels{ - treeServiceLabelSuccess: fmt.Sprintf("%v", success), + treeServiceLabelSuccess: strconv.FormatBool(success), }).Observe(d.Seconds()) } func (m *treeServiceMetrics) AddReplicateWaitDuration(d time.Duration, success bool) { m.replicateWaitDuration.With(prometheus.Labels{ - treeServiceLabelSuccess: fmt.Sprintf("%v", success), + treeServiceLabelSuccess: strconv.FormatBool(success), }).Observe(d.Seconds()) } func (m *treeServiceMetrics) AddSyncDuration(d time.Duration, success bool) { m.syncOpDuration.With(prometheus.Labels{ - treeServiceLabelSuccess: fmt.Sprintf("%v", success), + treeServiceLabelSuccess: strconv.FormatBool(success), }).Observe(d.Seconds()) } diff --git a/pkg/metrics/writecache.go b/pkg/metrics/writecache.go index 67b9d8ca..b27e684d 100644 --- a/pkg/metrics/writecache.go +++ b/pkg/metrics/writecache.go @@ -2,6 +2,7 @@ package metrics import ( "fmt" + "strconv" "sync" "time" @@ -148,7 +149,7 @@ func (m *writeCacheMetrics) SetMode(shardID string, mode string) { func (m *writeCacheMetrics) IncFlushCounter(shardID string, success bool, storageType string) { m.flushCounter.With(prometheus.Labels{ wcShardID: shardID, - wcSuccess: fmt.Sprintf("%v", success), + wcSuccess: strconv.FormatBool(success), wcStorage: storageType, }).Inc() } @@ -164,7 +165,7 @@ func setWriteCacheDuration(m *prometheus.HistogramVec, shardID string, success b m.With( prometheus.Labels{ wcShardID: shardID, - wcSuccess: fmt.Sprintf("%v", success), + wcSuccess: strconv.FormatBool(success), wcStorage: storageType, }, ).Observe(d.Seconds())