@@ -379,105 +379,6 @@ func TestUpdateStates(t *testing.T) {
379
379
380
380
require .True (t , updateAgentMetricsFnCalled )
381
381
})
382
-
383
- t .Run ("WorkspaceUsageExperiment" , func (t * testing.T ) {
384
- t .Parallel ()
385
-
386
- var (
387
- now = dbtime .Now ()
388
- dbM = dbmock .NewMockStore (gomock .NewController (t ))
389
- ps = pubsub .NewInMemory ()
390
-
391
- templateScheduleStore = schedule.MockTemplateScheduleStore {
392
- GetFn : func (context.Context , database.Store , uuid.UUID ) (schedule.TemplateScheduleOptions , error ) {
393
- panic ("should not be called" )
394
- },
395
- SetFn : func (context.Context , database.Store , database.Template , schedule.TemplateScheduleOptions ) (database.Template , error ) {
396
- panic ("not implemented" )
397
- },
398
- }
399
- batcher = & wstest.StatsBatcher {}
400
-
401
- req = & agentproto.UpdateStatsRequest {
402
- Stats : & agentproto.Stats {
403
- ConnectionsByProto : map [string ]int64 {
404
- "tcp" : 1 ,
405
- "dean" : 2 ,
406
- },
407
- ConnectionCount : 3 ,
408
- ConnectionMedianLatencyMs : 23 ,
409
- RxPackets : 120 ,
410
- RxBytes : 1000 ,
411
- TxPackets : 130 ,
412
- TxBytes : 2000 ,
413
- SessionCountVscode : 1 ,
414
- SessionCountJetbrains : 2 ,
415
- SessionCountReconnectingPty : 3 ,
416
- SessionCountSsh : 4 ,
417
- Metrics : []* agentproto.Stats_Metric {
418
- {
419
- Name : "awesome metric" ,
420
- Value : 42 ,
421
- },
422
- {
423
- Name : "uncool metric" ,
424
- Value : 0 ,
425
- },
426
- },
427
- },
428
- }
429
- )
430
- api := agentapi.StatsAPI {
431
- AgentFn : func (context.Context ) (database.WorkspaceAgent , error ) {
432
- return agent , nil
433
- },
434
- Database : dbM ,
435
- StatsReporter : workspacestats .NewReporter (workspacestats.ReporterOptions {
436
- Database : dbM ,
437
- Pubsub : ps ,
438
- StatsBatcher : batcher ,
439
- TemplateScheduleStore : templateScheduleStorePtr (templateScheduleStore ),
440
- }),
441
- AgentStatsRefreshInterval : 10 * time .Second ,
442
- TimeNowFn : func () time.Time {
443
- return now
444
- },
445
- Experiments : []codersdk.Experiment {codersdk .ExperimentWorkspaceUsage },
446
- }
447
-
448
- // Workspace gets fetched.
449
- dbM .EXPECT ().GetWorkspaceByAgentID (gomock .Any (), agent .ID ).Return (database.GetWorkspaceByAgentIDRow {
450
- Workspace : workspace ,
451
- TemplateName : template .Name ,
452
- }, nil )
453
-
454
- // We expect an activity bump because ConnectionCount > 0.
455
- dbM .EXPECT ().ActivityBumpWorkspace (gomock .Any (), database.ActivityBumpWorkspaceParams {
456
- WorkspaceID : workspace .ID ,
457
- NextAutostart : time.Time {}.UTC (),
458
- }).Return (nil )
459
-
460
- // Workspace last used at gets bumped.
461
- dbM .EXPECT ().UpdateWorkspaceLastUsedAt (gomock .Any (), database.UpdateWorkspaceLastUsedAtParams {
462
- ID : workspace .ID ,
463
- LastUsedAt : now ,
464
- }).Return (nil )
465
-
466
- resp , err := api .UpdateStats (context .Background (), req )
467
- require .NoError (t , err )
468
- require .Equal (t , & agentproto.UpdateStatsResponse {
469
- ReportInterval : durationpb .New (10 * time .Second ),
470
- }, resp )
471
-
472
- batcher .Mu .Lock ()
473
- defer batcher .Mu .Unlock ()
474
- require .EqualValues (t , 1 , batcher .Called )
475
- require .EqualValues (t , 0 , batcher .LastStats .SessionCountSsh )
476
- // TODO: other session values will come as they are migrated over
477
- // require.EqualValues(t, batcher.lastStats.SessionCountVscode, 0)
478
- // require.EqualValues(t, batcher.lastStats.SessionCountJetbrains, 0)
479
- // require.EqualValues(t, batcher.lastStats.SessionCountReconnectingPty, 0)
480
- })
481
382
}
482
383
483
384
func templateScheduleStorePtr (store schedule.TemplateScheduleStore ) * atomic.Pointer [schedule.TemplateScheduleStore ] {
0 commit comments