Skip to content

Commit

Permalink
runtime: direct-volume stats update to use GET parameter
Browse files Browse the repository at this point in the history
The go default http mux AFAIK doesn’t support pattern
routing so right now client is padding the url
for direct-volume stats with a subpath of the volume
path and this will always result in 404 not found returned
by the shim.

This change will update the shim to take the volume
path as a GET query parameter instead of a subpath.
If the parameter is missing or empty, then return
400 BadRequest to the client.

Fixes: #4297

Signed-off-by: Yibo Zhuang <yibzhuang@gmail.com>
  • Loading branch information
yibozhuang committed May 23, 2022
1 parent f528bc0 commit 338c9f2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/runtime/pkg/containerd-shim-v2/shim_management.go
Expand Up @@ -32,6 +32,8 @@ import (
)

const (
DirectVolumePathKey = "path"

DirectVolumeStatUrl = "/direct-volume/stats"
DirectVolumeResizeUrl = "/direct-volume/resize"
)
Expand Down Expand Up @@ -139,7 +141,16 @@ func decodeAgentMetrics(body string) []*dto.MetricFamily {
}

func (s *service) serveVolumeStats(w http.ResponseWriter, r *http.Request) {
volumePath, err := url.PathUnescape(strings.TrimPrefix(r.URL.Path, DirectVolumeStatUrl))
val := r.URL.Query().Get(DirectVolumePathKey)
if val == "" {
msg := fmt.Sprintf("Required parameter %s not found", DirectVolumePathKey)
shimMgtLog.Info(msg)
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(msg))
return
}

volumePath, err := url.PathUnescape(val)
if err != nil {
shimMgtLog.WithError(err).Error("failed to unescape the volume stat url path")
w.WriteHeader(http.StatusInternalServerError)
Expand Down

0 comments on commit 338c9f2

Please sign in to comment.