Revert "feat: make agent stats' cardinality configurable (#12468)" (#12533)

This reverts commit 21d1873d97.
This commit is contained in:
Cian Johnston
2024-03-11 14:33:36 +00:00
committed by GitHub
parent 773862a9f5
commit 8f40ee3465
18 changed files with 85 additions and 747 deletions
-38
View File
@@ -1,38 +0,0 @@
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
}
-53
View File
@@ -1,53 +0,0 @@
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)
}
})
}
}