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
3bd315dc
Commit
3bd315dc
authored
Oct 26, 2017
by
Yanqiang Miao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Filter out duplicated container stats
Signed-off-by:
Yanqiang Miao
<
miao.yanqiang@zte.com.cn
>
parent
6fc460b7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
11 deletions
+52
-11
cadvisor_stats_provider.go
pkg/kubelet/stats/cadvisor_stats_provider.go
+6
-6
cri_stats_provider.go
pkg/kubelet/stats/cri_stats_provider.go
+46
-5
No files found.
pkg/kubelet/stats/cadvisor_stats_provider.go
View file @
3bd315dc
...
@@ -106,7 +106,7 @@ func (p *cadvisorStatsProvider) ListPodStats() ([]statsapi.PodStats, error) {
...
@@ -106,7 +106,7 @@ func (p *cadvisorStatsProvider) ListPodStats() ([]statsapi.PodStats, error) {
if
!
isPodManagedContainer
(
&
cinfo
)
{
if
!
isPodManagedContainer
(
&
cinfo
)
{
continue
continue
}
}
ref
:=
buildPodRef
(
&
cinfo
)
ref
:=
buildPodRef
(
cinfo
.
Spec
.
Labels
)
// Lookup the PodStats for the pod using the PodRef. If none exists,
// Lookup the PodStats for the pod using the PodRef. If none exists,
// initialize a new entry.
// initialize a new entry.
...
@@ -172,10 +172,10 @@ func (p *cadvisorStatsProvider) ImageFsStats() (*statsapi.FsStats, error) {
...
@@ -172,10 +172,10 @@ func (p *cadvisorStatsProvider) ImageFsStats() (*statsapi.FsStats, error) {
}
}
// buildPodRef returns a PodReference that identifies the Pod managing cinfo
// buildPodRef returns a PodReference that identifies the Pod managing cinfo
func
buildPodRef
(
c
info
*
cadvisorapiv2
.
ContainerInfo
)
statsapi
.
PodReference
{
func
buildPodRef
(
c
ontainerLabels
map
[
string
]
string
)
statsapi
.
PodReference
{
podName
:=
kubetypes
.
GetPodName
(
c
info
.
Spec
.
Labels
)
podName
:=
kubetypes
.
GetPodName
(
c
ontainer
Labels
)
podNamespace
:=
kubetypes
.
GetPodNamespace
(
c
info
.
Spec
.
Labels
)
podNamespace
:=
kubetypes
.
GetPodNamespace
(
c
ontainer
Labels
)
podUID
:=
kubetypes
.
GetPodUID
(
c
info
.
Spec
.
Labels
)
podUID
:=
kubetypes
.
GetPodUID
(
c
ontainer
Labels
)
return
statsapi
.
PodReference
{
Name
:
podName
,
Namespace
:
podNamespace
,
UID
:
podUID
}
return
statsapi
.
PodReference
{
Name
:
podName
,
Namespace
:
podNamespace
,
UID
:
podUID
}
}
}
...
@@ -204,7 +204,7 @@ func removeTerminatedContainerInfo(containerInfo map[string]cadvisorapiv2.Contai
...
@@ -204,7 +204,7 @@ func removeTerminatedContainerInfo(containerInfo map[string]cadvisorapiv2.Contai
continue
continue
}
}
cinfoID
:=
containerID
{
cinfoID
:=
containerID
{
podRef
:
buildPodRef
(
&
cinfo
),
podRef
:
buildPodRef
(
cinfo
.
Spec
.
Labels
),
containerName
:
kubetypes
.
GetContainerName
(
cinfo
.
Spec
.
Labels
),
containerName
:
kubetypes
.
GetContainerName
(
cinfo
.
Spec
.
Labels
),
}
}
cinfoMap
[
cinfoID
]
=
append
(
cinfoMap
[
cinfoID
],
containerInfoWithCgroup
{
cinfoMap
[
cinfoID
]
=
append
(
cinfoMap
[
cinfoID
],
containerInfoWithCgroup
{
...
...
pkg/kubelet/stats/cri_stats_provider.go
View file @
3bd315dc
...
@@ -18,6 +18,7 @@ package stats
...
@@ -18,6 +18,7 @@ package stats
import
(
import
(
"fmt"
"fmt"
"sort"
"time"
"time"
"github.com/golang/glog"
"github.com/golang/glog"
...
@@ -31,6 +32,7 @@ import (
...
@@ -31,6 +32,7 @@ import (
statsapi
"k8s.io/kubernetes/pkg/kubelet/apis/stats/v1alpha1"
statsapi
"k8s.io/kubernetes/pkg/kubelet/apis/stats/v1alpha1"
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
"k8s.io/kubernetes/pkg/kubelet/server/stats"
"k8s.io/kubernetes/pkg/kubelet/server/stats"
kubetypes
"k8s.io/kubernetes/pkg/kubelet/types"
)
)
// criStatsProvider implements the containerStatsProvider interface by getting
// criStatsProvider implements the containerStatsProvider interface by getting
...
@@ -74,15 +76,10 @@ func (p *criStatsProvider) ListPodStats() ([]statsapi.PodStats, error) {
...
@@ -74,15 +76,10 @@ func (p *criStatsProvider) ListPodStats() ([]statsapi.PodStats, error) {
return
nil
,
fmt
.
Errorf
(
"failed to get rootFs info: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to get rootFs info: %v"
,
err
)
}
}
// Creates container map.
containerMap
:=
make
(
map
[
string
]
*
runtimeapi
.
Container
)
containers
,
err
:=
p
.
runtimeService
.
ListContainers
(
&
runtimeapi
.
ContainerFilter
{})
containers
,
err
:=
p
.
runtimeService
.
ListContainers
(
&
runtimeapi
.
ContainerFilter
{})
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to list all containers: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to list all containers: %v"
,
err
)
}
}
for
_
,
c
:=
range
containers
{
containerMap
[
c
.
Id
]
=
c
}
// Creates pod sandbox map.
// Creates pod sandbox map.
podSandboxMap
:=
make
(
map
[
string
]
*
runtimeapi
.
PodSandbox
)
podSandboxMap
:=
make
(
map
[
string
]
*
runtimeapi
.
PodSandbox
)
...
@@ -106,6 +103,14 @@ func (p *criStatsProvider) ListPodStats() ([]statsapi.PodStats, error) {
...
@@ -106,6 +103,14 @@ func (p *criStatsProvider) ListPodStats() ([]statsapi.PodStats, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to list all container stats: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to list all container stats: %v"
,
err
)
}
}
containers
=
removeTerminatedContainer
(
containers
)
// Creates container map.
containerMap
:=
make
(
map
[
string
]
*
runtimeapi
.
Container
)
for
_
,
c
:=
range
containers
{
containerMap
[
c
.
Id
]
=
c
}
for
_
,
stats
:=
range
resp
{
for
_
,
stats
:=
range
resp
{
containerID
:=
stats
.
Attributes
.
Id
containerID
:=
stats
.
Attributes
.
Id
container
,
found
:=
containerMap
[
containerID
]
container
,
found
:=
containerMap
[
containerID
]
...
@@ -279,3 +284,39 @@ func (p *criStatsProvider) makeContainerStats(
...
@@ -279,3 +284,39 @@ func (p *criStatsProvider) makeContainerStats(
return
result
return
result
}
}
// removeTerminatedContainer returns the specified container but with
// the stats of the terminated containers removed.
func
removeTerminatedContainer
(
containers
[]
*
runtimeapi
.
Container
)
[]
*
runtimeapi
.
Container
{
containerMap
:=
make
(
map
[
containerID
][]
*
runtimeapi
.
Container
)
// Sort order by create time
sort
.
Slice
(
containers
,
func
(
i
,
j
int
)
bool
{
return
containers
[
i
]
.
CreatedAt
<
containers
[
j
]
.
CreatedAt
})
for
_
,
container
:=
range
containers
{
refID
:=
containerID
{
podRef
:
buildPodRef
(
container
.
Labels
),
containerName
:
kubetypes
.
GetContainerName
(
container
.
Labels
),
}
containerMap
[
refID
]
=
append
(
containerMap
[
refID
],
container
)
}
result
:=
make
([]
*
runtimeapi
.
Container
,
0
)
for
_
,
refs
:=
range
containerMap
{
if
len
(
refs
)
==
1
{
result
=
append
(
result
,
refs
[
0
])
continue
}
found
:=
false
for
i
:=
0
;
i
<
len
(
refs
);
i
++
{
if
refs
[
i
]
.
State
==
runtimeapi
.
ContainerState_CONTAINER_RUNNING
{
found
=
true
result
=
append
(
result
,
refs
[
i
])
}
}
if
!
found
{
result
=
append
(
result
,
refs
[
len
(
refs
)
-
1
])
}
}
return
result
}
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