Bladeren bron

List Networks need not pull all the endpoints

Pulling all the endpoints is a very resource heavy operation especially
for Global-scoped networks with a backing KVStore. Such heavy operations
can be fetched for individual network inspect. These are unneccessary
for a simple network list operation.

Signed-off-by: Madhu Venugopal <madhu@docker.com>
Madhu Venugopal 8 jaren geleden
bovenliggende
commit
f388b7aa8a
2 gewijzigde bestanden met toevoegingen van 25 en 4 verwijderingen
  1. 23 2
      api/server/router/network/network_routes.go
  2. 2 2
      docs/api/version-history.md

+ 23 - 2
api/server/router/network/network_routes.go

@@ -10,6 +10,7 @@ import (
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types/filters"
 	"github.com/docker/docker/api/types/filters"
 	"github.com/docker/docker/api/types/network"
 	"github.com/docker/docker/api/types/network"
+	"github.com/docker/docker/api/types/versions"
 	"github.com/docker/libnetwork"
 	"github.com/docker/libnetwork"
 	"github.com/docker/libnetwork/networkdb"
 	"github.com/docker/libnetwork/networkdb"
 )
 )
@@ -55,7 +56,18 @@ SKIP:
 				continue SKIP
 				continue SKIP
 			}
 			}
 		}
 		}
-		list = append(list, *n.buildNetworkResource(nw))
+
+		var nr *types.NetworkResource
+		// Versions < 1.26 fetches all the containers attached to a network
+		// in a network list api call. It is a heavy weight operation when
+		// run across all the networks. Starting API version 1.26, this detailed
+		// info is available for network specific GET API (equivalent to inspect)
+		if versions.LessThan(httputils.VersionFromContext(ctx), "1.26") {
+			nr = n.buildDetailedNetworkResources(nw)
+		} else {
+			nr = n.buildNetworkResource(nw)
+		}
+		list = append(list, *nr)
 	}
 	}
 
 
 	list, err = filterNetworks(list, netFilters)
 	list, err = filterNetworks(list, netFilters)
@@ -77,7 +89,7 @@ func (n *networkRouter) getNetwork(ctx context.Context, w http.ResponseWriter, r
 		}
 		}
 		return err
 		return err
 	}
 	}
-	return httputils.WriteJSON(w, http.StatusOK, n.buildNetworkResource(nw))
+	return httputils.WriteJSON(w, http.StatusOK, n.buildDetailedNetworkResources(nw))
 }
 }
 
 
 func (n *networkRouter) postNetworkCreate(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
 func (n *networkRouter) postNetworkCreate(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
@@ -198,6 +210,15 @@ func (n *networkRouter) buildNetworkResource(nw libnetwork.Network) *types.Netwo
 		r.Peers = buildPeerInfoResources(peers)
 		r.Peers = buildPeerInfoResources(peers)
 	}
 	}
 
 
+	return r
+}
+
+func (n *networkRouter) buildDetailedNetworkResources(nw libnetwork.Network) *types.NetworkResource {
+	if nw == nil {
+		return &types.NetworkResource{}
+	}
+
+	r := n.buildNetworkResource(nw)
 	epl := nw.Endpoints()
 	epl := nw.Endpoints()
 	for _, e := range epl {
 	for _, e := range epl {
 		ei := e.Info()
 		ei := e.Info()

+ 2 - 2
docs/api/version-history.md

@@ -17,8 +17,8 @@ keywords: "API, Docker, rcli, REST, documentation"
 
 
 [Docker Engine API v1.26](v1.26/) documentation
 [Docker Engine API v1.26](v1.26/) documentation
 
 
-* `GET /containers/(id or name)/attach/ws` now returns WebSocket in binary frame format for API version >= v1.26,
-  and returns WebSocket in text frame format for API version< v1.26, for the purpose of backward-compatibility.
+* `GET /containers/(id or name)/attach/ws` now returns WebSocket in binary frame format for API version >= v1.26, and returns WebSocket in text frame format for API version< v1.26, for the purpose of backward-compatibility.
+* `GET /networks` is optimised only to return list of all networks and network specific information. List of all containers attached to a specific network is removed from this API and is only available using the network specific `GET /networks/{network-id}.
 
 
 ## v1.25 API changes
 ## v1.25 API changes