Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
f6be1388
Commit
f6be1388
authored
Sep 29, 2017
by
Lantao Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix imagefs stats.
parent
751bcc47
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
51 deletions
+35
-51
helper.go
pkg/kubelet/stats/helper.go
+29
-22
stats_provider.go
pkg/kubelet/stats/stats_provider.go
+4
-10
stats_provider_test.go
pkg/kubelet/stats/stats_provider_test.go
+2
-19
No files found.
pkg/kubelet/stats/helper.go
View file @
f6be1388
...
@@ -74,46 +74,53 @@ func cadvisorInfoToContainerStats(name string, info *cadvisorapiv2.ContainerInfo
...
@@ -74,46 +74,53 @@ func cadvisorInfoToContainerStats(name string, info *cadvisorapiv2.ContainerInfo
}
}
}
}
// The container logs live on the node rootfs device
if
rootFs
!=
nil
{
result
.
Logs
=
&
statsapi
.
FsStats
{
// The container logs live on the node rootfs device
Time
:
metav1
.
NewTime
(
cstat
.
Timestamp
),
result
.
Logs
=
&
statsapi
.
FsStats
{
AvailableBytes
:
&
rootFs
.
Available
,
Time
:
metav1
.
NewTime
(
cstat
.
Timestamp
),
CapacityBytes
:
&
rootFs
.
Capacity
,
AvailableBytes
:
&
rootFs
.
Available
,
InodesFree
:
rootFs
.
InodesFree
,
CapacityBytes
:
&
rootFs
.
Capacity
,
Inodes
:
rootFs
.
Inodes
,
InodesFree
:
rootFs
.
InodesFree
,
}
Inodes
:
rootFs
.
Inodes
,
}
if
rootFs
.
Inodes
!=
nil
&&
rootFs
.
InodesFree
!=
nil
{
if
rootFs
.
Inodes
!=
nil
&&
rootFs
.
InodesFree
!=
nil
{
logsInodesUsed
:=
*
rootFs
.
Inodes
-
*
rootFs
.
InodesFree
logsInodesUsed
:=
*
rootFs
.
Inodes
-
*
rootFs
.
InodesFree
result
.
Logs
.
InodesUsed
=
&
logsInodesUsed
result
.
Logs
.
InodesUsed
=
&
logsInodesUsed
}
}
}
// The container rootFs lives on the imageFs devices (which may not be the node root fs)
if
imageFs
!=
nil
{
result
.
Rootfs
=
&
statsapi
.
FsStats
{
// The container rootFs lives on the imageFs devices (which may not be the node root fs)
Time
:
metav1
.
NewTime
(
cstat
.
Timestamp
),
result
.
Rootfs
=
&
statsapi
.
FsStats
{
AvailableBytes
:
&
imageFs
.
Available
,
Time
:
metav1
.
NewTime
(
cstat
.
Timestamp
),
CapacityBytes
:
&
imageFs
.
Capacity
,
AvailableBytes
:
&
imageFs
.
Available
,
InodesFree
:
imageFs
.
InodesFree
,
CapacityBytes
:
&
imageFs
.
Capacity
,
Inodes
:
imageFs
.
Inodes
,
InodesFree
:
imageFs
.
InodesFree
,
Inodes
:
imageFs
.
Inodes
,
}
}
}
cfs
:=
cstat
.
Filesystem
cfs
:=
cstat
.
Filesystem
if
cfs
!=
nil
{
if
cfs
!=
nil
{
if
cfs
.
BaseUsageBytes
!=
nil
{
if
cfs
.
BaseUsageBytes
!=
nil
{
rootfsUsage
:=
*
cfs
.
BaseUsageBytes
if
result
.
Rootfs
!=
nil
{
result
.
Rootfs
.
UsedBytes
=
&
rootfsUsage
rootfsUsage
:=
*
cfs
.
BaseUsageBytes
if
cfs
.
TotalUsageBytes
!=
nil
{
result
.
Rootfs
.
UsedBytes
=
&
rootfsUsage
}
if
cfs
.
TotalUsageBytes
!=
nil
&&
result
.
Logs
!=
nil
{
logsUsage
:=
*
cfs
.
TotalUsageBytes
-
*
cfs
.
BaseUsageBytes
logsUsage
:=
*
cfs
.
TotalUsageBytes
-
*
cfs
.
BaseUsageBytes
result
.
Logs
.
UsedBytes
=
&
logsUsage
result
.
Logs
.
UsedBytes
=
&
logsUsage
}
}
}
}
if
cfs
.
InodeUsage
!=
nil
{
if
cfs
.
InodeUsage
!=
nil
&&
result
.
Rootfs
!=
nil
{
rootInodes
:=
*
cfs
.
InodeUsage
rootInodes
:=
*
cfs
.
InodeUsage
result
.
Rootfs
.
InodesUsed
=
&
rootInodes
result
.
Rootfs
.
InodesUsed
=
&
rootInodes
}
}
}
}
result
.
UserDefinedMetrics
=
cadvisorInfoToUserDefinedMetrics
(
info
)
result
.
UserDefinedMetrics
=
cadvisorInfoToUserDefinedMetrics
(
info
)
return
result
return
result
}
}
...
...
pkg/kubelet/stats/stats_provider.go
View file @
f6be1388
...
@@ -86,21 +86,15 @@ type containerStatsProvider interface {
...
@@ -86,21 +86,15 @@ type containerStatsProvider interface {
ImageFsStats
()
(
*
statsapi
.
FsStats
,
error
)
ImageFsStats
()
(
*
statsapi
.
FsStats
,
error
)
}
}
// GetCgroupStats returns the stats of the cgroup with the cgroupName.
// GetCgroupStats returns the stats of the cgroup with the cgroupName. Note that
// this function doesn't generate filesystem stats.
func
(
p
*
StatsProvider
)
GetCgroupStats
(
cgroupName
string
)
(
*
statsapi
.
ContainerStats
,
*
statsapi
.
NetworkStats
,
error
)
{
func
(
p
*
StatsProvider
)
GetCgroupStats
(
cgroupName
string
)
(
*
statsapi
.
ContainerStats
,
*
statsapi
.
NetworkStats
,
error
)
{
info
,
err
:=
getCgroupInfo
(
p
.
cadvisor
,
cgroupName
)
info
,
err
:=
getCgroupInfo
(
p
.
cadvisor
,
cgroupName
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
fmt
.
Errorf
(
"failed to get cgroup stats for %q: %v"
,
cgroupName
,
err
)
return
nil
,
nil
,
fmt
.
Errorf
(
"failed to get cgroup stats for %q: %v"
,
cgroupName
,
err
)
}
}
rootFsInfo
,
err
:=
p
.
cadvisor
.
RootFsInfo
()
// Rootfs and imagefs doesn't make sense for raw cgroup.
if
err
!=
nil
{
s
:=
cadvisorInfoToContainerStats
(
cgroupName
,
info
,
nil
,
nil
)
return
nil
,
nil
,
fmt
.
Errorf
(
"failed to get rootFs info: %v"
,
err
)
}
imageFsInfo
,
err
:=
p
.
cadvisor
.
ImagesFsInfo
()
if
err
!=
nil
{
return
nil
,
nil
,
fmt
.
Errorf
(
"failed to get imageFs info: %v"
,
err
)
}
s
:=
cadvisorInfoToContainerStats
(
cgroupName
,
info
,
&
rootFsInfo
,
&
imageFsInfo
)
n
:=
cadvisorInfoToNetworkStats
(
cgroupName
,
info
)
n
:=
cadvisorInfoToNetworkStats
(
cgroupName
,
info
)
return
s
,
n
,
nil
return
s
,
n
,
nil
}
}
...
...
pkg/kubelet/stats/stats_provider_test.go
View file @
f6be1388
...
@@ -69,9 +69,7 @@ var (
...
@@ -69,9 +69,7 @@ var (
func
TestGetCgroupStats
(
t
*
testing
.
T
)
{
func
TestGetCgroupStats
(
t
*
testing
.
T
)
{
const
(
const
(
cgroupName
=
"test-cgroup-name"
cgroupName
=
"test-cgroup-name"
rootFsInfoSeed
=
1000
containerInfoSeed
=
1000
imageFsInfoSeed
=
2000
containerInfoSeed
=
3000
)
)
var
(
var
(
mockCadvisor
=
new
(
cadvisortest
.
Mock
)
mockCadvisor
=
new
(
cadvisortest
.
Mock
)
...
@@ -81,16 +79,11 @@ func TestGetCgroupStats(t *testing.T) {
...
@@ -81,16 +79,11 @@ func TestGetCgroupStats(t *testing.T) {
assert
=
assert
.
New
(
t
)
assert
=
assert
.
New
(
t
)
options
=
cadvisorapiv2
.
RequestOptions
{
IdType
:
cadvisorapiv2
.
TypeName
,
Count
:
2
,
Recursive
:
false
}
options
=
cadvisorapiv2
.
RequestOptions
{
IdType
:
cadvisorapiv2
.
TypeName
,
Count
:
2
,
Recursive
:
false
}
rootFsInfo
=
getTestFsInfo
(
rootFsInfoSeed
)
imageFsInfo
=
getTestFsInfo
(
imageFsInfoSeed
)
containerInfo
=
getTestContainerInfo
(
containerInfoSeed
,
"test-pod"
,
"test-ns"
,
"test-container"
)
containerInfo
=
getTestContainerInfo
(
containerInfoSeed
,
"test-pod"
,
"test-ns"
,
"test-container"
)
containerInfoMap
=
map
[
string
]
cadvisorapiv2
.
ContainerInfo
{
cgroupName
:
containerInfo
}
containerInfoMap
=
map
[
string
]
cadvisorapiv2
.
ContainerInfo
{
cgroupName
:
containerInfo
}
)
)
mockCadvisor
.
mockCadvisor
.
On
(
"ContainerInfoV2"
,
cgroupName
,
options
)
.
Return
(
containerInfoMap
,
nil
)
On
(
"RootFsInfo"
)
.
Return
(
rootFsInfo
,
nil
)
.
On
(
"ImagesFsInfo"
)
.
Return
(
imageFsInfo
,
nil
)
.
On
(
"ContainerInfoV2"
,
cgroupName
,
options
)
.
Return
(
containerInfoMap
,
nil
)
provider
:=
newStatsProvider
(
mockCadvisor
,
mockPodManager
,
mockRuntimeCache
,
fakeContainerStatsProvider
{})
provider
:=
newStatsProvider
(
mockCadvisor
,
mockPodManager
,
mockRuntimeCache
,
fakeContainerStatsProvider
{})
cs
,
ns
,
err
:=
provider
.
GetCgroupStats
(
cgroupName
)
cs
,
ns
,
err
:=
provider
.
GetCgroupStats
(
cgroupName
)
...
@@ -98,21 +91,11 @@ func TestGetCgroupStats(t *testing.T) {
...
@@ -98,21 +91,11 @@ func TestGetCgroupStats(t *testing.T) {
checkCPUStats
(
t
,
""
,
containerInfoSeed
,
cs
.
CPU
)
checkCPUStats
(
t
,
""
,
containerInfoSeed
,
cs
.
CPU
)
checkMemoryStats
(
t
,
""
,
containerInfoSeed
,
containerInfo
,
cs
.
Memory
)
checkMemoryStats
(
t
,
""
,
containerInfoSeed
,
containerInfo
,
cs
.
Memory
)
checkFsStats
(
t
,
""
,
imageFsInfoSeed
,
cs
.
Rootfs
)
checkFsStats
(
t
,
""
,
rootFsInfoSeed
,
cs
.
Logs
)
checkNetworkStats
(
t
,
""
,
containerInfoSeed
,
ns
)
checkNetworkStats
(
t
,
""
,
containerInfoSeed
,
ns
)
assert
.
Equal
(
cgroupName
,
cs
.
Name
)
assert
.
Equal
(
cgroupName
,
cs
.
Name
)
assert
.
Equal
(
metav1
.
NewTime
(
containerInfo
.
Spec
.
CreationTime
),
cs
.
StartTime
)
assert
.
Equal
(
metav1
.
NewTime
(
containerInfo
.
Spec
.
CreationTime
),
cs
.
StartTime
)
assert
.
Equal
(
metav1
.
NewTime
(
containerInfo
.
Stats
[
0
]
.
Timestamp
),
cs
.
Rootfs
.
Time
)
assert
.
Equal
(
*
containerInfo
.
Stats
[
0
]
.
Filesystem
.
BaseUsageBytes
,
*
cs
.
Rootfs
.
UsedBytes
)
assert
.
Equal
(
*
containerInfo
.
Stats
[
0
]
.
Filesystem
.
InodeUsage
,
*
cs
.
Rootfs
.
InodesUsed
)
assert
.
Equal
(
metav1
.
NewTime
(
containerInfo
.
Stats
[
0
]
.
Timestamp
),
cs
.
Logs
.
Time
)
assert
.
Equal
(
*
containerInfo
.
Stats
[
0
]
.
Filesystem
.
TotalUsageBytes
-*
containerInfo
.
Stats
[
0
]
.
Filesystem
.
BaseUsageBytes
,
*
cs
.
Logs
.
UsedBytes
)
assert
.
Equal
(
*
rootFsInfo
.
Inodes
-*
rootFsInfo
.
InodesFree
,
*
cs
.
Logs
.
InodesUsed
)
mockCadvisor
.
AssertExpectations
(
t
)
mockCadvisor
.
AssertExpectations
(
t
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment