mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: handle new agent stat format correctly (#14576)
--------- Co-authored-by: Ethan Dickson <ethan@coder.com>
This commit is contained in:
co-authored by
Ethan Dickson
parent
37885e2e82
commit
922f4c545f
@@ -34,6 +34,10 @@ type Cache struct {
|
||||
|
||||
done chan struct{}
|
||||
cancel func()
|
||||
|
||||
// usage is a experiment flag to enable new workspace usage tracking behavior and will be
|
||||
// removed when the experiment is complete.
|
||||
usage bool
|
||||
}
|
||||
|
||||
type Intervals struct {
|
||||
@@ -41,7 +45,7 @@ type Intervals struct {
|
||||
DeploymentStats time.Duration
|
||||
}
|
||||
|
||||
func New(db database.Store, log slog.Logger, intervals Intervals) *Cache {
|
||||
func New(db database.Store, log slog.Logger, intervals Intervals, usage bool) *Cache {
|
||||
if intervals.TemplateBuildTimes <= 0 {
|
||||
intervals.TemplateBuildTimes = time.Hour
|
||||
}
|
||||
@@ -56,6 +60,7 @@ func New(db database.Store, log slog.Logger, intervals Intervals) *Cache {
|
||||
log: log,
|
||||
done: make(chan struct{}),
|
||||
cancel: cancel,
|
||||
usage: usage,
|
||||
}
|
||||
go func() {
|
||||
var wg sync.WaitGroup
|
||||
@@ -125,11 +130,25 @@ func (c *Cache) refreshTemplateBuildTimes(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (c *Cache) refreshDeploymentStats(ctx context.Context) error {
|
||||
from := dbtime.Now().Add(-15 * time.Minute)
|
||||
agentStats, err := c.database.GetDeploymentWorkspaceAgentStats(ctx, from)
|
||||
if err != nil {
|
||||
return err
|
||||
var (
|
||||
from = dbtime.Now().Add(-15 * time.Minute)
|
||||
agentStats database.GetDeploymentWorkspaceAgentStatsRow
|
||||
err error
|
||||
)
|
||||
|
||||
if c.usage {
|
||||
agentUsageStats, err := c.database.GetDeploymentWorkspaceAgentUsageStats(ctx, from)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
agentStats = database.GetDeploymentWorkspaceAgentStatsRow(agentUsageStats)
|
||||
} else {
|
||||
agentStats, err = c.database.GetDeploymentWorkspaceAgentStats(ctx, from)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
workspaceStats, err := c.database.GetDeploymentWorkspaceStats(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user