Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make discovery summarizer call servers in parallel #26705

Merged
merged 1 commit into from
Jul 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,39 @@ func (ds *discoverySummarizerServer) indexHandler(w http.ResponseWriter, r *http
func (ds *discoverySummarizerServer) summarizeGroupVersionsHandler(path string) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
var apiGroupList *unversioned.APIGroupList
// TODO: We can cache and parallelize the calls to all servers.
// TODO: We can cache calls to all servers.
groups := make(chan *unversioned.APIGroupList)
errorChannel := make(chan error)
for _, serverAddress := range ds.groupVersionPaths[path] {
groupList, err := ds.getAPIGroupList(serverAddress + path)
if err != nil {
addr := serverAddress
go func(groups chan *unversioned.APIGroupList, error_channel chan error) {
groupList, err := ds.getAPIGroupList(addr + path)
if err != nil {
errorChannel <- err
return
}
groups <- groupList
return
}(groups, errorChannel)
}

var groupList *unversioned.APIGroupList
var err error
for range ds.groupVersionPaths[path] {
select {
case groupList = <-groups:
if apiGroupList == nil {
apiGroupList = &unversioned.APIGroupList{}
*apiGroupList = *groupList
} else {
apiGroupList.Groups = append(apiGroupList.Groups, groupList.Groups...)
}
case err = <-errorChannel:
ds.writeErr(http.StatusBadGateway, err, w)
return
}
if apiGroupList == nil {
apiGroupList = &unversioned.APIGroupList{}
*apiGroupList = *groupList
} else {
apiGroupList.Groups = append(apiGroupList.Groups, groupList.Groups...)
}
}

ds.writeRawJSON(http.StatusOK, *apiGroupList, w)
return
}
Expand Down