chore: wire up usage tracking for managed agents (#19096)

Wires up the usage collector and publisher to coderd.

Relates to coder/internal#814
This commit is contained in:
Dean Sheather
2025-08-20 23:38:09 +10:00
committed by GitHub
parent dd867bd743
commit 6eb02d1c2a
43 changed files with 540 additions and 346 deletions
+10
View File
@@ -10,6 +10,7 @@ import (
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/coder/coder/v2/buildinfo"
@@ -21,10 +22,12 @@ import (
"github.com/coder/coder/v2/coderd/pproflabel"
agplprebuilds "github.com/coder/coder/v2/coderd/prebuilds"
"github.com/coder/coder/v2/coderd/rbac/policy"
agplusage "github.com/coder/coder/v2/coderd/usage"
"github.com/coder/coder/v2/coderd/wsbuilder"
"github.com/coder/coder/v2/enterprise/coderd/connectionlog"
"github.com/coder/coder/v2/enterprise/coderd/enidpsync"
"github.com/coder/coder/v2/enterprise/coderd/portsharing"
"github.com/coder/coder/v2/enterprise/coderd/usage"
"github.com/coder/quartz"
"golang.org/x/xerrors"
@@ -90,6 +93,13 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
if options.Entitlements == nil {
options.Entitlements = entitlements.New()
}
if options.Options.UsageInserter == nil {
options.Options.UsageInserter = &atomic.Pointer[agplusage.Inserter]{}
}
if options.Options.UsageInserter.Load() == nil {
collector := usage.NewDBInserter()
options.Options.UsageInserter.Store(&collector)
}
ctx, cancelFunc := context.WithCancel(ctx)