Merge pull request #45847 from thaJeztah/sysinfo_singleflight
api: use singleflight for /info endpoint
This commit is contained in:
commit
4ee0cf6878
2 changed files with 37 additions and 27 deletions
|
@ -2,7 +2,9 @@ package system // import "github.com/docker/docker/api/server/router/system"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/docker/docker/api/server/router"
|
"github.com/docker/docker/api/server/router"
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
buildkit "github.com/docker/docker/builder/builder-next"
|
buildkit "github.com/docker/docker/builder/builder-next"
|
||||||
|
"resenje.org/singleflight"
|
||||||
)
|
)
|
||||||
|
|
||||||
// systemRouter provides information about the Docker system overall.
|
// systemRouter provides information about the Docker system overall.
|
||||||
|
@ -13,6 +15,11 @@ type systemRouter struct {
|
||||||
routes []router.Route
|
routes []router.Route
|
||||||
builder *buildkit.Builder
|
builder *buildkit.Builder
|
||||||
features func() map[string]bool
|
features func() map[string]bool
|
||||||
|
|
||||||
|
// collectSystemInfo is a single-flight for the /info endpoint,
|
||||||
|
// unique per API version (as different API versions may return
|
||||||
|
// a different API response).
|
||||||
|
collectSystemInfo singleflight.Group[string, *types.Info]
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRouter initializes a new system router
|
// NewRouter initializes a new system router
|
||||||
|
|
|
@ -57,6 +57,8 @@ func (s *systemRouter) swarmStatus() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
|
version := httputils.VersionFromContext(ctx)
|
||||||
|
info, _, _ := s.collectSystemInfo.Do(ctx, version, func(ctx context.Context) (*types.Info, error) {
|
||||||
info := s.backend.SystemInfo()
|
info := s.backend.SystemInfo()
|
||||||
|
|
||||||
if s.cluster != nil {
|
if s.cluster != nil {
|
||||||
|
@ -64,7 +66,6 @@ func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *ht
|
||||||
info.Warnings = append(info.Warnings, info.Swarm.Warnings...)
|
info.Warnings = append(info.Warnings, info.Swarm.Warnings...)
|
||||||
}
|
}
|
||||||
|
|
||||||
version := httputils.VersionFromContext(ctx)
|
|
||||||
if versions.LessThan(version, "1.25") {
|
if versions.LessThan(version, "1.25") {
|
||||||
// TODO: handle this conversion in engine-api
|
// TODO: handle this conversion in engine-api
|
||||||
kvSecOpts, err := types.DecodeSecurityOptions(info.SecurityOptions)
|
kvSecOpts, err := types.DecodeSecurityOptions(info.SecurityOptions)
|
||||||
|
@ -89,6 +90,8 @@ func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *ht
|
||||||
if versions.GreaterThanOrEqualTo(version, "1.42") {
|
if versions.GreaterThanOrEqualTo(version, "1.42") {
|
||||||
info.KernelMemory = false
|
info.KernelMemory = false
|
||||||
}
|
}
|
||||||
|
return info, nil
|
||||||
|
})
|
||||||
return httputils.WriteJSON(w, http.StatusOK, info)
|
return httputils.WriteJSON(w, http.StatusOK, info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue