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
@@ -12,6 +12,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -473,13 +474,24 @@ func (r *remoteReporter) createSnapshot() (*Snapshot, error) {
|
||||
return nil
|
||||
})
|
||||
eg.Go(func() error {
|
||||
stats, err := r.options.Database.GetWorkspaceAgentStats(ctx, createdAfter)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("get workspace agent stats: %w", err)
|
||||
}
|
||||
snapshot.WorkspaceAgentStats = make([]WorkspaceAgentStat, 0, len(stats))
|
||||
for _, stat := range stats {
|
||||
snapshot.WorkspaceAgentStats = append(snapshot.WorkspaceAgentStats, ConvertWorkspaceAgentStat(stat))
|
||||
if r.options.DeploymentConfig != nil && slices.Contains(r.options.DeploymentConfig.Experiments, string(codersdk.ExperimentWorkspaceUsage)) {
|
||||
agentStats, err := r.options.Database.GetWorkspaceAgentUsageStats(ctx, createdAfter)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("get workspace agent stats: %w", err)
|
||||
}
|
||||
snapshot.WorkspaceAgentStats = make([]WorkspaceAgentStat, 0, len(agentStats))
|
||||
for _, stat := range agentStats {
|
||||
snapshot.WorkspaceAgentStats = append(snapshot.WorkspaceAgentStats, ConvertWorkspaceAgentStat(database.GetWorkspaceAgentStatsRow(stat)))
|
||||
}
|
||||
} else {
|
||||
agentStats, err := r.options.Database.GetWorkspaceAgentStats(ctx, createdAfter)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("get workspace agent stats: %w", err)
|
||||
}
|
||||
snapshot.WorkspaceAgentStats = make([]WorkspaceAgentStat, 0, len(agentStats))
|
||||
for _, stat := range agentStats {
|
||||
snapshot.WorkspaceAgentStats = append(snapshot.WorkspaceAgentStats, ConvertWorkspaceAgentStat(stat))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user