From 256369671925d4dcc1b1c3512a0db095466d700d Mon Sep 17 00:00:00 2001 From: derekwaynecarr Date: Mon, 8 Aug 2016 12:20:14 -0400 Subject: [PATCH] Add total inodes to kubelet summary api --- pkg/kubelet/api/v1alpha1/stats/types.go | 2 ++ pkg/kubelet/server/stats/summary.go | 6 +++++- pkg/kubelet/server/stats/summary_test.go | 13 ++++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pkg/kubelet/api/v1alpha1/stats/types.go b/pkg/kubelet/api/v1alpha1/stats/types.go index bded04bf045..aa283666463 100644 --- a/pkg/kubelet/api/v1alpha1/stats/types.go +++ b/pkg/kubelet/api/v1alpha1/stats/types.go @@ -175,6 +175,8 @@ type FsStats struct { UsedBytes *uint64 `json:"usedBytes,omitempty"` // InodesFree represents the free inodes in the filesystem. InodesFree *uint64 `json:"inodesFree,omitempty"` + // Inodes represents the total inodes in the filesystem. + Inodes *uint64 `json:"inodes,omitempty"` } // UserDefinedMetricType defines how the metric should be interpreted by the user. diff --git a/pkg/kubelet/server/stats/summary.go b/pkg/kubelet/server/stats/summary.go index 0c8701b7303..16bee64c724 100644 --- a/pkg/kubelet/server/stats/summary.go +++ b/pkg/kubelet/server/stats/summary.go @@ -125,7 +125,8 @@ func (sb *summaryBuilder) build() (*stats.Summary, error) { AvailableBytes: &sb.rootFsInfo.Available, CapacityBytes: &sb.rootFsInfo.Capacity, UsedBytes: &sb.rootFsInfo.Usage, - InodesFree: sb.rootFsInfo.InodesFree}, + InodesFree: sb.rootFsInfo.InodesFree, + Inodes: sb.rootFsInfo.Inodes}, StartTime: rootStats.StartTime, Runtime: &stats.RuntimeStats{ ImageFs: &stats.FsStats{ @@ -133,6 +134,7 @@ func (sb *summaryBuilder) build() (*stats.Summary, error) { CapacityBytes: &sb.imageFsInfo.Capacity, UsedBytes: &sb.imageStats.TotalStorageBytes, InodesFree: sb.imageFsInfo.InodesFree, + Inodes: sb.rootFsInfo.Inodes, }, }, } @@ -165,6 +167,7 @@ func (sb *summaryBuilder) containerInfoV2FsStats( AvailableBytes: &sb.rootFsInfo.Available, CapacityBytes: &sb.rootFsInfo.Capacity, InodesFree: sb.rootFsInfo.InodesFree, + Inodes: sb.rootFsInfo.Inodes, } // The container rootFs lives on the imageFs devices (which may not be the node root fs) @@ -172,6 +175,7 @@ func (sb *summaryBuilder) containerInfoV2FsStats( AvailableBytes: &sb.imageFsInfo.Available, CapacityBytes: &sb.imageFsInfo.Capacity, InodesFree: sb.imageFsInfo.InodesFree, + Inodes: sb.imageFsInfo.Inodes, } lcs, found := sb.latestContainerStats(info) if !found { diff --git a/pkg/kubelet/server/stats/summary_test.go b/pkg/kubelet/server/stats/summary_test.go index d89caa3b180..b6d5da19228 100644 --- a/pkg/kubelet/server/stats/summary_test.go +++ b/pkg/kubelet/server/stats/summary_test.go @@ -93,9 +93,11 @@ func TestBuildSummary(t *testing.T) { rootfsCapacity = uint64(10000000) rootfsAvailable = uint64(5000000) rootfsInodesFree = uint64(1000) + rootfsInodes = uint64(2000) imagefsCapacity = uint64(20000000) imagefsAvailable = uint64(8000000) imagefsInodesFree = uint64(2000) + imagefsInodes = uint64(4000) ) prf0 := kubestats.PodReference{Name: pName0, Namespace: namespace0, UID: "UID" + pName0} @@ -119,16 +121,20 @@ func TestBuildSummary(t *testing.T) { } freeRootfsInodes := rootfsInodesFree + totalRootfsInodes := rootfsInodes rootfs := v2.FsInfo{ Capacity: rootfsCapacity, Available: rootfsAvailable, InodesFree: &freeRootfsInodes, + Inodes: &totalRootfsInodes, } freeImagefsInodes := imagefsInodesFree + totalImagefsInodes := imagefsInodes imagefs := v2.FsInfo{ Capacity: imagefsCapacity, Available: imagefsAvailable, InodesFree: &freeImagefsInodes, + Inodes: &totalImagefsInodes, } // memory limit overrides for each container (used to test available bytes if a memory limit is known) @@ -177,8 +183,8 @@ func TestBuildSummary(t *testing.T) { assert.EqualValues(t, testTime(creationTime, seed).Unix(), sys.StartTime.Time.Unix(), name+".StartTime") checkCPUStats(t, name, seed, sys.CPU) checkMemoryStats(t, name, seed, info, sys.Memory) - checkFsStats(t, rootfsCapacity, rootfsAvailable, rootfsInodesFree, sys.Logs) - checkFsStats(t, imagefsCapacity, imagefsAvailable, imagefsInodesFree, sys.Rootfs) + checkFsStats(t, rootfsCapacity, rootfsAvailable, totalRootfsInodes, rootfsInodesFree, sys.Logs) + checkFsStats(t, imagefsCapacity, imagefsAvailable, totalImagefsInodes, imagefsInodesFree, sys.Rootfs) } assert.Equal(t, 3, len(summary.Pods)) @@ -370,10 +376,11 @@ func checkMemoryStats(t *testing.T, label string, seed int, info v2.ContainerInf } } -func checkFsStats(t *testing.T, capacity uint64, Available uint64, inodesFree uint64, fs *kubestats.FsStats) { +func checkFsStats(t *testing.T, capacity uint64, Available uint64, inodes uint64, inodesFree uint64, fs *kubestats.FsStats) { assert.EqualValues(t, capacity, *fs.CapacityBytes) assert.EqualValues(t, Available, *fs.AvailableBytes) assert.EqualValues(t, inodesFree, *fs.InodesFree) + assert.EqualValues(t, inodes, *fs.Inodes) } func TestCustomMetrics(t *testing.T) {