Skip to content

Commit ae50163

Browse files
easyCZroboquat
authored andcommitted
[usage] Round
1 parent c9bf0c6 commit ae50163

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

components/usage/pkg/controller/reconciler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func (u *UsageReconciler) ReconcileTimeRange(ctx context.Context, from, to time.
131131
func generateUsageReport(teams []teamWithWorkspaces, maxStopTime time.Time) ([]TeamUsage, error) {
132132
var report []TeamUsage
133133
for _, team := range teams {
134-
var teamTotalRuntime float64
134+
var teamTotalRuntime int64
135135
for _, workspace := range team.Workspaces {
136136
for _, instance := range workspace.Instances {
137137
teamTotalRuntime += instance.WorkspaceRuntimeSeconds(maxStopTime)
@@ -312,6 +312,6 @@ func toSet(items []string) []string {
312312
}
313313

314314
type TeamUsage struct {
315-
TeamID string `json:"team_id"`
316-
WorkspaceSeconds float64 `json:"workspace_seconds"`
315+
TeamID string `json:"team_id"`
316+
WorkspaceSeconds int64 `json:"workspace_seconds"`
317317
}

components/usage/pkg/controller/reconciler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func TestUsageReconciler_ReconcileTimeRange(t *testing.T) {
138138
Report: []TeamUsage{
139139
{
140140
TeamID: teamID.String(),
141-
WorkspaceSeconds: 9.223372036854766e+11,
141+
WorkspaceSeconds: instances[0].WorkspaceRuntimeSeconds(runTime) * 100,
142142
},
143143
},
144144
},

components/usage/pkg/db/workspace_instance.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ type WorkspaceInstance struct {
4444

4545
// WorkspaceRuntimeSeconds computes how long this WorkspaceInstance has been running.
4646
// If the instance is still running (no stop time set), maxStopTime is used to to compute the duration - this is an upper bound on stop
47-
func (i *WorkspaceInstance) WorkspaceRuntimeSeconds(maxStopTime time.Time) float64 {
47+
func (i *WorkspaceInstance) WorkspaceRuntimeSeconds(maxStopTime time.Time) int64 {
4848
start := i.StartedTime.Time()
4949
stop := maxStopTime
5050
if i.StoppedTime.IsSet() {
5151
stop = i.StoppedTime.Time()
5252
}
5353

54-
return stop.Sub(start).Seconds()
54+
return int64(stop.Sub(start).Round(time.Second).Seconds())
5555
}
5656

5757
// TableName sets the insert table name for this struct type

0 commit comments

Comments
 (0)