- Notifications
You must be signed in to change notification settings - Fork928
feat: make agent stats' cardinality configurable#12535
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
975caa5
fcaebb3
70102f8
e3bfa0d
92e538a
fd19896
a682843
48b68ad
661f5c2
7d3ded4
defcf74
97f2bd1
8f2c505
c0896a7
c11dc61
cdd6734
06f2f87
3c1d016
f8ebdf2
05e5cd0
b1ef0d6
a669411
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,57 @@ | ||
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, | ||
}, | ||
dannykopping marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
{ | ||
name: "all valid entries", | ||
labels: agentmetrics.LabelAll, | ||
}, | ||
} | ||
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.