Skip to content
Open
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
4 changes: 2 additions & 2 deletions lib/diskutilization/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ Concretely, the collector reads filesystem metadata and uses the allocated block

Snapshots are classified by the memory artifact present in `snapshot-latest`:

- `snapshot_compressed` for compressed memory files such as `memory-ranges.zst` or `memory-ranges.lz4`
- `snapshot_uncompressed` for raw `memory-ranges`
- `snapshot_compressed` for compressed memory files such as `memory-ranges.zst`, `memory-ranges.lz4`, `memory.zst`, or `memory.lz4`
- `snapshot_uncompressed` for raw `memory-ranges` or `memory`
- `snapshot_other` when a snapshot directory exists but does not match a recognized memory artifact shape

The full `snapshot-latest` directory is counted once under its classified snapshot component so the metric includes related config and state files, not just the memory artifact itself.
Expand Down
6 changes: 6 additions & 0 deletions lib/diskutilization/diskutilization.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,16 @@ func classifySnapshotDir(snapshotDir string) (component string, exists bool, err
switch {
case pathExists(filepath.Join(snapshotDir, "memory-ranges.zst")):
return ComponentSnapshotCompressed, true, nil
case pathExists(filepath.Join(snapshotDir, "memory.zst")):
return ComponentSnapshotCompressed, true, nil
case pathExists(filepath.Join(snapshotDir, "memory-ranges.lz4")):
return ComponentSnapshotCompressed, true, nil
case pathExists(filepath.Join(snapshotDir, "memory.lz4")):
return ComponentSnapshotCompressed, true, nil
case pathExists(filepath.Join(snapshotDir, "memory-ranges")):
return ComponentSnapshotUncompressed, true, nil
case pathExists(filepath.Join(snapshotDir, "memory")):
return ComponentSnapshotUncompressed, true, nil
default:
return ComponentSnapshotOther, true, nil
}
Expand Down
22 changes: 19 additions & 3 deletions lib/diskutilization/diskutilization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,19 @@ func TestCollect_UsesAllocatedBytesAndClassifiesSnapshots(t *testing.T) {
}))
require.NoError(t, os.WriteFile(filepath.Join(compressedSnapshotDir, "config.json"), []byte(`{}`), 0644))

otherSnapshotDir := p.InstanceSnapshotLatest("inst-3")
firecrackerUncompressedSnapshotDir := p.InstanceSnapshotLatest("inst-3")
require.NoError(t, createSparseTestFile(filepath.Join(firecrackerUncompressedSnapshotDir, "memory"), 48*1024*1024, []sparseWrite{
{offset: 0, data: bytes.Repeat([]byte("f"), 4096)},
}))
require.NoError(t, os.WriteFile(filepath.Join(firecrackerUncompressedSnapshotDir, "config.json"), []byte(`{}`), 0644))

firecrackerCompressedSnapshotDir := p.InstanceSnapshotLatest("inst-4")
require.NoError(t, createSparseTestFile(filepath.Join(firecrackerCompressedSnapshotDir, "memory.zst"), 24*1024*1024, []sparseWrite{
{offset: 0, data: bytes.Repeat([]byte("z"), 4096)},
}))
require.NoError(t, os.WriteFile(filepath.Join(firecrackerCompressedSnapshotDir, "config.json"), []byte(`{}`), 0644))

otherSnapshotDir := p.InstanceSnapshotLatest("inst-5")
require.NoError(t, os.MkdirAll(otherSnapshotDir, 0755))
require.NoError(t, os.WriteFile(filepath.Join(otherSnapshotDir, "config.json"), []byte(`{}`), 0644))

Expand All @@ -72,13 +84,17 @@ func TestCollect_UsesAllocatedBytesAndClassifiesSnapshots(t *testing.T) {

uncompressedTotal, err := sumTreeAllocatedBytes(uncompressedSnapshotDir)
require.NoError(t, err)
firecrackerUncompressedTotal, err := sumTreeAllocatedBytes(firecrackerUncompressedSnapshotDir)
require.NoError(t, err)
compressedTotal, err := sumTreeAllocatedBytes(compressedSnapshotDir)
require.NoError(t, err)
firecrackerCompressedTotal, err := sumTreeAllocatedBytes(firecrackerCompressedSnapshotDir)
require.NoError(t, err)
otherTotal, err := sumTreeAllocatedBytes(otherSnapshotDir)
require.NoError(t, err)

require.Equal(t, uncompressedTotal, utilization.SnapshotUncompressed)
require.Equal(t, compressedTotal, utilization.SnapshotCompressed)
require.Equal(t, uncompressedTotal+firecrackerUncompressedTotal, utilization.SnapshotUncompressed)
require.Equal(t, compressedTotal+firecrackerCompressedTotal, utilization.SnapshotCompressed)
require.Equal(t, otherTotal, utilization.SnapshotOther)
}

Expand Down
2 changes: 1 addition & 1 deletion lib/resources/monitoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func TestStartMonitoringPublishesDiskUtilizationFromCachedSnapshot(t *testing.T)
{offset: 0, data: bytes.Repeat([]byte("o"), 4096)},
}))
snapshotDir := mgr.paths.InstanceSnapshotLatest("vm-1")
require.NoError(t, createMonitoringSparseTestFile(filepath.Join(snapshotDir, "memory-ranges.zst"), 32*1024*1024, []monitoringSparseWrite{
require.NoError(t, createMonitoringSparseTestFile(filepath.Join(snapshotDir, "memory.zst"), 32*1024*1024, []monitoringSparseWrite{
{offset: 0, data: bytes.Repeat([]byte("s"), 4096)},
}))
require.NoError(t, os.WriteFile(filepath.Join(snapshotDir, "config.json"), []byte(`{}`), 0644))
Expand Down
Loading