Skip to content

feat: expose template insights as Prometheus metrics #10325

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
merged 21 commits into from
Oct 19, 2023
Merged
Prev Previous commit
Next Next commit
Fix?
  • Loading branch information
mtojek committed Oct 18, 2023
commit 2d03fedb9b5b1d80f3ef3a0bb67cbb15d8bb40dc
15 changes: 8 additions & 7 deletions coderd/prometheusmetrics/insights/metricscollector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,13 @@ func TestCollect_TemplateInsights(t *testing.T) {
client := coderdtest.New(t, options)

// Given
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()

// Initialize metrics collector
mc, err := insights.NewMetricsCollector(db, logger.Named("metrics_collector"), 0, time.Millisecond)
require.NoError(t, err)

registry := prometheus.NewRegistry()
registry.Register(mc)

closeFunc, err := mc.Run(ctx)
require.NoError(t, err)
t.Cleanup(closeFunc)

// Create two users, one that will appear in the report and another that
// won't (due to not having/using a workspace).
user := coderdtest.CreateFirstUser(t, client)
Expand All @@ -73,6 +66,14 @@ func TestCollect_TemplateInsights(t *testing.T) {
_ = agenttest.New(t, client.URL, authToken)
resources := coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()

// Run metrics collector
closeFunc, err := mc.Run(ctx)
require.NoError(t, err)
t.Cleanup(closeFunc)

// Connect to the agent to generate usage/latency stats.
conn, err := client.DialWorkspaceAgent(ctx, resources[0].Agents[0].ID, &codersdk.DialWorkspaceAgentOptions{
Logger: logger.Named("client"),
Expand Down