diff options
author | Jhon Honce <jhonce@redhat.com> | 2021-09-09 10:13:06 -0700 |
---|---|---|
committer | Jhon Honce <jhonce@redhat.com> | 2021-09-10 15:07:25 -0700 |
commit | deaf9692432bb6a9353fe56cecb6cddf0401a78c (patch) | |
tree | 862568c3d0d129e8f03dd3dfecb3490f0670a964 /pkg/api/handlers/libpod/containers.go | |
parent | e6046224ea88cad9286303456562b4a24ad9cf9b (diff) | |
download | podman-deaf9692432bb6a9353fe56cecb6cddf0401a78c.tar.gz podman-deaf9692432bb6a9353fe56cecb6cddf0401a78c.tar.bz2 podman-deaf9692432bb6a9353fe56cecb6cddf0401a78c.zip |
Refacter API server emphasis on logging
* To aid in debugging log API request and response bodies at trace
level. Events can be correlated using the X-Reference-Id.
* Server now echos X-Reference-Id from client if set, otherwise
generates an unique id.
* Move logic for X-Reference-Id into middleware
* Change uses of Header.Add() to Set() when setting Content-Type
* Log API operations in Apache format using gorilla middleware
* Port server code to use BaseContext and ConnContext
Fixes #10053
Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'pkg/api/handlers/libpod/containers.go')
-rw-r--r-- | pkg/api/handlers/libpod/containers.go | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/pkg/api/handlers/libpod/containers.go b/pkg/api/handlers/libpod/containers.go index 77269db8b..4639093f2 100644 --- a/pkg/api/handlers/libpod/containers.go +++ b/pkg/api/handlers/libpod/containers.go @@ -9,6 +9,7 @@ import ( "github.com/containers/podman/v3/libpod/define" "github.com/containers/podman/v3/pkg/api/handlers/compat" "github.com/containers/podman/v3/pkg/api/handlers/utils" + api "github.com/containers/podman/v3/pkg/api/types" "github.com/containers/podman/v3/pkg/domain/entities" "github.com/containers/podman/v3/pkg/domain/infra/abi" "github.com/containers/podman/v3/pkg/util" @@ -18,8 +19,8 @@ import ( ) func ContainerExists(w http.ResponseWriter, r *http.Request) { - decoder := r.Context().Value("decoder").(*schema.Decoder) - runtime := r.Context().Value("runtime").(*libpod.Runtime) + decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder) + runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) // Now use the ABI implementation to prevent us from having duplicate // code. containerEngine := abi.ContainerEngine{Libpod: runtime} @@ -58,7 +59,7 @@ func ContainerExists(w http.ResponseWriter, r *http.Request) { } func ListContainers(w http.ResponseWriter, r *http.Request) { - decoder := r.Context().Value("decoder").(*schema.Decoder) + decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder) query := struct { All bool `schema:"all"` External bool `schema:"external"` @@ -89,7 +90,7 @@ func ListContainers(w http.ResponseWriter, r *http.Request) { limit = query.Last } - runtime := r.Context().Value("runtime").(*libpod.Runtime) + runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) // Now use the ABI implementation to prevent us from having duplicate // code. containerEngine := abi.ContainerEngine{Libpod: runtime} @@ -118,7 +119,7 @@ func ListContainers(w http.ResponseWriter, r *http.Request) { } func GetContainer(w http.ResponseWriter, r *http.Request) { - decoder := r.Context().Value("decoder").(*schema.Decoder) + decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder) query := struct { Size bool `schema:"size"` }{ @@ -130,7 +131,7 @@ func GetContainer(w http.ResponseWriter, r *http.Request) { errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String())) return } - runtime := r.Context().Value("runtime").(*libpod.Runtime) + runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) name := utils.GetName(r) container, err := runtime.LookupContainer(name) if err != nil { @@ -150,7 +151,7 @@ func WaitContainer(w http.ResponseWriter, r *http.Request) { } func UnmountContainer(w http.ResponseWriter, r *http.Request) { - runtime := r.Context().Value("runtime").(*libpod.Runtime) + runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) name := utils.GetName(r) conn, err := runtime.LookupContainer(name) if err != nil { @@ -165,7 +166,7 @@ func UnmountContainer(w http.ResponseWriter, r *http.Request) { utils.WriteResponse(w, http.StatusNoContent, "") } func MountContainer(w http.ResponseWriter, r *http.Request) { - runtime := r.Context().Value("runtime").(*libpod.Runtime) + runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) name := utils.GetName(r) conn, err := runtime.LookupContainer(name) if err != nil { @@ -181,7 +182,7 @@ func MountContainer(w http.ResponseWriter, r *http.Request) { func ShowMountedContainers(w http.ResponseWriter, r *http.Request) { response := make(map[string]string) - runtime := r.Context().Value("runtime").(*libpod.Runtime) + runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) conns, err := runtime.GetAllContainers() if err != nil { utils.InternalServerError(w, err) @@ -201,7 +202,7 @@ func ShowMountedContainers(w http.ResponseWriter, r *http.Request) { func Checkpoint(w http.ResponseWriter, r *http.Request) { var targetFile string - decoder := r.Context().Value("decoder").(*schema.Decoder) + decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder) query := struct { Keep bool `schema:"keep"` LeaveRunning bool `schema:"leaveRunning"` @@ -218,7 +219,7 @@ func Checkpoint(w http.ResponseWriter, r *http.Request) { return } name := utils.GetName(r) - runtime := r.Context().Value("runtime").(*libpod.Runtime) + runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) ctr, err := runtime.LookupContainer(name) if err != nil { utils.ContainerNotFound(w, name, err) @@ -268,7 +269,7 @@ func Restore(w http.ResponseWriter, r *http.Request) { var ( targetFile string ) - decoder := r.Context().Value("decoder").(*schema.Decoder) + decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder) query := struct { Keep bool `schema:"keep"` TCPEstablished bool `schema:"tcpEstablished"` @@ -287,7 +288,7 @@ func Restore(w http.ResponseWriter, r *http.Request) { return } name := utils.GetName(r) - runtime := r.Context().Value("runtime").(*libpod.Runtime) + runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) ctr, err := runtime.LookupContainer(name) if err != nil { utils.ContainerNotFound(w, name, err) @@ -328,7 +329,7 @@ func Restore(w http.ResponseWriter, r *http.Request) { func InitContainer(w http.ResponseWriter, r *http.Request) { name := utils.GetName(r) - runtime := r.Context().Value("runtime").(*libpod.Runtime) + runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) ctr, err := runtime.LookupContainer(name) if err != nil { utils.ContainerNotFound(w, name, err) @@ -347,7 +348,7 @@ func InitContainer(w http.ResponseWriter, r *http.Request) { } func ShouldRestart(w http.ResponseWriter, r *http.Request) { - runtime := r.Context().Value("runtime").(*libpod.Runtime) + runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) // Now use the ABI implementation to prevent us from having duplicate // code. containerEngine := abi.ContainerEngine{Libpod: runtime} |