(ctx context.Context)
| 131 | } |
| 132 | |
| 133 | func (c *Cache) refreshDeploymentStats(ctx context.Context) error { |
| 134 | var ( |
| 135 | from = c.clock.Now().Add(-15 * time.Minute) |
| 136 | agentStats database.GetDeploymentWorkspaceAgentStatsRow |
| 137 | err error |
| 138 | ) |
| 139 | |
| 140 | if c.usage { |
| 141 | agentUsageStats, err := c.database.GetDeploymentWorkspaceAgentUsageStats(ctx, from) |
| 142 | if err != nil { |
| 143 | return err |
| 144 | } |
| 145 | agentStats = database.GetDeploymentWorkspaceAgentStatsRow(agentUsageStats) |
| 146 | } else { |
| 147 | agentStats, err = c.database.GetDeploymentWorkspaceAgentStats(ctx, from) |
| 148 | if err != nil { |
| 149 | return err |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | workspaceStats, err := c.database.GetDeploymentWorkspaceStats(ctx) |
| 154 | if err != nil { |
| 155 | return err |
| 156 | } |
| 157 | c.deploymentStatsResponse.Store(&codersdk.DeploymentStats{ |
| 158 | AggregatedFrom: from, |
| 159 | CollectedAt: dbtime.Time(c.clock.Now()), |
| 160 | NextUpdateAt: dbtime.Time(c.clock.Now().Add(c.intervals.DeploymentStats)), |
| 161 | Workspaces: codersdk.WorkspaceDeploymentStats{ |
| 162 | Pending: workspaceStats.PendingWorkspaces, |
| 163 | Building: workspaceStats.BuildingWorkspaces, |
| 164 | Running: workspaceStats.RunningWorkspaces, |
| 165 | Failed: workspaceStats.FailedWorkspaces, |
| 166 | Stopped: workspaceStats.StoppedWorkspaces, |
| 167 | ConnectionLatencyMS: codersdk.WorkspaceConnectionLatencyMS{ |
| 168 | P50: agentStats.WorkspaceConnectionLatency50, |
| 169 | P95: agentStats.WorkspaceConnectionLatency95, |
| 170 | }, |
| 171 | RxBytes: agentStats.WorkspaceRxBytes, |
| 172 | TxBytes: agentStats.WorkspaceTxBytes, |
| 173 | }, |
| 174 | SessionCount: codersdk.SessionCountDeploymentStats{ |
| 175 | VSCode: agentStats.SessionCountVSCode, |
| 176 | SSH: agentStats.SessionCountSSH, |
| 177 | JetBrains: agentStats.SessionCountJetBrains, |
| 178 | ReconnectingPTY: agentStats.SessionCountReconnectingPTY, |
| 179 | }, |
| 180 | }) |
| 181 | return nil |
| 182 | } |
| 183 | |
| 184 | func (c *Cache) run(ctx context.Context, name string, interval time.Duration, refresh func(context.Context) error) { |
| 185 | logger := c.log.With(slog.F("name", name), slog.F("interval", interval)) |
nothing calls this directly
no test coverage detected