v2: stats: do not ignore errors

We must check all errors and handle them properly. Otherwise, we can run
into nil dereferences ultimately killing the service.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
Valentin Rothberg 2020-01-15 11:41:38 +01:00
parent a1ff93bdfe
commit 3c7b7761ce
1 changed files with 31 additions and 6 deletions

View File

@ -81,19 +81,44 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) {
time.Sleep(DefaultStatsPeriod)
}
cgroupPath, _ := ctnr.CGroupPath()
cgroup, _ := cgroups.Load(cgroupPath)
cgroupPath, err := ctnr.CGroupPath()
if err != nil {
utils.InternalServerError(w, err)
return
}
cgroup, err := cgroups.Load(cgroupPath)
if err != nil {
utils.InternalServerError(w, err)
return
}
for ok := true; ok; ok = query.Stream {
state, _ := ctnr.State()
state, err := ctnr.State()
if err != nil {
utils.InternalServerError(w, err)
return
}
if state != define.ContainerStateRunning {
time.Sleep(10 * time.Second)
continue
}
stats, _ := ctnr.GetContainerStats(stats)
cgroupStat, _ := cgroup.Stat()
inspect, _ := ctnr.Inspect(false)
stats, err := ctnr.GetContainerStats(stats)
if err != nil {
utils.InternalServerError(w, err)
return
}
cgroupStat, err := cgroup.Stat()
if err != nil {
utils.InternalServerError(w, err)
return
}
inspect, err := ctnr.Inspect(false)
if err != nil {
utils.InternalServerError(w, err)
return
}
net := make(map[string]docker.NetworkStats)
net[inspect.NetworkSettings.EndpointID] = docker.NetworkStats{