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

Stateful plugin loading #4806

Merged
merged 1 commit into from
Dec 18, 2018
Merged

Conversation

PlayerWithoutName
Copy link
Contributor

@PlayerWithoutName PlayerWithoutName commented Mar 10, 2018

Depends on #4506

The plugins are currently loaded during Executor creation, which takes some extensibility from them. This PR makes them 'stateful', which will allow for more flexibility.

@PlayerWithoutName PlayerWithoutName force-pushed the feat/plugins/loader branch 4 times, most recently from 9985522 to 0349fb8 Compare March 10, 2018 20:40
Copy link
Member

@magik6k magik6k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nitpicks, overall LGTM.

This could be used to solve the config problem from #4506 (comment) in a quite non-hacky way.

I wonder what impact this will have on the command execution perf as afaik we don't load plugins when executing commands on the daemon. On the other hand we might end up doing that anyways if command-plugins ever become a thing.

cmd/ipfs/main.go Outdated
@@ -112,6 +112,31 @@ func mainRet() int {
}
log.Debugf("config path is %s", repoPath)

pluginpath := filepath.Join(repoPath, "plugins")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could wrap this whole code block into a separate function like loadPlugins

cmd/ipfs/main.go Outdated
}

err = plugins.Initialize()
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a function returns only a single error you can collapse it into if err := plugins.Initialize(); err != nil {

core/builder.go Outdated
@@ -15,6 +15,7 @@ import (
dag "github.com/ipfs/go-ipfs/merkledag"
resolver "github.com/ipfs/go-ipfs/path/resolver"
pin "github.com/ipfs/go-ipfs/pin"
"github.com/ipfs/go-ipfs/plugin/loader"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed prefix

@Kubuxu
Copy link
Member

Kubuxu commented Mar 10, 2018

The ConstructNode isn't the right place to pass this information. ConstructNode will not be called when running ipfs daemon so the Plugins can't be passed to the core node itself or used by anything really.

The problem we are having here is: want want to use plugins pre and post commands lib execution. Best course of action I see here is adding Plugins variable to oldcmds.Context.

This way the plugins can be loaded before command execution and then used latter with created core.Node.

@Stebalien what do you think?

@Kubuxu Kubuxu added the need/author-input Needs input from the original author label Mar 12, 2018
@PlayerWithoutName PlayerWithoutName force-pushed the feat/plugins/loader branch 2 times, most recently from e51dee1 to fbbf41c Compare March 12, 2018 19:56
@magik6k magik6k removed the need/author-input Needs input from the original author label Mar 12, 2018
@Kubuxu Kubuxu requested a review from Stebalien March 13, 2018 19:05
@whyrusleeping
Copy link
Member

cc @frrist

@Kubuxu
Copy link
Member

Kubuxu commented Mar 14, 2018

It might help with Tracing API as you will be able to access config, just at latter stage after initial Run to the plugin. We could also make Init run before node and Run after the node is created but you won't be able to pass core.Node instance due to circular dependency.

@frrist
Copy link
Member

frrist commented Mar 15, 2018

The main reason for needing access to the nodes config was to determine the peerId of the node running the plugin, this was how we were going to name the tracer.
Currently this is being solved via an env variable since as @magik6k pointed out, the peerId may not be available if ipfs init hasn't been ran. If this allows us to pass the nodes config to a plugin after the node has been initialized that would be great!

@PlayerWithoutName
Copy link
Contributor Author

Yeah, i think after this, you could create like ConfigConsumer interface, implement it on the tracing plugin, then create a method that provides the config for all the plugins that implement that interface and you should be good.

@Kubuxu
Copy link
Member

Kubuxu commented Mar 20, 2018

@PlayerWithoutName could you rebase your PR. To solve conflicts with other PR (#4506 ) please base it on feat/opentrace branch.

@Kubuxu Kubuxu added the status/in-progress In progress label Mar 20, 2018
@Kubuxu Kubuxu assigned Kubuxu and unassigned Kubuxu Mar 20, 2018
@Kubuxu Kubuxu added need/author-input Needs input from the original author and removed status/in-progress In progress labels Mar 23, 2018
@PlayerWithoutName PlayerWithoutName force-pushed the feat/plugins/loader branch 3 times, most recently from 0f40a97 to aea981a Compare March 25, 2018 21:16
@magik6k magik6k removed the need/author-input Needs input from the original author label Mar 25, 2018
@@ -18,6 +19,7 @@ type Context struct {
Online bool
ConfigRoot string
ReqLog *ReqLog
Plugins *loader.PluginLoader
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd separate this with a newline from the group above.

}
// Initialize all the loaded plugins
func (loader *PluginLoader) Initialize() error {
return initialize(loader.plugins)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just put these funcs on the struct directly?

Copy link
Member

@Kubuxu Kubuxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from 2 nitpicks that @magik6k pointed out SGWM.

@PlayerWithoutName PlayerWithoutName force-pushed the feat/plugins/loader branch 2 times, most recently from 2bb74de to 8b45855 Compare April 14, 2018 21:36
func run(plugins []plugin.Plugin) error {
for _, pl := range plugins {
//Run the plugins
func (loader *PluginLoader) Run() error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good practice to keep the implementation of given structure in one package.
In this case, it means keeping those functions in one file with the definition of the struct.

@Kubuxu Kubuxu added the RFM label Apr 17, 2018
@Kubuxu
Copy link
Member

Kubuxu commented Apr 17, 2018

@Stebalien want to review this?

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I do worry about the perf implications of loading plugins on the client but:

  1. Most plugins should do most of their work on-demand anyways.
  2. Ideally, we'd want to run IPLD plugins on the client.

@whyrusleeping
Copy link
Member

@Kubuxu this one needs a rebase. Then i'll merge it in

@PlayerWithoutName
Copy link
Contributor Author

Rebased

cmd/ipfs/main.go Outdated
@@ -47,6 +47,44 @@ const (
heapProfile = "ipfs.memprof"
)

type cmdInvocation struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like some code that got deleted in another PR is getting reintroduced here. cc @magik6k

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, it was legacy code accidentally put up with second commit.

@Stebalien
Copy link
Member

Rebased... will merge if I can get the tests to pass.

License: MIT
Signed-off-by: Kacper Łukawski <kacluk98@gmail.com>
@Stebalien Stebalien merged commit 5866e6a into ipfs:master Dec 18, 2018
@ghost ghost removed the status/in-progress In progress label Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants