Skip to content

Commit

Permalink
Merge pull request #11637 from manadart/2.8-rc
Browse files Browse the repository at this point in the history
#11637

## Description of change

Cherry picked commits constituting the following patches:
- #11570
- #11606 
- #11608 

These are performance enhancements around the frequency of database access when materialising space information via `network.AllSpaceInfos`.
  • Loading branch information
jujubot committed May 28, 2020
2 parents afe2aa8 + d803a7e commit db0bdd4
Show file tree
Hide file tree
Showing 26 changed files with 346 additions and 104 deletions.
3 changes: 2 additions & 1 deletion apiserver/common/crossmodel/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/juju/juju/core/crossmodel"
"github.com/juju/juju/core/firewall"
"github.com/juju/juju/core/network"
"github.com/juju/juju/core/permission"
"github.com/juju/juju/core/status"
"github.com/juju/juju/state"
Expand Down Expand Up @@ -212,7 +213,7 @@ type Application interface {
// details on the methods, see the methods on state.Bindings with
// the same names.
type Bindings interface {
MapWithSpaceNames() (map[string]string, error)
MapWithSpaceNames(network.SpaceInfos) (map[string]string, error)
}

type Charm interface {
Expand Down
8 changes: 7 additions & 1 deletion apiserver/facades/client/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -2444,6 +2444,12 @@ func (u *APIv8) ApplicationInfo(_, _ struct{}) {}

// ApplicationsInfo returns applications information.
func (api *APIBase) ApplicationsInfo(in params.Entities) (params.ApplicationInfoResults, error) {
// Get all the space infos before iterating over the application infos.
allSpaceInfosLookup, err := api.backend.AllSpaceInfos()
if err != nil {
return params.ApplicationInfoResults{}, common.ServerError(err)
}

out := make([]params.ApplicationInfoResult, len(in.Entities))
for i, one := range in.Entities {
tag, err := names.ParseApplicationTag(one.Tag)
Expand All @@ -2469,7 +2475,7 @@ func (api *APIBase) ApplicationsInfo(in params.Entities) (params.ApplicationInfo
continue
}

bindingsMap, err := bindings.MapWithSpaceNames()
bindingsMap, err := bindings.MapWithSpaceNames(allSpaceInfosLookup)
if err != nil {
out[i].Error = common.ServerError(err)
continue
Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/client/application/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ type Application interface {
// the same names.
type Bindings interface {
Map() map[string]string
MapWithSpaceNames() (map[string]string, error)
MapWithSpaceNames(network.SpaceInfos) (map[string]string, error)
}

// Charm defines a subset of the functionality provided by the
Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/client/application/charmstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
)

//go:generate go run github.com/golang/mock/mockgen -package mocks -destination mocks/storage_mock.go github.com/juju/juju/state/storage Storage
//go:generate go run github.com/golang/mock/mockgen -package mocks -destination mocks/interface_mock.go gopkg.in/juju/charmrepo.v4 Interface
//go:generate go run github.com/golang/mock/mockgen -package mocks -destination mocks/interface_mock.go github.com/juju/charmrepo/v5 Interface
//go:generate go run github.com/golang/mock/mockgen -package mocks -destination mocks/charm_mock.go github.com/juju/juju/apiserver/facades/client/application StateCharm
//go:generate go run github.com/golang/mock/mockgen -package mocks -destination mocks/model_mock.go github.com/juju/juju/apiserver/facades/client/application StateModel
//go:generate go run github.com/golang/mock/mockgen -package mocks -destination mocks/charmstore_mock.go github.com/juju/juju/apiserver/facades/client/application State
Expand Down
8 changes: 7 additions & 1 deletion apiserver/facades/client/application/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/juju/schema"
"gopkg.in/juju/environschema.v1"

"github.com/juju/juju/apiserver/common"
"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/caas"
"github.com/juju/juju/core/constraints"
Expand Down Expand Up @@ -96,7 +97,12 @@ func (api *APIBase) getConfig(
return params.ApplicationGetResults{}, err
}

bindingMap, err := endpoints.MapWithSpaceNames()
allSpaceInfosLookup, err := api.backend.AllSpaceInfos()
if err != nil {
return params.ApplicationGetResults{}, common.ServerError(err)
}

bindingMap, err := endpoints.MapWithSpaceNames(allSpaceInfosLookup)
if err != nil {
return params.ApplicationGetResults{}, err
}
Expand Down
4 changes: 3 additions & 1 deletion apiserver/facades/client/application/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ func (b *mockBindings) Map() map[string]string {
return b.bMap
}

func (b *mockBindings) MapWithSpaceNames() (map[string]string, error) {
// TODO (stickupkid): This implementation is wrong, we should move to a newer
// gomock style setup.
func (b *mockBindings) MapWithSpaceNames(network.SpaceInfos) (map[string]string, error) {
return b.bMap, nil
}

Expand Down
5 changes: 3 additions & 2 deletions apiserver/facades/client/application/mocks/charm_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 18 additions & 7 deletions apiserver/facades/client/application/mocks/charmstore_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 15 additions & 10 deletions apiserver/facades/client/application/mocks/interface_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions apiserver/facades/client/application/mocks/model_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions apiserver/facades/client/application/mocks/storage_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit db0bdd4

Please sign in to comment.