-
Notifications
You must be signed in to change notification settings - Fork 902
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dannykopping
merged 22 commits into
coder:main
from
dannykopping:dk/configurable-cardinality
Mar 13, 2024
Merged
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
975caa5
Initial implementation
dannykopping fcaebb3
Refactoring
dannykopping 70102f8
Drive-by change to add delve to nix flake so ./scripts/develop.sh --d…
dannykopping e3bfa0d
Update deployment config
dannykopping 92e538a
Linting
dannykopping fd19896
Control cardinality of coderd metrics as well
dannykopping a682843
Remove default value
dannykopping 48b68ad
make fmt && make gen
dannykopping 661f5c2
Appeasing CI
dannykopping 7d3ded4
Appeasing CI, again...
dannykopping defcf74
...
dannykopping 97f2bd1
Review comments & CI appeasement
dannykopping 8f2c505
More review comments & CI appeasement
dannykopping c0896a7
Fixing lints
dannykopping c11dc61
chore(dogfood): update keys
johnstcn cdd6734
Fix flaky label evaluation by sorting both sides
dannykopping 06f2f87
Update node key
dannykopping 3c1d016
Filter out unacceptable labels in AgentStats
dannykopping f8ebdf2
make fmt
dannykopping 05e5cd0
Merge branch 'dk/configurable-cardinality' of github.com:dannykopping…
dannykopping b1ef0d6
Merge branch 'main' of github.com:/coder/coder into dk/configurable-c…
dannykopping a669411
Review comments
dannykopping File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.