-
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
Changes from 3 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
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -338,6 +338,8 @@ func AgentStats(ctx context.Context, logger slog.Logger, registerer prometheus.R | |
aggregateByLabels = agentmetrics.LabelAgentStats | ||
} | ||
|
||
aggregateByLabels = filterInvalidLabels(aggregateByLabels) | ||
|
||
metricsCollectorAgentStats := prometheus.NewHistogram(prometheus.HistogramOpts{ | ||
Namespace: "coderd", | ||
Subsystem: "prometheusmetrics", | ||
|
@@ -514,3 +516,20 @@ func AgentStats(ctx context.Context, logger slog.Logger, registerer prometheus.R | |
<-done | ||
}, nil | ||
} | ||
|
||
// filterInvalidLabels handles a slightly messy situation whereby `prometheus-aggregate-agent-stats-by` can control on | ||
// which labels agent stats are aggregated, but for these specific metrics in this file there is no `template` label value, | ||
// and therefore we have to exclude it from the list of acceptable labels. | ||
func filterInvalidLabels(labels []string) []string { | ||
var out []string | ||
|
||
for _, label := range labels { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe optimize it this way?
|
||
if label == agentmetrics.LabelTemplateName { | ||
continue | ||
} | ||
|
||
out = append(out, label) | ||
} | ||
|
||
return out | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"github.com/coder/coder/v2/coderd/agentmetrics" | ||
|
||
"github.com/coder/coder/v2/coderd/batchstats" | ||
"github.com/coder/coder/v2/coderd/database/dbtestutil" | ||
"github.com/coder/coder/v2/coderd/database/dbtime" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: sorting? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hhmm, I ran There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh nice. I just ran it and it... changes a lot. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is extremely opinionated |
||
|
@@ -451,7 +453,7 @@ func TestAgentStats(t *testing.T) { | |
// and it doesn't depend on the real time. | ||
closeFunc, err := prometheusmetrics.AgentStats(ctx, slogtest.Make(t, &slogtest.Options{ | ||
IgnoreErrors: true, | ||
}), registry, db, time.Now().Add(-time.Minute), time.Millisecond, nil) | ||
}), registry, db, time.Now().Add(-time.Minute), time.Millisecond, agentmetrics.LabelAll) | ||
require.NoError(t, err) | ||
t.Cleanup(closeFunc) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add an
internal_test.go
to verify this function?