forked from TrueCloudLab/frostfs-node
[#424] morphcache: Use labels for method duration
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
85deb12f4d
commit
c8023a9c8d
3 changed files with 16 additions and 48 deletions
|
@ -1,7 +1,6 @@
|
||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -12,66 +11,35 @@ import (
|
||||||
const (
|
const (
|
||||||
mcSubsystem = "morphcache"
|
mcSubsystem = "morphcache"
|
||||||
mcSuccess = "success"
|
mcSuccess = "success"
|
||||||
|
mcMethod = "method"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MorphCacheMetrics interface {
|
type MorphCacheMetrics interface {
|
||||||
AddNNSContractHashDuration(success bool, d time.Duration)
|
AddMethodDuration(method string, success bool, d time.Duration)
|
||||||
|
|
||||||
AddGroupKeyDuration(success bool, d time.Duration)
|
|
||||||
|
|
||||||
AddTxHeightDuration(success bool, d time.Duration)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type morphCacheMetrics struct {
|
type morphCacheMetrics struct {
|
||||||
// Duration of processing get nns contract hash request
|
methodDuration *prometheus.HistogramVec
|
||||||
nnsContractHashDuration *prometheus.HistogramVec
|
|
||||||
|
|
||||||
// Duration of processing get group key request
|
|
||||||
groupKeyDuration *prometheus.HistogramVec
|
|
||||||
|
|
||||||
// Duration of processing get tx height request
|
|
||||||
txHeightDuration *prometheus.HistogramVec
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ MorphCacheMetrics = (*morphCacheMetrics)(nil)
|
var _ MorphCacheMetrics = (*morphCacheMetrics)(nil)
|
||||||
|
|
||||||
func newMorphCacheMetrics() *morphCacheMetrics {
|
func newMorphCacheMetrics() *morphCacheMetrics {
|
||||||
return &morphCacheMetrics{
|
return &morphCacheMetrics{
|
||||||
nnsContractHashDuration: newMCMethodDurationCounter("nns_contract_hash"),
|
methodDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
|
||||||
groupKeyDuration: newMCMethodDurationCounter("group_key"),
|
|
||||||
txHeightDuration: newMCMethodDurationCounter("tx_height"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *morphCacheMetrics) AddNNSContractHashDuration(success bool, d time.Duration) {
|
|
||||||
m.nnsContractHashDuration.With(
|
|
||||||
prometheus.Labels{
|
|
||||||
mcSuccess: strconv.FormatBool(success),
|
|
||||||
},
|
|
||||||
).Observe(float64(d))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *morphCacheMetrics) AddGroupKeyDuration(success bool, d time.Duration) {
|
|
||||||
m.groupKeyDuration.With(
|
|
||||||
prometheus.Labels{
|
|
||||||
mcSuccess: strconv.FormatBool(success),
|
|
||||||
},
|
|
||||||
).Observe(float64(d))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *morphCacheMetrics) AddTxHeightDuration(success bool, d time.Duration) {
|
|
||||||
m.txHeightDuration.With(
|
|
||||||
prometheus.Labels{
|
|
||||||
mcSuccess: strconv.FormatBool(success),
|
|
||||||
},
|
|
||||||
).Observe(float64(d))
|
|
||||||
}
|
|
||||||
|
|
||||||
func newMCMethodDurationCounter(method string) *prometheus.HistogramVec {
|
|
||||||
return metrics.NewHistogramVec(prometheus.HistogramOpts{
|
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Subsystem: mcSubsystem,
|
Subsystem: mcSubsystem,
|
||||||
Name: fmt.Sprintf("%s_req_duration_seconds", method),
|
Name: "request_duration_seconds",
|
||||||
Help: fmt.Sprintf("Accumulated %s request process duration", method),
|
Help: "Morph cache request process duration",
|
||||||
}, []string{mcSuccess})
|
}, []string{mcSuccess, mcMethod}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *morphCacheMetrics) AddMethodDuration(method string, success bool, d time.Duration) {
|
||||||
|
m.methodDuration.With(
|
||||||
|
prometheus.Labels{
|
||||||
|
mcSuccess: strconv.FormatBool(success),
|
||||||
|
mcMethod: method,
|
||||||
|
},
|
||||||
|
).Observe(d.Seconds())
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ func (c *Client) NNSHash() (util.Uint160, error) {
|
||||||
startedAt := time.Now()
|
startedAt := time.Now()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
c.cache.metrics.AddNNSContractHashDuration(success, time.Since(startedAt))
|
c.cache.metrics.AddMethodDuration("NNSContractHash", success, time.Since(startedAt))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
nnsHash := c.cache.nns()
|
nnsHash := c.cache.nns()
|
||||||
|
@ -233,7 +233,7 @@ func (c *Client) contractGroupKey() (*keys.PublicKey, error) {
|
||||||
success := false
|
success := false
|
||||||
startedAt := time.Now()
|
startedAt := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
c.cache.metrics.AddGroupKeyDuration(success, time.Since(startedAt))
|
c.cache.metrics.AddMethodDuration("GroupKey", success, time.Since(startedAt))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if gKey := c.cache.groupKey(); gKey != nil {
|
if gKey := c.cache.groupKey(); gKey != nil {
|
||||||
|
|
|
@ -800,7 +800,7 @@ func (c *Client) getTransactionHeight(h util.Uint256) (uint32, error) {
|
||||||
success := false
|
success := false
|
||||||
startedAt := time.Now()
|
startedAt := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
c.cache.metrics.AddTxHeightDuration(success, time.Since(startedAt))
|
c.cache.metrics.AddMethodDuration("TxHeight", success, time.Since(startedAt))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if rh, ok := c.cache.txHeights.Get(h); ok {
|
if rh, ok := c.cache.txHeights.Get(h); ok {
|
||||||
|
|
Loading…
Reference in a new issue