mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
![Doug Davis](/assets/img/avatar_default.png)
This defines a 'context' object that is passed to each API handler. Right now the context just has a unique 'requestID' for each API call. The next steps would be: - use this 'requestID' in our logging. - determine the best way to format the logging to include this info. In particular for log events that generate multiple entries in the log we can use the requestID to help correlate the log entries. Adding the requestID to the logging will be a challenge since it could mean changing every single logrus.XXX() call to pass in the 'context' object. But first step is to agree on a format, which we can discus in a subsequent PR, but my initial thoughts are to add it right after the timestamp: current format: INFO[0039] POST /v1.21/build?buildargs=%7B%22foo%22%3A%22xxx%22%7D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&memory=0&memswap=0&rm=1&t=&ulimits=null proposed format: INFO[0039-83dea1222191] POST /v1.21/build?buildargs=%7B%22foo%22%3A%22xxx%22%7D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&memory=0&memswap=0&rm=1&t=&ulimits=null Signed-off-by: Doug Davis <dug@us.ibm.com>
37 lines
825 B
Go
37 lines
825 B
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
"github.com/docker/docker/pkg/version"
|
|
)
|
|
|
|
// getContainersByName inspects containers configuration and serializes it as json.
|
|
func (s *Server) getContainersByName(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if vars == nil {
|
|
return fmt.Errorf("Missing parameter")
|
|
}
|
|
|
|
var json interface{}
|
|
var err error
|
|
|
|
version, _ := ctx.Value("api-version").(version.Version)
|
|
|
|
switch {
|
|
case version.LessThan("1.20"):
|
|
json, err = s.daemon.ContainerInspectPre120(vars["name"])
|
|
case version.Equal("1.20"):
|
|
json, err = s.daemon.ContainerInspect120(vars["name"])
|
|
default:
|
|
json, err = s.daemon.ContainerInspect(vars["name"])
|
|
}
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return writeJSON(w, http.StatusOK, json)
|
|
}
|