- Notifications
You must be signed in to change notification settings - Fork928
feat: make agent stats' cardinality configurable#12468
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
1172e09
ddd563e
6a1ab6e
ce0c22d
25fd616
cc1a0b0
122f68d
3e569ff
62e2624
6544d2d
5e89d05
ae8a912
023f7d4
9aedd97
92be1d6
9b16a3b
6c7d1bd
3538e78
5a97817
c861500
6bcfe99
765fe9d
37c3628
f1d2821
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package agentmetrics | ||
import ( | ||
"strings" | ||
"golang.org/x/xerrors" | ||
) | ||
const ( | ||
LabelAgentName = "agent_name" | ||
LabelTemplateName = "template_name" | ||
LabelUsername = "username" | ||
LabelWorkspaceName = "workspace_name" | ||
) | ||
var ( | ||
LabelAll = []string{LabelAgentName, LabelTemplateName, LabelUsername, LabelWorkspaceName} | ||
LabelAgentStats = []string{LabelAgentName, LabelUsername, LabelWorkspaceName} | ||
) | ||
// ValidateAggregationLabels ensures a given set of labels are valid aggregation labels. | ||
func ValidateAggregationLabels(labels []string) error { | ||
acceptable := LabelAll | ||
seen := make(map[string]any, len(acceptable)) | ||
for _, label := range acceptable { | ||
seen[label] = nil | ||
} | ||
for _, label := range labels { | ||
if _, found := seen[label]; !found { | ||
return xerrors.Errorf("%q is not a valid aggregation label; only one or more of %q are acceptable", | ||
label, strings.Join(acceptable, ", ")) | ||
} | ||
} | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package agentmetrics_test | ||
import ( | ||
"testing" | ||
"github.com/stretchr/testify/require" | ||
"github.com/coder/coder/v2/coderd/agentmetrics" | ||
) | ||
func TestValidateAggregationLabels(t *testing.T) { | ||
t.Parallel() | ||
tests := []struct { | ||
name string | ||
labels []string | ||
expectedErr bool | ||
}{ | ||
{ | ||
name: "empty list is valid", | ||
}, | ||
{ | ||
name: "single valid entry", | ||
labels: []string{agentmetrics.LabelTemplateName}, | ||
}, | ||
{ | ||
name: "multiple valid entries", | ||
labels: []string{agentmetrics.LabelTemplateName, agentmetrics.LabelUsername}, | ||
}, | ||
{ | ||
name: "repeated valid entries are not invalid", | ||
labels: []string{agentmetrics.LabelTemplateName, agentmetrics.LabelUsername, agentmetrics.LabelUsername, agentmetrics.LabelUsername}, | ||
}, | ||
{ | ||
name: "empty entry is invalid", | ||
labels: []string{""}, | ||
expectedErr: true, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
tc := tc | ||
t.Run(tc.name, func(t *testing.T) { | ||
t.Parallel() | ||
err := agentmetrics.ValidateAggregationLabels(tc.labels) | ||
if tc.expectedErr { | ||
require.Error(t, err) | ||
} | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.