fix p2p label test to work with numbers

This commit is contained in:
William Banfield
2021-10-26 09:08:00 +02:00
parent b87c3b49c9
commit fcebb1e015
2 changed files with 6 additions and 6 deletions

View File

@@ -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.

View File

@@ -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)
}