Merge pull request #6432 from dmcgowan/fix-introspection-service
services/introspection: fix plugin caching to show grpc plugins
This commit is contained in:
commit
a372097669
@ -132,9 +132,19 @@ func (ps *Set) Get(t Type) (interface{}, error) {
|
|||||||
return nil, fmt.Errorf("no plugins registered for %s: %w", t, errdefs.ErrNotFound)
|
return nil, fmt.Errorf("no plugins registered for %s: %w", t, errdefs.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAll returns all initialized plugins
|
||||||
|
func (ps *Set) GetAll() []*Plugin {
|
||||||
|
return ps.ordered
|
||||||
|
}
|
||||||
|
|
||||||
|
// Plugins returns plugin set
|
||||||
|
func (i *InitContext) Plugins() *Set {
|
||||||
|
return i.plugins
|
||||||
|
}
|
||||||
|
|
||||||
// GetAll plugins in the set
|
// GetAll plugins in the set
|
||||||
func (i *InitContext) GetAll() []*Plugin {
|
func (i *InitContext) GetAll() []*Plugin {
|
||||||
return i.plugins.ordered
|
return i.plugins.GetAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetByID returns the plugin of the given type and ID
|
// GetByID returns the plugin of the given type and ID
|
||||||
|
@ -41,12 +41,9 @@ func init() {
|
|||||||
ID: services.IntrospectionService,
|
ID: services.IntrospectionService,
|
||||||
Requires: []plugin.Type{},
|
Requires: []plugin.Type{},
|
||||||
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
||||||
// this service works by using the plugin context up till the point
|
// this service fetches all plugins through the plugin set of the plugin context
|
||||||
// this service is initialized. Since we require this service last,
|
|
||||||
// it should provide the full set of plugins.
|
|
||||||
pluginsPB := pluginsToPB(ic.GetAll())
|
|
||||||
return &Local{
|
return &Local{
|
||||||
plugins: pluginsPB,
|
plugins: ic.Plugins(),
|
||||||
root: ic.Root,
|
root: ic.Root,
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
@ -55,19 +52,19 @@ func init() {
|
|||||||
|
|
||||||
// Local is a local implementation of the introspection service
|
// Local is a local implementation of the introspection service
|
||||||
type Local struct {
|
type Local struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
plugins []api.Plugin
|
root string
|
||||||
root string
|
plugins *plugin.Set
|
||||||
|
pluginCache []api.Plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = (api.IntrospectionClient)(&Local{})
|
var _ = (api.IntrospectionClient)(&Local{})
|
||||||
|
|
||||||
// UpdateLocal updates the local introspection service
|
// UpdateLocal updates the local introspection service
|
||||||
func (l *Local) UpdateLocal(root string, plugins []api.Plugin) {
|
func (l *Local) UpdateLocal(root string) {
|
||||||
l.mu.Lock()
|
l.mu.Lock()
|
||||||
defer l.mu.Unlock()
|
defer l.mu.Unlock()
|
||||||
l.root = root
|
l.root = root
|
||||||
l.plugins = plugins
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plugins returns the locally defined plugins
|
// Plugins returns the locally defined plugins
|
||||||
@ -95,7 +92,11 @@ func (l *Local) Plugins(ctx context.Context, req *api.PluginsRequest, _ ...grpc.
|
|||||||
func (l *Local) getPlugins() []api.Plugin {
|
func (l *Local) getPlugins() []api.Plugin {
|
||||||
l.mu.Lock()
|
l.mu.Lock()
|
||||||
defer l.mu.Unlock()
|
defer l.mu.Unlock()
|
||||||
return l.plugins
|
plugins := l.plugins.GetAll()
|
||||||
|
if l.pluginCache == nil || len(plugins) != len(l.pluginCache) {
|
||||||
|
l.pluginCache = pluginsToPB(plugins)
|
||||||
|
}
|
||||||
|
return l.pluginCache
|
||||||
}
|
}
|
||||||
|
|
||||||
// Server returns the local server information
|
// Server returns the local server information
|
||||||
|
@ -31,11 +31,8 @@ func init() {
|
|||||||
plugin.Register(&plugin.Registration{
|
plugin.Register(&plugin.Registration{
|
||||||
Type: plugin.GRPCPlugin,
|
Type: plugin.GRPCPlugin,
|
||||||
ID: "introspection",
|
ID: "introspection",
|
||||||
Requires: []plugin.Type{"*"},
|
Requires: []plugin.Type{plugin.ServicePlugin},
|
||||||
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
||||||
// this service works by using the plugin context up till the point
|
|
||||||
// this service is initialized. Since we require this service last,
|
|
||||||
// it should provide the full set of plugins.
|
|
||||||
plugins, err := ic.GetByType(plugin.ServicePlugin)
|
plugins, err := ic.GetByType(plugin.ServicePlugin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -50,13 +47,11 @@ func init() {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
allPluginsPB := pluginsToPB(ic.GetAll())
|
|
||||||
|
|
||||||
localClient, ok := i.(*Local)
|
localClient, ok := i.(*Local)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("Could not create a local client for introspection service")
|
return nil, errors.New("Could not create a local client for introspection service")
|
||||||
}
|
}
|
||||||
localClient.UpdateLocal(ic.Root, allPluginsPB)
|
localClient.UpdateLocal(ic.Root)
|
||||||
|
|
||||||
return &server{
|
return &server{
|
||||||
local: localClient,
|
local: localClient,
|
||||||
|
Loading…
Reference in New Issue
Block a user