forked from TrueCloudLab/frostfs-node
[#412] node: Replace metrics package
Use observability module. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
74578052f9
commit
c09144ecf1
15 changed files with 162 additions and 459 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
|
@ -12,8 +13,8 @@ const objectSubsystem = "object"
|
|||
|
||||
type (
|
||||
methodCount struct {
|
||||
success metric[prometheus.Counter]
|
||||
total metric[prometheus.Counter]
|
||||
success prometheus.Counter
|
||||
total prometheus.Counter
|
||||
}
|
||||
|
||||
objectServiceMetrics struct {
|
||||
|
@ -25,19 +26,19 @@ type (
|
|||
rangeCounter methodCount
|
||||
rangeHashCounter methodCount
|
||||
|
||||
getDuration metric[prometheus.Counter]
|
||||
putDuration metric[prometheus.Counter]
|
||||
headDuration metric[prometheus.Counter]
|
||||
searchDuration metric[prometheus.Counter]
|
||||
deleteDuration metric[prometheus.Counter]
|
||||
rangeDuration metric[prometheus.Counter]
|
||||
rangeHashDuration metric[prometheus.Counter]
|
||||
getDuration prometheus.Counter
|
||||
putDuration prometheus.Counter
|
||||
headDuration prometheus.Counter
|
||||
searchDuration prometheus.Counter
|
||||
deleteDuration prometheus.Counter
|
||||
rangeDuration prometheus.Counter
|
||||
rangeHashDuration prometheus.Counter
|
||||
|
||||
putPayload metric[prometheus.Counter]
|
||||
getPayload metric[prometheus.Counter]
|
||||
putPayload prometheus.Counter
|
||||
getPayload prometheus.Counter
|
||||
|
||||
shardMetrics metric[*prometheus.GaugeVec]
|
||||
shardsReadonly metric[*prometheus.GaugeVec]
|
||||
shardMetrics *prometheus.GaugeVec
|
||||
shardsReadonly *prometheus.GaugeVec
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -49,13 +50,13 @@ const (
|
|||
|
||||
func newObjectMethodCallCounter(name string) methodCount {
|
||||
return methodCount{
|
||||
success: newCounter(prometheus.CounterOpts{
|
||||
success: metrics.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: objectSubsystem,
|
||||
Name: fmt.Sprintf("%s_req_count_success", name),
|
||||
Help: fmt.Sprintf("The number of successful %s requests processed", name),
|
||||
}),
|
||||
total: newCounter(prometheus.CounterOpts{
|
||||
total: metrics.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: objectSubsystem,
|
||||
Name: fmt.Sprintf("%s_req_count", name),
|
||||
|
@ -64,15 +65,10 @@ func newObjectMethodCallCounter(name string) methodCount {
|
|||
}
|
||||
}
|
||||
|
||||
func (m methodCount) mustRegister() {
|
||||
mustRegister(m.success)
|
||||
mustRegister(m.total)
|
||||
}
|
||||
|
||||
func (m methodCount) Inc(success bool) {
|
||||
m.total.value.Inc()
|
||||
m.total.Inc()
|
||||
if success {
|
||||
m.success.value.Inc()
|
||||
m.success.Inc()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,8 +95,8 @@ func newObjectServiceMetrics() objectServiceMetrics {
|
|||
}
|
||||
}
|
||||
|
||||
func newObjectMethodPayloadCounter(method string) metric[prometheus.Counter] {
|
||||
return newCounter(prometheus.CounterOpts{
|
||||
func newObjectMethodPayloadCounter(method string) prometheus.Counter {
|
||||
return metrics.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: objectSubsystem,
|
||||
Name: fmt.Sprintf("%s_payload", method),
|
||||
|
@ -108,8 +104,8 @@ func newObjectMethodPayloadCounter(method string) metric[prometheus.Counter] {
|
|||
})
|
||||
}
|
||||
|
||||
func newObjectMethodDurationCounter(method string) metric[prometheus.Counter] {
|
||||
return newCounter(prometheus.CounterOpts{
|
||||
func newObjectMethodDurationCounter(method string) prometheus.Counter {
|
||||
return metrics.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: objectSubsystem,
|
||||
Name: fmt.Sprintf("%s_req_duration", method),
|
||||
|
@ -117,8 +113,8 @@ func newObjectMethodDurationCounter(method string) metric[prometheus.Counter] {
|
|||
})
|
||||
}
|
||||
|
||||
func newObjectGaugeVector(name, help string, labels []string) metric[*prometheus.GaugeVec] {
|
||||
return newGaugeVec(prometheus.GaugeOpts{
|
||||
func newObjectGaugeVector(name, help string, labels []string) *prometheus.GaugeVec {
|
||||
return metrics.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: objectSubsystem,
|
||||
Name: name,
|
||||
|
@ -126,30 +122,6 @@ func newObjectGaugeVector(name, help string, labels []string) metric[*prometheus
|
|||
}, labels)
|
||||
}
|
||||
|
||||
func (m objectServiceMetrics) register() {
|
||||
m.getCounter.mustRegister()
|
||||
m.putCounter.mustRegister()
|
||||
m.headCounter.mustRegister()
|
||||
m.searchCounter.mustRegister()
|
||||
m.deleteCounter.mustRegister()
|
||||
m.rangeCounter.mustRegister()
|
||||
m.rangeHashCounter.mustRegister()
|
||||
|
||||
mustRegister(m.getDuration)
|
||||
mustRegister(m.putDuration)
|
||||
mustRegister(m.headDuration)
|
||||
mustRegister(m.searchDuration)
|
||||
mustRegister(m.deleteDuration)
|
||||
mustRegister(m.rangeDuration)
|
||||
mustRegister(m.rangeHashDuration)
|
||||
|
||||
mustRegister(m.putPayload)
|
||||
mustRegister(m.getPayload)
|
||||
|
||||
mustRegister(m.shardMetrics)
|
||||
mustRegister(m.shardsReadonly)
|
||||
}
|
||||
|
||||
func (m objectServiceMetrics) IncGetReqCounter(success bool) {
|
||||
m.getCounter.Inc(success)
|
||||
}
|
||||
|
@ -179,43 +151,43 @@ func (m objectServiceMetrics) IncRangeHashReqCounter(success bool) {
|
|||
}
|
||||
|
||||
func (m objectServiceMetrics) AddGetReqDuration(d time.Duration) {
|
||||
m.getDuration.value.Add(float64(d))
|
||||
m.getDuration.Add(float64(d))
|
||||
}
|
||||
|
||||
func (m objectServiceMetrics) AddPutReqDuration(d time.Duration) {
|
||||
m.putDuration.value.Add(float64(d))
|
||||
m.putDuration.Add(float64(d))
|
||||
}
|
||||
|
||||
func (m objectServiceMetrics) AddHeadReqDuration(d time.Duration) {
|
||||
m.headDuration.value.Add(float64(d))
|
||||
m.headDuration.Add(float64(d))
|
||||
}
|
||||
|
||||
func (m objectServiceMetrics) AddSearchReqDuration(d time.Duration) {
|
||||
m.searchDuration.value.Add(float64(d))
|
||||
m.searchDuration.Add(float64(d))
|
||||
}
|
||||
|
||||
func (m objectServiceMetrics) AddDeleteReqDuration(d time.Duration) {
|
||||
m.deleteDuration.value.Add(float64(d))
|
||||
m.deleteDuration.Add(float64(d))
|
||||
}
|
||||
|
||||
func (m objectServiceMetrics) AddRangeReqDuration(d time.Duration) {
|
||||
m.rangeDuration.value.Add(float64(d))
|
||||
m.rangeDuration.Add(float64(d))
|
||||
}
|
||||
|
||||
func (m objectServiceMetrics) AddRangeHashReqDuration(d time.Duration) {
|
||||
m.rangeHashDuration.value.Add(float64(d))
|
||||
m.rangeHashDuration.Add(float64(d))
|
||||
}
|
||||
|
||||
func (m objectServiceMetrics) AddPutPayload(ln int) {
|
||||
m.putPayload.value.Add(float64(ln))
|
||||
m.putPayload.Add(float64(ln))
|
||||
}
|
||||
|
||||
func (m objectServiceMetrics) AddGetPayload(ln int) {
|
||||
m.getPayload.value.Add(float64(ln))
|
||||
m.getPayload.Add(float64(ln))
|
||||
}
|
||||
|
||||
func (m objectServiceMetrics) AddToObjectCounter(shardID, objectType string, delta int) {
|
||||
m.shardMetrics.value.With(
|
||||
m.shardMetrics.With(
|
||||
prometheus.Labels{
|
||||
shardIDLabelKey: shardID,
|
||||
counterTypeLabelKey: objectType,
|
||||
|
@ -224,7 +196,7 @@ func (m objectServiceMetrics) AddToObjectCounter(shardID, objectType string, del
|
|||
}
|
||||
|
||||
func (m objectServiceMetrics) SetObjectCounter(shardID, objectType string, v uint64) {
|
||||
m.shardMetrics.value.With(
|
||||
m.shardMetrics.With(
|
||||
prometheus.Labels{
|
||||
shardIDLabelKey: shardID,
|
||||
counterTypeLabelKey: objectType,
|
||||
|
@ -237,7 +209,7 @@ func (m objectServiceMetrics) SetReadonly(shardID string, readonly bool) {
|
|||
if readonly {
|
||||
flag = 1
|
||||
}
|
||||
m.shardsReadonly.value.With(
|
||||
m.shardsReadonly.With(
|
||||
prometheus.Labels{
|
||||
shardIDLabelKey: shardID,
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue