Skip to content
Closed
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
2 changes: 1 addition & 1 deletion cmd/dive/cli/internal/command/ci/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (e Evaluator) Evaluate(ctx context.Context, analysis *image.Analysis) Evalu

e.InefficientFiles = append(e.InefficientFiles, ReferenceFile{
References: len(fileData.Nodes),
SizeBytes: uint64(fileData.CumulativeSize),
SizeBytes: uint64(fileData.WastedSize()),
Path: fileData.Path,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"sizeBytes": 6405
}
],
"inefficientBytes": 32025,
"inefficientBytes": 19215,
"sizeBytes": 1220598
},
"layer": [
Expand Down
2 changes: 1 addition & 1 deletion cmd/dive/cli/internal/ui/v1/view/image_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (v *ImageDetails) Render() error {
var wastedSpace int64
for idx := 0; idx < len(v.inefficiencies); idx++ {
data := v.inefficiencies[len(v.inefficiencies)-1-idx]
wastedSpace += data.CumulativeSize
wastedSpace += data.WastedSize()

inefficiencyReport += fmt.Sprintf(analysisTemplate, strconv.Itoa(len(data.Nodes)), humanize.Bytes(uint64(data.CumulativeSize)), data.Path)
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/dive/cli/testdata/snapshots/cli_build_test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,19 @@ View build details: docker-desktop://<redacted>
[Test_Build_CI_gate_fail - 1]
Analysis:
efficiency: 100.00 %
wastedBytes: 131 bytes (131 B)
userWastedPercent: 71.98 %
wastedBytes: 97 bytes (97 B)
userWastedPercent: 53.30 %

Inefficient Files:
Count Wasted Space File Path
3 80 B /root/saved.txt
2 34 B /root/example/somefile1.txt
3 63 B /root/saved.txt
2 17 B /root/example/somefile1.txt
2 17 B /root/example/somefile3.txt
2 0 B /root
10 0 B /etc

Evaluation:
FAIL highestUserWastedPercent (too many bytes wasted, relative to the user bytes added (%-user-wasted-bytes=0.72 > threshold=0.1))
FAIL highestUserWastedPercent (too many bytes wasted, relative to the user bytes added (%-user-wasted-bytes=0.53 > threshold=0.1))
SKIP highestWastedBytes (disabled)
PASS lowestEfficiency (0.9)

Expand Down
10 changes: 5 additions & 5 deletions cmd/dive/cli/testdata/snapshots/cli_ci_test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
[Test_CI_Fail - 1]
Analysis:
efficiency: 100.00 %
wastedBytes: 131 bytes (131 B)
userWastedPercent: 71.98 %
wastedBytes: 97 bytes (97 B)
userWastedPercent: 53.30 %

Inefficient Files:
Count Wasted Space File Path
3 80 B /root/saved.txt
2 34 B /root/example/somefile1.txt
3 63 B /root/saved.txt
2 17 B /root/example/somefile1.txt
2 17 B /root/example/somefile3.txt
2 0 B /root
10 0 B /etc

Evaluation:
FAIL highestUserWastedPercent (too many bytes wasted, relative to the user bytes added (%-user-wasted-bytes=0.72 > threshold=0.1))
FAIL highestUserWastedPercent (too many bytes wasted, relative to the user bytes added (%-user-wasted-bytes=0.53 > threshold=0.1))
SKIP highestWastedBytes (disabled)
PASS lowestEfficiency (0.9)

Expand Down
11 changes: 11 additions & 0 deletions dive/filetree/efficiency.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ type EfficiencyData struct {
minDiscoveredSize int64
}

// WastedSize returns the number of bytes that could be reclaimed for this
// path by keeping a single copy. CumulativeSize sums every copy across
// layers, including the smallest one we'd keep, so the recoverable amount
// is the total minus the smallest copy.
func (e *EfficiencyData) WastedSize() int64 {
if e.minDiscoveredSize < 0 {
return 0
}
return e.CumulativeSize - e.minDiscoveredSize
}

// EfficiencySlice represents an ordered set of EfficiencyData data structures.
type EfficiencySlice []*EfficiencyData

Expand Down
2 changes: 1 addition & 1 deletion dive/image/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func Analyze(ctx context.Context, img *Image) (*Analysis, error) {

var wastedBytes uint64
for _, file := range inefficiencies {
wastedBytes += uint64(file.CumulativeSize)
wastedBytes += uint64(file.WastedSize())
}

return &Analysis{
Expand Down
2 changes: 1 addition & 1 deletion dive/image/docker/image_archive_analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func Test_Analysis(t *testing.T) {
wastedPercent float64
path string
}{
"docker-image": {0.9844212134184309, 1220598, 66237, 32025, 0.4834911001404049, "../../../.data/test-docker-image.tar"},
"docker-image": {0.9844212134184309, 1220598, 66237, 19215, 0.29009466008424295, "../../../.data/test-docker-image.tar"},
}

for name, test := range table {
Expand Down