Add test to validate metric name correctness
Enforce metrics names should be lowercase and conform to regex `[a-z][a-z_]+`
package metrics
import (
- "github.com/stretchr/testify/require"
+ "fmt"
+ "regexp"
"testing"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
+var IsMetric = regexp.MustCompile(`^[a-z][a-z_]*$`).MatchString
+
func TestScopeDefsMapped(t *testing.T) {
for i := PersistenceCreateShardScope; i < NumCommonScopes; i++ {
key, ok := ScopeDefs[Common][i]
@@ -75,3 +81,12 @@ func TestMetricDefsMapped(t *testing.T) {
require.NotEmpty(t, key)
}
}
+
+func TestMetricDefs(t *testing.T) {
+ for service, metrics := range MetricDefs {
+ for _, metricDef := range metrics {
+ matched := IsMetric(string(metricDef.metricName))
+ assert.True(t, matched, fmt.Sprintf("Service: %v, metric_name: %v", service, metricDef.metricName))
+ }
+ }
+}
