Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
874 changes: 442 additions & 432 deletions api/services/control/control.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions api/services/control/control.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ message PruneRequest {

message DiskUsageRequest {
repeated string filter = 1;
int64 ageLimit = 2;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Struggled to find a good name for this. In Prune it is called KeepDuration but that name does not make sense at all for DiskUsage.

In buildx this is --filter until=<duration> that is detected on client side and converted to another field. buildx du will likely keep the same name there.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ageLimit SGTM - but if we change this, would it also make sense to change the name in the prune request? We're already making changes to these structs in the next release because of the new storage fields.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if prune had ageLimit is it obvious which way it works? Eg. is it pruning the things that are newer than ageLimit or older? Correct is older but I don't know if it is obvious.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I second this, ageLimit is fine for disk usage request. WDYT @dvdksn?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively maxAge, we use maxUsedSpace in GC policy.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maxAge is nice, it works well in both places 🎉

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anything, I think this is minAge

}

message DiskUsageResponse {
Expand Down
31 changes: 31 additions & 0 deletions api/services/control/control_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions cache/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,7 @@ func (cm *cacheManager) DiskUsage(ctx context.Context, opt client.DiskUsageInfo)
if err := cm.markShared(m); err != nil {
return nil, err
}
cutOff := time.Now().Add(-opt.AgeLimit)

var du []*client.UsageInfo
for id, cr := range m {
Expand All @@ -1468,9 +1469,15 @@ func (cm *cacheManager) DiskUsage(ctx context.Context, opt client.DiskUsageInfo)
RecordType: cr.recordType,
Shared: cr.shared,
}
if filter.Match(adaptUsageInfo(c)) {
du = append(du, c)
if !filter.Match(adaptUsageInfo(c)) {
continue
}
if opt.AgeLimit > 0 {
if c.LastUsedAt != nil && c.LastUsedAt.After(cutOff) {
continue
}
}
du = append(du, c)
}

eg, ctx := errgroup.WithContext(ctx)
Expand Down
17 changes: 15 additions & 2 deletions client/diskusage.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (c *Client) DiskUsage(ctx context.Context, opts ...DiskUsageOption) ([]*Usa
o.SetDiskUsageOption(info)
}

req := &controlapi.DiskUsageRequest{Filter: info.Filter}
req := &controlapi.DiskUsageRequest{Filter: info.Filter, AgeLimit: int64(info.AgeLimit)}
resp, err := c.ControlClient().DiskUsage(ctx, req)
if err != nil {
return nil, errors.Wrap(err, "failed to call diskusage")
Expand Down Expand Up @@ -72,7 +72,8 @@ type DiskUsageOption interface {
}

type DiskUsageInfo struct {
Filter []string
Filter []string
AgeLimit time.Duration
}

type UsageRecordType string
Expand All @@ -85,3 +86,15 @@ const (
UsageRecordTypeCacheMount UsageRecordType = "exec.cachemount"
UsageRecordTypeRegular UsageRecordType = "regular"
)

type diskUsageOptionFunc func(*DiskUsageInfo)

func (f diskUsageOptionFunc) SetDiskUsageOption(info *DiskUsageInfo) {
f(info)
}

func WithAgeLimit(age time.Duration) DiskUsageOption {
return diskUsageOptionFunc(func(info *DiskUsageInfo) {
info.AgeLimit = age
})
}
3 changes: 2 additions & 1 deletion control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ func (c *Controller) DiskUsage(ctx context.Context, r *controlapi.DiskUsageReque
}
for _, w := range workers {
du, err := w.DiskUsage(ctx, client.DiskUsageInfo{
Filter: r.Filter,
Filter: r.Filter,
AgeLimit: time.Duration(r.AgeLimit),
})
if err != nil {
return nil, err
Expand Down