@@ -17,13 +17,15 @@ import (
17
17
18
18
"cdr.dev/slog"
19
19
"cdr.dev/slog/sloggers/slogtest"
20
+ "github.com/coder/coder/v2/agent"
20
21
"github.com/coder/coder/v2/agent/agenttest"
21
22
"github.com/coder/coder/v2/coderd/coderdtest"
22
23
"github.com/coder/coder/v2/coderd/database/dbauthz"
23
24
"github.com/coder/coder/v2/coderd/database/dbtestutil"
24
25
"github.com/coder/coder/v2/coderd/prometheusmetrics/insights"
25
26
"github.com/coder/coder/v2/coderd/workspaceapps"
26
27
"github.com/coder/coder/v2/codersdk"
28
+ "github.com/coder/coder/v2/codersdk/agentsdk"
27
29
"github.com/coder/coder/v2/provisioner/echo"
28
30
"github.com/coder/coder/v2/provisionersdk/proto"
29
31
"github.com/coder/coder/v2/testutil"
@@ -78,9 +80,28 @@ func TestCollectInsights(t *testing.T) {
78
80
coderdtest .AwaitWorkspaceBuildJobCompleted (t , client , workspace .LatestBuild .ID )
79
81
80
82
// Start an agent so that we can generate stats.
81
- _ = agenttest .New (t , client .URL , authToken )
83
+ agentClient := agentsdk .New (client .URL )
84
+ agentClient .SetSessionToken (authToken )
85
+ agentClient .SDK .SetLogger (logger .Leveled (slog .LevelDebug ).Named ("agent" ))
86
+
87
+ _ = agenttest .New (t , client .URL , authToken , func (o * agent.Options ) {
88
+ o .Client = agentClient
89
+ })
82
90
resources := coderdtest .AwaitWorkspaceAgents (t , client , workspace .ID )
83
91
92
+ // Fake app stats
93
+ _ , err = agentClient .PostStats (context .Background (), & agentsdk.Stats {
94
+ // ConnectionsByProto can't be nil, otherwise stats get rejected
95
+ ConnectionsByProto : map [string ]int64 {"TCP" : 1 },
96
+ // ConnectionCount must be positive as database query ignores stats with no active connections at the time frame
97
+ ConnectionCount : 74 ,
98
+ // SessionCountJetBrains, SessionCountVSCode must be positive, but the exact value is ignored.
99
+ // Database query approximates it to 60s of usage.
100
+ SessionCountJetBrains : 47 ,
101
+ SessionCountVSCode : 34 ,
102
+ })
103
+ require .NoError (t , err , "unable to post fake stats" )
104
+
84
105
// Fake app usage
85
106
reporter := workspaceapps .NewStatsDBReporter (db , workspaceapps .DefaultStatsDBReporterBatchSize )
86
107
//nolint:gocritic // This is a test.
0 commit comments