Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(cyclops): keep partial OpenCost usage visible (#7111)

r33drichardsfcbb37f87967
diff --git a/libs/fleet/backend/usage/opencost.go b/libs/fleet/backend/usage/opencost.go
index e154392397..b409d63f21 100644
--- a/libs/fleet/backend/usage/opencost.go
+++ b/libs/fleet/backend/usage/opencost.go
@@ -262,17 +262,24 @@ func completeCoverageBoundary(frames []allocationFrame, requestedStart, requeste
sort.Slice(frames, func(i, j int) bool {
return frames[i].start.Before(frames[j].start)
})
- cutoff := requestedStart
+ latest := requestedStart
+ expected := requestedStart
+ complete := true
for _, frame := range frames {
- if !frame.start.Equal(cutoff) {
- return cutoff, false
+ if !frame.start.Equal(expected) {
+ complete = false
+ }
+ if frame.end.After(expected) {
+ expected = frame.end
+ }
+ if frame.end.After(latest) {
+ latest = frame.end
}
- cutoff = frame.end
}
- if cutoff.After(requestedEnd) {
- cutoff = requestedEnd
+ if latest.After(requestedEnd) {
+ latest = requestedEnd
}
- return cutoff, cutoff.Equal(requestedEnd)
+ return latest, complete && expected.Equal(requestedEnd)
}
func validateOpenCostAllocation(row openCostAllocation, requestedStart, requestedEnd time.Time, step time.Duration, allowed map[string]struct{}) (Allocation, bool) {
diff --git a/libs/fleet/backend/usage/opencost_test.go b/libs/fleet/backend/usage/opencost_test.go
index 93caef207e..e2e88f6b39 100644
--- a/libs/fleet/backend/usage/opencost_test.go
+++ b/libs/fleet/backend/usage/opencost_test.go
@@ -61,9 +61,10 @@ func TestParseOpenCostAllocationsMarksIncompleteCoverage(t *testing.T) {
wantCutoff time.Time
wantRows int
}{
- "empty": {[]byte(`{"code":200,"data":[]}`), start, 0},
- "missing_frame": {[]byte(`{"code":200,"data":[{"first":` + row(start, start.Add(time.Hour)) + `},{}]}`), start.Add(time.Hour), 1},
- "gap": {[]byte(`{"code":200,"data":[{"first":` + row(start, start.Add(time.Hour)) + `},{"third":` + row(start.Add(2*time.Hour), start.Add(3*time.Hour)) + `}]}`), start.Add(time.Hour), 1},
+ "empty": {[]byte(`{"code":200,"data":[]}`), start, 0},
+ "missing_frame": {[]byte(`{"code":200,"data":[{"first":` + row(start, start.Add(time.Hour)) + `},{}]}`), start.Add(time.Hour), 1},
+ "gap": {[]byte(`{"code":200,"data":[{"first":` + row(start, start.Add(time.Hour)) + `},{"third":` + row(start.Add(2*time.Hour), start.Add(3*time.Hour)) + `}]}`), start.Add(3 * time.Hour), 2},
+ "missing_prefix": {[]byte(`{"code":200,"data":[{"third":` + row(start.Add(2*time.Hour), start.Add(3*time.Hour)) + `}]}`), start.Add(3 * time.Hour), 1},
} {
t.Run(name, func(t *testing.T) {
allocations, asOf, partial, err := parseOpenCostAllocations(test.body, start, start.Add(3*time.Hour), time.Hour, []string{"ns-a"})