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
}
}
// The container logs live on the node rootfs device
result
.
Logs
=
&
statsapi
.
FsStats
{
Time
:
metav1
.
NewTime
(
cstat
.
Timestamp
),
AvailableBytes
:
&
rootFs
.
Available
,
CapacityBytes
:
&
rootFs
.
Capacity
,
InodesFree
:
rootFs
.
InodesFree
,
Inodes
:
rootFs
.
Inodes
,
}
if
rootFs
!=
nil
{
// The container logs live on the node rootfs device
result
.
Logs
=
&
statsapi
.
FsStats
{
Time
:
metav1
.
NewTime
(
cstat
.
Timestamp
),
AvailableBytes
:
&
rootFs
.
Available
,
CapacityBytes
:
&
rootFs
.
Capacity
,
InodesFree
:
rootFs
.
InodesFree
,
Inodes
:
rootFs
.
Inodes
,
}
if
rootFs
.
Inodes
!=
nil
&&
rootFs
.
InodesFree
!=
nil
{
logsInodesUsed
:=
*
rootFs
.
Inodes
-
*
rootFs
.
InodesFree
result
.
Logs
.
InodesUsed
=
&
logsInodesUsed
if
rootFs
.
Inodes
!=
nil
&&
rootFs
.
InodesFree
!=
nil
{
logsInodesUsed
:=
*
rootFs
.
Inodes
-
*
rootFs
.
InodesFree
result
.
Logs
.
InodesUsed
=
&
logsInodesUsed
}
}
// The container rootFs lives on the imageFs devices (which may not be the node root fs)
result
.
Rootfs
=
&
statsapi
.
FsStats
{
Time
:
metav1
.
NewTime
(
cstat
.
Timestamp
),
AvailableBytes
:
&
imageFs
.
Available
,
CapacityBytes
:
&
imageFs
.
Capacity
,
InodesFree
:
imageFs
.
InodesFree
,
Inodes
:
imageFs
.
Inodes
,
if
imageFs
!=
nil
{
// The container rootFs lives on the imageFs devices (which may not be the node root fs)
result
.
Rootfs
=
&
statsapi
.
FsStats
{
Time
:
metav1
.
NewTime
(
cstat
.
Timestamp
),
AvailableBytes
:
&
imageFs
.
Available
,
CapacityBytes
:
&
imageFs
.
Capacity
,
InodesFree
:
imageFs
.
InodesFree
,
Inodes
:
imageFs
.
Inodes
,
}
}
cfs
:=
cstat
.
Filesystem
if
cfs
!=
nil
{
if
cfs
.
BaseUsageBytes
!=
nil
{
rootfsUsage
:=
*
cfs
.
BaseUsageBytes
result
.
Rootfs
.
UsedBytes
=
&
rootfsUsage
if
cfs
.
TotalUsageBytes
!=
nil
{
if
result
.
Rootfs
!=
nil
{
rootfsUsage
:=
*
cfs
.
BaseUsageBytes
result
.
Rootfs
.
UsedBytes
=
&
rootfsUsage
}
if
cfs
.
TotalUsageBytes
!=
nil
&&
result
.
Logs
!=
nil
{
logsUsage
:=
*
cfs
.
TotalUsageBytes
-
*
cfs
.
BaseUsageBytes
result
.
Logs
.
UsedBytes
=
&
logsUsage
}
}
if
cfs
.
InodeUsage
!=
nil
{
if
cfs
.
InodeUsage
!=
nil
&&
result
.
Rootfs
!=
nil
{
rootInodes
:=
*
cfs
.
InodeUsage
result
.
Rootfs
.
InodesUsed
=
&
rootInodes
}
}
result
.
UserDefinedMetrics
=
cadvisorInfoToUserDefinedMetrics
(
info
)
return
result
}
...
...
pkg/kubelet/stats/stats_provider.go
View file @
f6be1388
...
...
@@ -86,21 +86,15 @@ type containerStatsProvider interface {
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
)
{
info
,
err
:=
getCgroupInfo
(
p
.
cadvisor
,
cgroupName
)
if
err
!=
nil
{
return
nil
,
nil
,
fmt
.
Errorf
(
"failed to get cgroup stats for %q: %v"
,
cgroupName
,
err
)
}
rootFsInfo
,
err
:=
p
.
cadvisor
.
RootFsInfo
()
if
err
!=
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
)
// Rootfs and imagefs doesn't make sense for raw cgroup.
s
:=
cadvisorInfoToContainerStats
(
cgroupName
,
info
,
nil
,
nil
)
n
:=
cadvisorInfoToNetworkStats
(
cgroupName
,
info
)
return
s
,
n
,
nil
}
...
...
pkg/kubelet/stats/stats_provider_test.go
View file @
f6be1388
...
...
@@ -69,9 +69,7 @@ var (
func
TestGetCgroupStats
(
t
*
testing
.
T
)
{
const
(
cgroupName
=
"test-cgroup-name"
rootFsInfoSeed
=
1000
imageFsInfoSeed
=
2000
containerInfoSeed
=
3000
containerInfoSeed
=
1000
)
var
(
mockCadvisor
=
new
(
cadvisortest
.
Mock
)
...
...
@@ -81,16 +79,11 @@ func TestGetCgroupStats(t *testing.T) {
assert
=
assert
.
New
(
t
)
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"
)
containerInfoMap
=
map
[
string
]
cadvisorapiv2
.
ContainerInfo
{
cgroupName
:
containerInfo
}
)
mockCadvisor
.
On
(
"RootFsInfo"
)
.
Return
(
rootFsInfo
,
nil
)
.
On
(
"ImagesFsInfo"
)
.
Return
(
imageFsInfo
,
nil
)
.
On
(
"ContainerInfoV2"
,
cgroupName
,
options
)
.
Return
(
containerInfoMap
,
nil
)
mockCadvisor
.
On
(
"ContainerInfoV2"
,
cgroupName
,
options
)
.
Return
(
containerInfoMap
,
nil
)
provider
:=
newStatsProvider
(
mockCadvisor
,
mockPodManager
,
mockRuntimeCache
,
fakeContainerStatsProvider
{})
cs
,
ns
,
err
:=
provider
.
GetCgroupStats
(
cgroupName
)
...
...
@@ -98,21 +91,11 @@ func TestGetCgroupStats(t *testing.T) {
checkCPUStats
(
t
,
""
,
containerInfoSeed
,
cs
.
CPU
)
checkMemoryStats
(
t
,
""
,
containerInfoSeed
,
containerInfo
,
cs
.
Memory
)
checkFsStats
(
t
,
""
,
imageFsInfoSeed
,
cs
.
Rootfs
)
checkFsStats
(
t
,
""
,
rootFsInfoSeed
,
cs
.
Logs
)
checkNetworkStats
(
t
,
""
,
containerInfoSeed
,
ns
)
assert
.
Equal
(
cgroupName
,
cs
.
Name
)
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
)
}
...
...
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