Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
24 commits
Select commitHold shift + click to select a range
1172e09
Initial implementation
dannykoppingMar 7, 2024
ddd563e
Refactoring
dannykoppingMar 8, 2024
6a1ab6e
Drive-by change to add delve to nix flake so ./scripts/develop.sh --d…
dannykoppingMar 8, 2024
ce0c22d
Update deployment config
dannykoppingMar 8, 2024
25fd616
Linting
dannykoppingMar 8, 2024
cc1a0b0
Control cardinality of coderd metrics as well
dannykoppingMar 8, 2024
122f68d
Remove default value
dannykoppingMar 8, 2024
3e569ff
make fmt && make gen
dannykoppingMar 8, 2024
62e2624
Appeasing CI
dannykoppingMar 8, 2024
6544d2d
Appeasing CI, again...
dannykoppingMar 8, 2024
5e89d05
...
dannykoppingMar 8, 2024
ae8a912
Fix loop var capture
dannykoppingMar 8, 2024
023f7d4
Review comments & CI appeasement
dannykoppingMar 11, 2024
9aedd97
Merge branch 'dk/configurable-cardinality' of github.com:dannykopping…
dannykoppingMar 11, 2024
92be1d6
More review comments & CI appeasement
dannykoppingMar 11, 2024
9b16a3b
Fixing lints
dannykoppingMar 11, 2024
6c7d1bd
Merge branch 'main' of github.com:/coder/coder into dk/configurable-c…
dannykoppingMar 11, 2024
3538e78
chore(dogfood): update keys
johnstcnMar 11, 2024
5a97817
Merge remote-tracking branch 'upstream/cj/dogfood-update-keys' into d…
dannykoppingMar 11, 2024
c861500
Merge branch 'main' of github.com:/coder/coder into dk/configurable-c…
dannykoppingMar 11, 2024
6bcfe99
Merge branch 'main' of github.com:/coder/coder into dk/configurable-c…
dannykoppingMar 11, 2024
765fe9d
Fix flaky label evaluation by sorting both sides
dannykoppingMar 11, 2024
37c3628
Merge branch 'main' of github.com:/coder/coder into dk/configurable-c…
dannykoppingMar 11, 2024
f1d2821
Update node key
dannykoppingMar 11, 2024
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
4 changes: 2 additions & 2 deletionscli/server.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -229,13 +229,13 @@ func enablePrometheus(
afterCtx(ctx, closeInsightsMetricsCollector)

if vals.Prometheus.CollectAgentStats {
closeAgentStatsFunc, err := prometheusmetrics.AgentStats(ctx, logger, options.PrometheusRegistry, options.Database, time.Now(), 0)
closeAgentStatsFunc, err := prometheusmetrics.AgentStats(ctx, logger, options.PrometheusRegistry, options.Database, time.Now(), 0, options.DeploymentValues.Prometheus.AggregateAgentStatsBy.Value())
if err != nil {
return nil, xerrors.Errorf("register agent stats prometheus metric: %w", err)
}
afterCtx(ctx, closeAgentStatsFunc)

metricsAggregator, err := prometheusmetrics.NewMetricsAggregator(logger, options.PrometheusRegistry, 0)
metricsAggregator, err := prometheusmetrics.NewMetricsAggregator(logger, options.PrometheusRegistry, 0, options.DeploymentValues.Prometheus.AggregateAgentStatsBy.Value())
if err != nil {
return nil, xerrors.Errorf("can't initialize metrics aggregator: %w", err)
}
Expand Down
5 changes: 5 additions & 0 deletionscli/testdata/coder_server_--help.golden
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -123,6 +123,11 @@ INTROSPECTION / PROMETHEUS OPTIONS:
--prometheus-address host:port, $CODER_PROMETHEUS_ADDRESS (default: 127.0.0.1:2112)
The bind address to serve prometheus metrics.

--prometheus-aggregate-agent-stats-by string-array, $CODER_PROMETHEUS_AGGREGATE_AGENT_STATS_BY (default: agent_name,template_name,username,workspace_name)
When collecting agent stats, aggregate metrics by a given set of
comma-separated labels to reduce cardinality. Accepted values are
agent_name, template_name, username, workspace_name.

--prometheus-collect-agent-stats bool, $CODER_PROMETHEUS_COLLECT_AGENT_STATS
Collect agent stats (may increase charges for metrics storage).

Expand Down
9 changes: 9 additions & 0 deletionscli/testdata/server-config.yaml.golden
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -188,6 +188,15 @@ introspection:
# Collect agent stats (may increase charges for metrics storage).
# (default: <unset>, type: bool)
collect_agent_stats: false
# When collecting agent stats, aggregate metrics by a given set of comma-separated
# labels to reduce cardinality. Accepted values are agent_name, template_name,
# username, workspace_name.
# (default: agent_name,template_name,username,workspace_name, type: string-array)
aggregate_agent_stats_by:
- agent_name
- template_name
- username
- workspace_name
# Collect database metrics (may increase charges for metrics storage).
# (default: false, type: bool)
collect_db_metrics: false
Expand Down
38 changes: 38 additions & 0 deletionscoderd/agentmetrics/labels.go
View file
Open in desktop
Original file line numberDiff line numberDiff 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
}
53 changes: 53 additions & 0 deletionscoderd/agentmetrics/labels_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff 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)
}
})
}
}
6 changes: 6 additions & 0 deletionscoderd/apidoc/docs.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

6 changes: 6 additions & 0 deletionscoderd/apidoc/swagger.json
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Loading

[8]ページ先頭

©2009-2025 Movatter.jp