Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backend] Allow capital letters and underscore in metric names #3741

Merged
merged 3 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion backend/src/apiserver/server/run_metric_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ import (
)

const (
metricNamePattern = "^[a-z]([-a-z0-9]{0,62}[a-z0-9])?$"
// This regex expresses the following constraints:
// * Allows lowercase/capital letters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lowercase/uppercase just to be symmetric?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, I forgot about uppercase. lol

// * Allows "_", "-" and numbers in the middle
// * Additionally, numbers are also allowed at the end
// * At most 64 characters
metricNamePattern = "^[a-zA-Z]([-_a-zA-Z0-9]{0,62}[a-zA-Z0-9])?$"
)

// ValidateRunMetric validates RunMetric fields from request.
Expand Down
17 changes: 13 additions & 4 deletions backend/src/apiserver/server/run_metric_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,21 @@ func TestValidateRunMetric_InvalidNodeIDs(t *testing.T) {
}

func TestNewReportRunMetricResult_OK(t *testing.T) {
expected := newReportRunMetricResult("metric-1", "node-1")
expected.Status = api.ReportRunMetricsResponse_ReportRunMetricResult_OK
tests := []struct {
metricName string
}{
{"metric-1"},
{"Metric_2"},
{"Metric3Name"},
}

actual := NewReportRunMetricResult(expected.GetMetricName(), expected.GetMetricNodeId(), nil)
for _, tc := range tests {
expected := newReportRunMetricResult(tc.metricName, "node-1")
expected.Status = api.ReportRunMetricsResponse_ReportRunMetricResult_OK
actual := NewReportRunMetricResult(expected.GetMetricName(), expected.GetMetricNodeId(), nil)

assert.Equal(t, expected, actual)
assert.Equalf(t, expected, actual, "TestNewReportRunMetricResult_OK metric name '%s' should be OK", tc.metricName)
}
}

func TestNewReportRunMetricResult_UnknownError(t *testing.T) {
Expand Down