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
4f01eb52
Unverified
Commit
4f01eb52
authored
Feb 28, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Feb 28, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #74336 from littleroad/exited_container
cri_stats_provider: Implement removeTerminatedContainer correctly
parents
9fd7a4c2
3f8eda37
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
8 deletions
+67
-8
cri_stats_provider.go
pkg/kubelet/stats/cri_stats_provider.go
+15
-0
cri_stats_provider_test.go
pkg/kubelet/stats/cri_stats_provider_test.go
+48
-8
helper.go
pkg/kubelet/stats/helper.go
+4
-0
No files found.
pkg/kubelet/stats/cri_stats_provider.go
View file @
4f01eb52
...
@@ -455,12 +455,19 @@ func (p *criStatsProvider) makeContainerStats(
...
@@ -455,12 +455,19 @@ func (p *criStatsProvider) makeContainerStats(
if
usageNanoCores
!=
nil
{
if
usageNanoCores
!=
nil
{
result
.
CPU
.
UsageNanoCores
=
usageNanoCores
result
.
CPU
.
UsageNanoCores
=
usageNanoCores
}
}
}
else
{
result
.
CPU
.
Time
=
metav1
.
NewTime
(
time
.
Unix
(
0
,
time
.
Now
()
.
UnixNano
()))
result
.
CPU
.
UsageCoreNanoSeconds
=
Uint64Ptr
(
0
)
result
.
CPU
.
UsageNanoCores
=
Uint64Ptr
(
0
)
}
}
if
stats
.
Memory
!=
nil
{
if
stats
.
Memory
!=
nil
{
result
.
Memory
.
Time
=
metav1
.
NewTime
(
time
.
Unix
(
0
,
stats
.
Memory
.
Timestamp
))
result
.
Memory
.
Time
=
metav1
.
NewTime
(
time
.
Unix
(
0
,
stats
.
Memory
.
Timestamp
))
if
stats
.
Memory
.
WorkingSetBytes
!=
nil
{
if
stats
.
Memory
.
WorkingSetBytes
!=
nil
{
result
.
Memory
.
WorkingSetBytes
=
&
stats
.
Memory
.
WorkingSetBytes
.
Value
result
.
Memory
.
WorkingSetBytes
=
&
stats
.
Memory
.
WorkingSetBytes
.
Value
}
}
}
else
{
result
.
Memory
.
Time
=
metav1
.
NewTime
(
time
.
Unix
(
0
,
time
.
Now
()
.
UnixNano
()))
result
.
Memory
.
WorkingSetBytes
=
Uint64Ptr
(
0
)
}
}
if
stats
.
WritableLayer
!=
nil
{
if
stats
.
WritableLayer
!=
nil
{
result
.
Rootfs
.
Time
=
metav1
.
NewTime
(
time
.
Unix
(
0
,
stats
.
WritableLayer
.
Timestamp
))
result
.
Rootfs
.
Time
=
metav1
.
NewTime
(
time
.
Unix
(
0
,
stats
.
WritableLayer
.
Timestamp
))
...
@@ -516,13 +523,21 @@ func (p *criStatsProvider) makeContainerCPUAndMemoryStats(
...
@@ -516,13 +523,21 @@ func (p *criStatsProvider) makeContainerCPUAndMemoryStats(
if
usageNanoCores
!=
nil
{
if
usageNanoCores
!=
nil
{
result
.
CPU
.
UsageNanoCores
=
usageNanoCores
result
.
CPU
.
UsageNanoCores
=
usageNanoCores
}
}
}
else
{
result
.
CPU
.
Time
=
metav1
.
NewTime
(
time
.
Unix
(
0
,
time
.
Now
()
.
UnixNano
()))
result
.
CPU
.
UsageCoreNanoSeconds
=
Uint64Ptr
(
0
)
result
.
CPU
.
UsageNanoCores
=
Uint64Ptr
(
0
)
}
}
if
stats
.
Memory
!=
nil
{
if
stats
.
Memory
!=
nil
{
result
.
Memory
.
Time
=
metav1
.
NewTime
(
time
.
Unix
(
0
,
stats
.
Memory
.
Timestamp
))
result
.
Memory
.
Time
=
metav1
.
NewTime
(
time
.
Unix
(
0
,
stats
.
Memory
.
Timestamp
))
if
stats
.
Memory
.
WorkingSetBytes
!=
nil
{
if
stats
.
Memory
.
WorkingSetBytes
!=
nil
{
result
.
Memory
.
WorkingSetBytes
=
&
stats
.
Memory
.
WorkingSetBytes
.
Value
result
.
Memory
.
WorkingSetBytes
=
&
stats
.
Memory
.
WorkingSetBytes
.
Value
}
}
}
else
{
result
.
Memory
.
Time
=
metav1
.
NewTime
(
time
.
Unix
(
0
,
time
.
Now
()
.
UnixNano
()))
result
.
Memory
.
WorkingSetBytes
=
Uint64Ptr
(
0
)
}
}
return
result
return
result
}
}
...
...
pkg/kubelet/stats/cri_stats_provider_test.go
View file @
4f01eb52
...
@@ -57,12 +57,15 @@ const (
...
@@ -57,12 +57,15 @@ const (
seedContainer2
=
5000
seedContainer2
=
5000
seedSandbox2
=
6000
seedSandbox2
=
6000
seedContainer3
=
7000
seedContainer3
=
7000
seedSandbox3
=
8000
seedContainer5
=
9000
)
)
const
(
const
(
pName0
=
"pod0"
pName0
=
"pod0"
pName1
=
"pod1"
pName1
=
"pod1"
pName2
=
"pod2"
pName2
=
"pod2"
pName3
=
"pod3"
)
)
const
(
const
(
...
@@ -70,6 +73,7 @@ const (
...
@@ -70,6 +73,7 @@ const (
cName1
=
"container1-name"
cName1
=
"container1-name"
cName2
=
"container2-name"
cName2
=
"container2-name"
cName3
=
"container3-name"
cName3
=
"container3-name"
cName5
=
"container5-name"
)
)
func
TestCRIListPodStats
(
t
*
testing
.
T
)
{
func
TestCRIListPodStats
(
t
*
testing
.
T
)
{
...
@@ -101,6 +105,11 @@ func TestCRIListPodStats(t *testing.T) {
...
@@ -101,6 +105,11 @@ func TestCRIListPodStats(t *testing.T) {
container4
=
makeFakeContainer
(
sandbox2
,
cName3
,
1
,
false
)
container4
=
makeFakeContainer
(
sandbox2
,
cName3
,
1
,
false
)
containerStats4
=
makeFakeContainerStats
(
container4
,
imageFsMountpoint
)
containerStats4
=
makeFakeContainerStats
(
container4
,
imageFsMountpoint
)
containerLogStats4
=
makeFakeLogStats
(
4000
)
containerLogStats4
=
makeFakeLogStats
(
4000
)
sandbox3
=
makeFakePodSandbox
(
"sandbox3-name"
,
"sandbox3-uid"
,
"sandbox3-ns"
)
container5
=
makeFakeContainer
(
sandbox3
,
cName5
,
0
,
true
)
containerStats5
=
makeFakeContainerStats
(
container5
,
imageFsMountpoint
)
containerLogStats5
=
makeFakeLogStats
(
5000
)
)
)
var
(
var
(
...
@@ -140,13 +149,13 @@ func TestCRIListPodStats(t *testing.T) {
...
@@ -140,13 +149,13 @@ func TestCRIListPodStats(t *testing.T) {
On
(
"GetDirFsInfo"
,
imageFsMountpoint
)
.
Return
(
imageFsInfo
,
nil
)
.
On
(
"GetDirFsInfo"
,
imageFsMountpoint
)
.
Return
(
imageFsInfo
,
nil
)
.
On
(
"GetDirFsInfo"
,
unknownMountpoint
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
cadvisorfs
.
ErrNoSuchDevice
)
On
(
"GetDirFsInfo"
,
unknownMountpoint
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
cadvisorfs
.
ErrNoSuchDevice
)
fakeRuntimeService
.
SetFakeSandboxes
([]
*
critest
.
FakePodSandbox
{
fakeRuntimeService
.
SetFakeSandboxes
([]
*
critest
.
FakePodSandbox
{
sandbox0
,
sandbox1
,
sandbox2
,
sandbox0
,
sandbox1
,
sandbox2
,
sandbox3
,
})
})
fakeRuntimeService
.
SetFakeContainers
([]
*
critest
.
FakeContainer
{
fakeRuntimeService
.
SetFakeContainers
([]
*
critest
.
FakeContainer
{
container0
,
container1
,
container2
,
container3
,
container4
,
container0
,
container1
,
container2
,
container3
,
container4
,
container5
,
})
})
fakeRuntimeService
.
SetFakeContainerStats
([]
*
runtimeapi
.
ContainerStats
{
fakeRuntimeService
.
SetFakeContainerStats
([]
*
runtimeapi
.
ContainerStats
{
containerStats0
,
containerStats1
,
containerStats2
,
containerStats3
,
containerStats4
,
containerStats0
,
containerStats1
,
containerStats2
,
containerStats3
,
containerStats4
,
containerStats5
,
})
})
ephemeralVolumes
:=
makeFakeVolumeStats
([]
string
{
"ephVolume1, ephVolumes2"
})
ephemeralVolumes
:=
makeFakeVolumeStats
([]
string
{
"ephVolume1, ephVolumes2"
})
...
@@ -161,6 +170,7 @@ func TestCRIListPodStats(t *testing.T) {
...
@@ -161,6 +170,7 @@ func TestCRIListPodStats(t *testing.T) {
kuberuntime
.
BuildContainerLogsDirectory
(
types
.
UID
(
"sandbox0-uid"
),
cName1
)
:
containerLogStats1
,
kuberuntime
.
BuildContainerLogsDirectory
(
types
.
UID
(
"sandbox0-uid"
),
cName1
)
:
containerLogStats1
,
kuberuntime
.
BuildContainerLogsDirectory
(
types
.
UID
(
"sandbox1-uid"
),
cName2
)
:
containerLogStats2
,
kuberuntime
.
BuildContainerLogsDirectory
(
types
.
UID
(
"sandbox1-uid"
),
cName2
)
:
containerLogStats2
,
kuberuntime
.
BuildContainerLogsDirectory
(
types
.
UID
(
"sandbox2-uid"
),
cName3
)
:
containerLogStats4
,
kuberuntime
.
BuildContainerLogsDirectory
(
types
.
UID
(
"sandbox2-uid"
),
cName3
)
:
containerLogStats4
,
kuberuntime
.
BuildContainerLogsDirectory
(
types
.
UID
(
"sandbox3-uid"
),
cName5
)
:
containerLogStats5
,
}
}
fakeLogStatsProvider
:=
NewFakeLogMetricsService
(
fakeLogStats
)
fakeLogStatsProvider
:=
NewFakeLogMetricsService
(
fakeLogStats
)
...
@@ -177,7 +187,7 @@ func TestCRIListPodStats(t *testing.T) {
...
@@ -177,7 +187,7 @@ func TestCRIListPodStats(t *testing.T) {
stats
,
err
:=
provider
.
ListPodStats
()
stats
,
err
:=
provider
.
ListPodStats
()
assert
:=
assert
.
New
(
t
)
assert
:=
assert
.
New
(
t
)
assert
.
NoError
(
err
)
assert
.
NoError
(
err
)
assert
.
Equal
(
3
,
len
(
stats
))
assert
.
Equal
(
4
,
len
(
stats
))
podStatsMap
:=
make
(
map
[
statsapi
.
PodReference
]
statsapi
.
PodStats
)
podStatsMap
:=
make
(
map
[
statsapi
.
PodReference
]
statsapi
.
PodStats
)
for
_
,
s
:=
range
stats
{
for
_
,
s
:=
range
stats
{
...
@@ -239,6 +249,19 @@ func TestCRIListPodStats(t *testing.T) {
...
@@ -239,6 +249,19 @@ func TestCRIListPodStats(t *testing.T) {
checkCRINetworkStats
(
assert
,
p2
.
Network
,
infos
[
sandbox2
.
PodSandboxStatus
.
Id
]
.
Stats
[
0
]
.
Network
)
checkCRINetworkStats
(
assert
,
p2
.
Network
,
infos
[
sandbox2
.
PodSandboxStatus
.
Id
]
.
Stats
[
0
]
.
Network
)
checkCRIPodCPUAndMemoryStats
(
assert
,
p2
,
infos
[
sandbox2Cgroup
]
.
Stats
[
0
])
checkCRIPodCPUAndMemoryStats
(
assert
,
p2
,
infos
[
sandbox2Cgroup
]
.
Stats
[
0
])
p3
:=
podStatsMap
[
statsapi
.
PodReference
{
Name
:
"sandbox3-name"
,
UID
:
"sandbox3-uid"
,
Namespace
:
"sandbox3-ns"
}]
assert
.
Equal
(
sandbox3
.
CreatedAt
,
p3
.
StartTime
.
UnixNano
())
assert
.
Equal
(
1
,
len
(
p3
.
Containers
))
c5
:=
p3
.
Containers
[
0
]
assert
.
Equal
(
cName5
,
c5
.
Name
)
assert
.
Equal
(
container5
.
CreatedAt
,
c5
.
StartTime
.
UnixNano
())
assert
.
NotNil
(
c5
.
CPU
.
Time
)
assert
.
Zero
(
*
c5
.
CPU
.
UsageCoreNanoSeconds
)
assert
.
Zero
(
*
c5
.
CPU
.
UsageNanoCores
)
assert
.
NotNil
(
c5
.
Memory
.
Time
)
assert
.
Zero
(
*
c5
.
Memory
.
WorkingSetBytes
)
mockCadvisor
.
AssertExpectations
(
t
)
mockCadvisor
.
AssertExpectations
(
t
)
}
}
...
@@ -266,6 +289,10 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
...
@@ -266,6 +289,10 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
containerStats3
=
makeFakeContainerStats
(
container3
,
imageFsMountpoint
)
containerStats3
=
makeFakeContainerStats
(
container3
,
imageFsMountpoint
)
container4
=
makeFakeContainer
(
sandbox2
,
cName3
,
1
,
false
)
container4
=
makeFakeContainer
(
sandbox2
,
cName3
,
1
,
false
)
containerStats4
=
makeFakeContainerStats
(
container4
,
imageFsMountpoint
)
containerStats4
=
makeFakeContainerStats
(
container4
,
imageFsMountpoint
)
sandbox3
=
makeFakePodSandbox
(
"sandbox3-name"
,
"sandbox3-uid"
,
"sandbox3-ns"
)
container5
=
makeFakeContainer
(
sandbox3
,
cName5
,
0
,
true
)
containerStats5
=
makeFakeContainerStats
(
container5
,
imageFsMountpoint
)
)
)
var
(
var
(
...
@@ -301,13 +328,13 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
...
@@ -301,13 +328,13 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
mockCadvisor
.
mockCadvisor
.
On
(
"ContainerInfoV2"
,
"/"
,
options
)
.
Return
(
infos
,
nil
)
On
(
"ContainerInfoV2"
,
"/"
,
options
)
.
Return
(
infos
,
nil
)
fakeRuntimeService
.
SetFakeSandboxes
([]
*
critest
.
FakePodSandbox
{
fakeRuntimeService
.
SetFakeSandboxes
([]
*
critest
.
FakePodSandbox
{
sandbox0
,
sandbox1
,
sandbox2
,
sandbox0
,
sandbox1
,
sandbox2
,
sandbox3
,
})
})
fakeRuntimeService
.
SetFakeContainers
([]
*
critest
.
FakeContainer
{
fakeRuntimeService
.
SetFakeContainers
([]
*
critest
.
FakeContainer
{
container0
,
container1
,
container2
,
container3
,
container4
,
container0
,
container1
,
container2
,
container3
,
container4
,
container5
,
})
})
fakeRuntimeService
.
SetFakeContainerStats
([]
*
runtimeapi
.
ContainerStats
{
fakeRuntimeService
.
SetFakeContainerStats
([]
*
runtimeapi
.
ContainerStats
{
containerStats0
,
containerStats1
,
containerStats2
,
containerStats3
,
containerStats4
,
containerStats0
,
containerStats1
,
containerStats2
,
containerStats3
,
containerStats4
,
containerStats5
,
})
})
ephemeralVolumes
:=
makeFakeVolumeStats
([]
string
{
"ephVolume1, ephVolumes2"
})
ephemeralVolumes
:=
makeFakeVolumeStats
([]
string
{
"ephVolume1, ephVolumes2"
})
...
@@ -330,7 +357,7 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
...
@@ -330,7 +357,7 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
stats
,
err
:=
provider
.
ListPodCPUAndMemoryStats
()
stats
,
err
:=
provider
.
ListPodCPUAndMemoryStats
()
assert
:=
assert
.
New
(
t
)
assert
:=
assert
.
New
(
t
)
assert
.
NoError
(
err
)
assert
.
NoError
(
err
)
assert
.
Equal
(
3
,
len
(
stats
))
assert
.
Equal
(
4
,
len
(
stats
))
podStatsMap
:=
make
(
map
[
statsapi
.
PodReference
]
statsapi
.
PodStats
)
podStatsMap
:=
make
(
map
[
statsapi
.
PodReference
]
statsapi
.
PodStats
)
for
_
,
s
:=
range
stats
{
for
_
,
s
:=
range
stats
{
...
@@ -399,6 +426,19 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
...
@@ -399,6 +426,19 @@ func TestCRIListPodCPUAndMemoryStats(t *testing.T) {
assert
.
Nil
(
c2
.
Accelerators
)
assert
.
Nil
(
c2
.
Accelerators
)
assert
.
Nil
(
c2
.
UserDefinedMetrics
)
assert
.
Nil
(
c2
.
UserDefinedMetrics
)
p3
:=
podStatsMap
[
statsapi
.
PodReference
{
Name
:
"sandbox3-name"
,
UID
:
"sandbox3-uid"
,
Namespace
:
"sandbox3-ns"
}]
assert
.
Equal
(
sandbox3
.
CreatedAt
,
p3
.
StartTime
.
UnixNano
())
assert
.
Equal
(
1
,
len
(
p3
.
Containers
))
c5
:=
p3
.
Containers
[
0
]
assert
.
Equal
(
cName5
,
c5
.
Name
)
assert
.
Equal
(
container5
.
CreatedAt
,
c5
.
StartTime
.
UnixNano
())
assert
.
NotNil
(
c5
.
CPU
.
Time
)
assert
.
Zero
(
*
c5
.
CPU
.
UsageCoreNanoSeconds
)
assert
.
Zero
(
*
c5
.
CPU
.
UsageNanoCores
)
assert
.
NotNil
(
c5
.
Memory
.
Time
)
assert
.
Zero
(
*
c5
.
Memory
.
WorkingSetBytes
)
mockCadvisor
.
AssertExpectations
(
t
)
mockCadvisor
.
AssertExpectations
(
t
)
}
}
...
...
pkg/kubelet/stats/helper.go
View file @
4f01eb52
...
@@ -326,3 +326,7 @@ func getUint64Value(value *uint64) uint64 {
...
@@ -326,3 +326,7 @@ func getUint64Value(value *uint64) uint64 {
return
*
value
return
*
value
}
}
func
Uint64Ptr
(
i
uint64
)
*
uint64
{
return
&
i
}
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