fix(registry): accumulate blob sizes into SpaceReclaimed during prune
- commit
- 52cf0df949621ecd0cd703f4cb72ea670e9ce99e
- author
- brice · · 2026-03-27 18:36 UTC
- parent
- f5d3652
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +5 -3
M internal/usecase/images/service.go +3 -1
| @@ -243,10 +243,12 @@ func (s *Service) PruneRegistry(ctx context.Context, keepLast int) (domain.Image | |||
| 243 | 243 | if _, referenced := referencedDigests[digest]; referenced { | |
| 244 | 244 | continue | |
| 245 | 245 | } | |
| 246 | - | if err := s.blobStorage.DeleteBlob(digest); err != nil { | |
| 246 | + | size, err := s.blobStorage.DeleteBlob(digest) | |
| 247 | + | if err != nil { | |
| 247 | 248 | return domain.ImagePruneReport{}, log.WrapErr(err, "failed to delete blob") | |
| 248 | 249 | } | |
| 249 | 250 | report.Registry.BlobsRemoved++ | |
| 251 | + | report.Registry.SpaceReclaimed += size | |
| 250 | 252 | } | |
| 251 | 253 | ||
| 252 | 254 | // Clean up stale uploads (abandoned push operations) | |
| @@ -243,10 +243,12 @@ func (s *Service) PruneRegistry(ctx context.Context, keepLast int) (domain.Image | |||||
| 243 | if _, referenced := referencedDigests[digest]; referenced { | 243 | if _, referenced := referencedDigests[digest]; referenced { | ||
| 244 | continue | 244 | continue | ||
| 245 | } | 245 | } | ||
| 246 | - | if err := s.blobStorage.DeleteBlob(digest); err != nil { | 246 | + | size, err := s.blobStorage.DeleteBlob(digest) |
| 247 | + | if err != nil { | |||
| 247 | return domain.ImagePruneReport{}, log.WrapErr(err, "failed to delete blob") | 248 | return domain.ImagePruneReport{}, log.WrapErr(err, "failed to delete blob") | ||
| 248 | } | 249 | } | ||
| 249 | report.Registry.BlobsRemoved++ | 250 | report.Registry.BlobsRemoved++ | ||
| 251 | + | report.Registry.SpaceReclaimed += size | |||
| 250 | } | 252 | } | ||
| 251 | 253 | ||||
| 252 | // Clean up stale uploads (abandoned push operations) | 254 | // Clean up stale uploads (abandoned push operations) | ||
M internal/usecase/images/service_test.go +2 -2
| @@ -789,7 +789,7 @@ func (f *fakeBlobStorage) ListBlobs() ([]string, error) { | |||
| 789 | 789 | return append([]string(nil), f.blobs...), nil | |
| 790 | 790 | } | |
| 791 | 791 | ||
| 792 | - | func (f *fakeBlobStorage) DeleteBlob(digest string) error { | |
| 792 | + | func (f *fakeBlobStorage) DeleteBlob(digest string) (int64, error) { | |
| 793 | 793 | f.deletedBlobs = append(f.deletedBlobs, digest) | |
| 794 | 794 | for i, existing := range f.blobs { | |
| 795 | 795 | if existing != digest { | |
| @@ -798,7 +798,7 @@ func (f *fakeBlobStorage) DeleteBlob(digest string) error { | |||
| 798 | 798 | f.blobs = append(f.blobs[:i], f.blobs[i+1:]...) | |
| 799 | 799 | break | |
| 800 | 800 | } | |
| 801 | - | return nil | |
| 801 | + | return 0, nil | |
| 802 | 802 | } | |
| 803 | 803 | ||
| 804 | 804 | func (f *fakeBlobStorage) CleanupStaleUploads(_ time.Duration) (int, int64, error) { | |
| @@ -789,7 +789,7 @@ func (f *fakeBlobStorage) ListBlobs() ([]string, error) { | |||||
| 789 | return append([]string(nil), f.blobs...), nil | 789 | return append([]string(nil), f.blobs...), nil | ||
| 790 | } | 790 | } | ||
| 791 | 791 | ||||
| 792 | - | func (f *fakeBlobStorage) DeleteBlob(digest string) error { | 792 | + | func (f *fakeBlobStorage) DeleteBlob(digest string) (int64, error) { |
| 793 | f.deletedBlobs = append(f.deletedBlobs, digest) | 793 | f.deletedBlobs = append(f.deletedBlobs, digest) | ||
| 794 | for i, existing := range f.blobs { | 794 | for i, existing := range f.blobs { | ||
| 795 | if existing != digest { | 795 | if existing != digest { | ||
| @@ -798,7 +798,7 @@ func (f *fakeBlobStorage) DeleteBlob(digest string) error { | |||||
| 798 | f.blobs = append(f.blobs[:i], f.blobs[i+1:]...) | 798 | f.blobs = append(f.blobs[:i], f.blobs[i+1:]...) | ||
| 799 | break | 799 | break | ||
| 800 | } | 800 | } | ||
| 801 | - | return nil | 801 | + | return 0, nil |
| 802 | } | 802 | } | ||
| 803 | 803 | ||||
| 804 | func (f *fakeBlobStorage) CleanupStaleUploads(_ time.Duration) (int, int64, error) { | 804 | func (f *fakeBlobStorage) CleanupStaleUploads(_ time.Duration) (int, int64, error) { | ||