diff --git a/internal/p2p/metrics.go b/internal/p2p/metrics.go index 3a8a0d850..3677180de 100644 --- a/internal/p2p/metrics.go +++ b/internal/p2p/metrics.go @@ -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. diff --git a/internal/p2p/metrics_test.go b/internal/p2p/metrics_test.go index e1add2979..53b3c47bd 100644 --- a/internal/p2p/metrics_test.go +++ b/internal/p2p/metrics_test.go @@ -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) }