Skip to content

Commit

Permalink
Merge pull request google#589 from rjnagal/docker
Browse files Browse the repository at this point in the history
Add recursive option for /stats endpoint.
  • Loading branch information
vmarmol committed Mar 13, 2015
2 parents 588b149 + 1b3de3a commit b4f6712
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions api/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,30 @@ func (self *version2_0) HandleRequest(requestType string, request []string, m ma
}
switch sr.IdType {
case typeName:
cont, err := m.GetContainerInfo(name, &query)
if err != nil {
return fmt.Errorf("failed to get container %q: %v", name, err)
contStats := make(map[string][]v2.ContainerStats, 0)
if sr.Recursive == false {
cont, err := m.GetContainerInfo(name, &query)
if err != nil {
return fmt.Errorf("failed to get container %q: %v", name, err)
}
contStats[name] = convertStats(cont)
} else {
containers, err := m.SubcontainersInfo(name, &query)
if err != nil {
return fmt.Errorf("failed to get subcontainers for container %q with error: %s", name, err)
}
for _, cont := range containers {
contStats[cont.Name] = convertStats(cont)
}
}
contStats := convertStats(cont)
return writeResult(contStats, w)
case typeDocker:
contStats := make(map[string][]v2.ContainerStats, 0)
if name == "/" {
// special case: get all docker containers.
// TODO(rjnagal): require recursive=true to be set?
if sr.Recursive == false {
return fmt.Errorf("unknown Docker container %q", name)
}
containers, err := m.AllDockerContainers(&query)
if err != nil {
return fmt.Errorf("failed to get all docker containers: %v", err)
Expand Down Expand Up @@ -451,6 +464,9 @@ func getStatsRequest(id string, r *http.Request) (v2.StatsRequest, error) {
}
sr.Count = int(n)
}
// TODO(rjnagal): Add option to specify recursive.
recursive := r.URL.Query().Get("recursive")
if recursive == "true" {
sr.Recursive = true
}
return sr, nil
}

0 comments on commit b4f6712

Please sign in to comment.