Skip to content

Commit b5e83cb

Browse files
committed
rename interface
1 parent 9295149 commit b5e83cb

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

coderd/agentapi/stats_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type statsBatcher struct {
3939
lastStats *agentproto.Stats
4040
}
4141

42-
var _ workspacestats.StatsBatcher = &statsBatcher{}
42+
var _ workspacestats.Batcher = &statsBatcher{}
4343

4444
func (b *statsBatcher) Add(now time.Time, agentID uuid.UUID, templateID uuid.UUID, userID uuid.UUID, workspaceID uuid.UUID, st *agentproto.Stats) error {
4545
b.mu.Lock()

coderd/coderd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ type Options struct {
187187
HTTPClient *http.Client
188188

189189
UpdateAgentMetrics func(ctx context.Context, labels prometheusmetrics.AgentMetricLabels, metrics []*agentproto.Stats_Metric)
190-
StatsBatcher *workspacestats.Batcher
190+
StatsBatcher *workspacestats.DBBatcher
191191

192192
WorkspaceAppsStatsCollectorOptions workspaceapps.StatsCollectorOptions
193193

coderd/coderdtest/coderdtest.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ type Options struct {
144144
// Logger should only be overridden if you expect errors
145145
// as part of your test.
146146
Logger *slog.Logger
147-
StatsBatcher *workspacestats.Batcher
147+
StatsBatcher *workspacestats.DBBatcher
148148

149149
WorkspaceAppsStatsCollectorOptions workspaceapps.StatsCollectorOptions
150150
AllowWorkspaceRenames bool

coderd/workspacestats/batcher.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ const (
2424
defaultFlushInterval = time.Second
2525
)
2626

27-
type StatsBatcher interface {
27+
type Batcher interface {
2828
Add(now time.Time, agentID uuid.UUID, templateID uuid.UUID, userID uuid.UUID, workspaceID uuid.UUID, st *agentproto.Stats) error
2929
}
3030

31-
// Batcher holds a buffer of agent stats and periodically flushes them to
31+
// DBBatcher holds a buffer of agent stats and periodically flushes them to
3232
// its configured store.
33-
type Batcher struct {
33+
type DBBatcher struct {
3434
store database.Store
3535
log slog.Logger
3636

@@ -54,39 +54,39 @@ type Batcher struct {
5454
}
5555

5656
// Option is a functional option for configuring a Batcher.
57-
type BatcherOption func(b *Batcher)
57+
type BatcherOption func(b *DBBatcher)
5858

5959
// BatcherWithStore sets the store to use for storing stats.
6060
func BatcherWithStore(store database.Store) BatcherOption {
61-
return func(b *Batcher) {
61+
return func(b *DBBatcher) {
6262
b.store = store
6363
}
6464
}
6565

6666
// BatcherWithBatchSize sets the number of stats to store in a batch.
6767
func BatcherWithBatchSize(size int) BatcherOption {
68-
return func(b *Batcher) {
68+
return func(b *DBBatcher) {
6969
b.batchSize = size
7070
}
7171
}
7272

7373
// BatcherWithInterval sets the interval for flushes.
7474
func BatcherWithInterval(d time.Duration) BatcherOption {
75-
return func(b *Batcher) {
75+
return func(b *DBBatcher) {
7676
b.interval = d
7777
}
7878
}
7979

8080
// BatcherWithLogger sets the logger to use for logging.
8181
func BatcherWithLogger(log slog.Logger) BatcherOption {
82-
return func(b *Batcher) {
82+
return func(b *DBBatcher) {
8383
b.log = log
8484
}
8585
}
8686

8787
// NewBatcher creates a new Batcher and starts it.
88-
func NewBatcher(ctx context.Context, opts ...BatcherOption) (*Batcher, func(), error) {
89-
b := &Batcher{}
88+
func NewBatcher(ctx context.Context, opts ...BatcherOption) (*DBBatcher, func(), error) {
89+
b := &DBBatcher{}
9090
b.log = slog.Make(sloghuman.Sink(os.Stderr))
9191
b.flushLever = make(chan struct{}, 1) // Buffered so that it doesn't block.
9292
for _, opt := range opts {
@@ -131,7 +131,7 @@ func NewBatcher(ctx context.Context, opts ...BatcherOption) (*Batcher, func(), e
131131
}
132132

133133
// Add adds a stat to the batcher for the given workspace and agent.
134-
func (b *Batcher) Add(
134+
func (b *DBBatcher) Add(
135135
now time.Time,
136136
agentID uuid.UUID,
137137
templateID uuid.UUID,
@@ -178,7 +178,7 @@ func (b *Batcher) Add(
178178
}
179179

180180
// Run runs the batcher.
181-
func (b *Batcher) run(ctx context.Context) {
181+
func (b *DBBatcher) run(ctx context.Context) {
182182
// nolint:gocritic // This is only ever used for one thing - inserting agent stats.
183183
authCtx := dbauthz.AsSystemRestricted(ctx)
184184
for {
@@ -203,7 +203,7 @@ func (b *Batcher) run(ctx context.Context) {
203203
}
204204

205205
// flush flushes the batcher's buffer.
206-
func (b *Batcher) flush(ctx context.Context, forced bool, reason string) {
206+
func (b *DBBatcher) flush(ctx context.Context, forced bool, reason string) {
207207
b.mu.Lock()
208208
b.flushForced.Store(true)
209209
start := time.Now()
@@ -260,7 +260,7 @@ func (b *Batcher) flush(ctx context.Context, forced bool, reason string) {
260260
}
261261

262262
// initBuf resets the buffer. b MUST be locked.
263-
func (b *Batcher) initBuf(size int) {
263+
func (b *DBBatcher) initBuf(size int) {
264264
b.buf = &database.InsertWorkspaceAgentStatsParams{
265265
ID: make([]uuid.UUID, 0, b.batchSize),
266266
CreatedAt: make([]time.Time, 0, b.batchSize),
@@ -284,7 +284,7 @@ func (b *Batcher) initBuf(size int) {
284284
b.connectionsByProto = make([]map[string]int64, 0, size)
285285
}
286286

287-
func (b *Batcher) resetBuf() {
287+
func (b *DBBatcher) resetBuf() {
288288
b.buf.ID = b.buf.ID[:0]
289289
b.buf.CreatedAt = b.buf.CreatedAt[:0]
290290
b.buf.UserID = b.buf.UserID[:0]

coderd/workspacestats/batcher_internal_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestBatchStats(t *testing.T) {
3838
b, closer, err := NewBatcher(ctx,
3939
BatcherWithStore(store),
4040
BatcherWithLogger(log),
41-
func(b *Batcher) {
41+
func(b *DBBatcher) {
4242
b.tickCh = tick
4343
b.flushed = flushed
4444
},

coderd/workspacestats/reporter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type ReporterOptions struct {
2727
Logger slog.Logger
2828
Pubsub pubsub.Pubsub
2929
TemplateScheduleStore *atomic.Pointer[schedule.TemplateScheduleStore]
30-
StatsBatcher StatsBatcher
30+
StatsBatcher Batcher
3131
UsageTracker *UsageTracker
3232
UpdateAgentMetricsFn func(ctx context.Context, labels prometheusmetrics.AgentMetricLabels, metrics []*agentproto.Stats_Metric)
3333

0 commit comments

Comments
 (0)