mirror of
https://github.com/tendermint/tendermint.git
synced 2026-05-21 14:41:30 +00:00
fix p2p label test to work with numbers
This commit is contained in:
@@ -22,7 +22,7 @@ var (
|
||||
// valueToLabelRegexp is used to find the golang package name and type name
|
||||
// so that the name can be turned into a prometheus label where the characters
|
||||
// in the label do not include prometheus special characters such as '*' and '.'.
|
||||
valueToLabelRegexp = regexp.MustCompile("\\*?([a-zA-Z0-0]+)\\.(.*)")
|
||||
valueToLabelRegexp = regexp.MustCompile(`\*?(\w+)\.(.*)`)
|
||||
)
|
||||
|
||||
// Metrics contains metrics exposed by this package.
|
||||
@@ -156,7 +156,7 @@ func NopMetrics() *Metrics {
|
||||
}
|
||||
}
|
||||
|
||||
// ValueToMetricLabel is a function that is used to produce a prometheus label value of the golang
|
||||
// ValueToMetricLabel is a method that is used to produce a prometheus label value of the golang
|
||||
// type that is passed in.
|
||||
// This method uses a map on the Metrics struct so that each label name only needs
|
||||
// to be produced once to prevent expensive string operations.
|
||||
|
||||
@@ -4,16 +4,16 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tendermint/tendermint/proto/tendermint/statesync"
|
||||
"github.com/tendermint/tendermint/proto/tendermint/p2p"
|
||||
)
|
||||
|
||||
func TestValueToMetricsLabel(t *testing.T) {
|
||||
m := NopMetrics()
|
||||
r := &statesync.ParamsRequest{}
|
||||
r := &p2p.PexResponse{}
|
||||
str := m.ValueToMetricLabel(r)
|
||||
assert.Equal(t, "statesync_ParamsRequest", str)
|
||||
assert.Equal(t, "p2p_PexResponse", str)
|
||||
|
||||
// subsequent calls to the function should produce the same result
|
||||
str = m.ValueToMetricLabel(r)
|
||||
assert.Equal(t, "statesync_ParamsRequest", str)
|
||||
assert.Equal(t, "p2p_PexResponse", str)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user