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

Add Opentracing plugin support #4506

Merged
merged 1 commit into from
Mar 25, 2018
Merged

Add Opentracing plugin support #4506

merged 1 commit into from
Mar 25, 2018

Conversation

frrist
Copy link
Member

@frrist frrist commented Dec 19, 2017

define an interface for creating and configuring tracers
add the Jaeger tracer as a plugin

License: MIT
Signed-off-by: ForrestWeston forrest@protocol.ai

@ghost ghost assigned frrist Dec 19, 2017
@ghost ghost added the status/in-progress In progress label Dec 19, 2017
@frrist
Copy link
Member Author

frrist commented Dec 19, 2017

Points worth noting:

  • Plugins do not work on windows.
    - Jaeger should be version controlled (currently its not), not sure how to accomplish this yet.
  • To start the Jaeger UI (lets you view traces, spans, and their metadata)
docker run -p5775:5775/udp -p6831:6831/udp -p6832:6832/udp \                                                                                                     Tue Dec 19 18:57:00 UTC 2017
    -p5778:5778 -p16686:16686 -p14268:14268 -p9411:9411 jaegertracing/all-in-one:0.8.0

- To actually use this you need to have a few different branches checked out and packages linked, will add a how-to for that shortly.

@frrist
Copy link
Member Author

frrist commented Dec 19, 2017

Not sure what's going wrong with Jenkins here, the plugin isn't enabled in the PR, and it looks like all tests pass (not sure on the exit code though):

# passed all 243 test(s)
1..243
script returned exit code 2

@@ -41,3 +52,15 @@ func runIPLDPlugin(pl plugin.Plugin) error {

return ipldpl.RegisterInputEncParsers(coredag.DefaultInputEncParsers)
}

func runTracerPlugin(pl plugin.Plugin) error {
Copy link
Member

Choose a reason for hiding this comment

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

since we're doing a type cast above, we can make this function just accept a PluginTracer and skip the cast here. Should do the same for the ipld one too

}

//Initalize a Jaeger tracer and set it as the global tracer in opentracing api
func (*jaegerPlugin) InitGlobalTracer(cfg map[string]interface{}) error {
Copy link
Member

Choose a reason for hiding this comment

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

we should probably use values from the cfg input in the configuration we do here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I think instead of using a cfg we should define tracer specific options in the plugins themselves, since config values can differ across different tracer implementations.

return err
switch pl.(type) {
case plugin.PluginIPLD:
err := runIPLDPlugin(pl.(plugin.PluginIPLD))
Copy link
Member

Choose a reason for hiding this comment

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

no need to do the cast here, the type switch does some magic for you.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are we sure about this? building with err := runIPLDPlugin(pl) instead of err := runIPLDPlugin(pl.(plugin.PluginIPLD)) fails

Copy link
Member Author

Choose a reason for hiding this comment

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

plugin/loader/initializer.go:26:24: cannot use pl (type "github.com/ipfs/go-ipfs/plugin".Plugin) as type "github.com/ipfs/go-ipfs/plugin".PluginIPLD in argument to runIPLDPlugin:
        "github.com/ipfs/go-ipfs/plugin".Plugin does not implement "github.com/ipfs/go-ipfs/plugin".PluginIPLD (missing RegisterBlockDecoders method)

Copy link
Member

Choose a reason for hiding this comment

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

Ah, i forgot one bit, it needs to be:

switch pl := pl.(type) {

}

func runTracerPlugin(pl plugin.PluginTracer) error {
err := pl.InitGlobalTracer()
Copy link
Member

Choose a reason for hiding this comment

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

To make type checks easier, I would do:

tr, err := pl.GetTracer()
if err != nil {
  return err
}
opentrace.SetGlobalTracer(tr)

That way if the types in your plugin are wrong, this won't fail silently, it will hit type assertion issues and throw an error.

cmd/ipfs/main.go Outdated

// check if repo is accessible before loading plugins
ok, err := checkPermissions(cctx.ConfigRoot)
if err != nil {
return nil, err
}
if ok {
if _, err := loader.LoadPlugins(pluginpath); err != nil {
if _, err := loader.LoadPlugins(cctx.ConfigRoot); 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.

Hrm... making that code open up and parse the config on its own breaks some abstractions. The fact that the config is a file on disk is an implementation detail, We might need to rethink some things here.

cc @Stebalien @magik6k We need to get some configuration, and the peer ID to the tracing plugin. I'm not entirely sure yet how that should get fed through, ideas?

Copy link
Member Author

Choose a reason for hiding this comment

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

For some context, here is how it may be used with the tracing plugin
https://github.com/ipfs/go-jaeger-plugin/pull/1/files#diff-e92ca16875e3c00b8a36338613029bf9R35

Copy link
Member

Choose a reason for hiding this comment

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

This will also break changes in https://github.com/ipfs/go-ipfs/pull/4244/files#diff-153cb71153ee178fe2869148600ce8d5R197.

The problem is that at this stage we may not even have a peerID/config (i.e. user calling ipfs init), we may add some sort of late init for plugins that want it and call that above in buildEnv, either before or after calling core.NewNode

Copy link
Member Author

Choose a reason for hiding this comment

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

For now setting the tracer name could be a manual process - maybe we don't want it to be the nodeID, I was doing this for convenience.

This would still be done via a configuration file (where the tracer name is a field), but that file would reside in the plugin path - possibly under a directory based on the plugin name (e.g. pluginPath/pluginName/config.cfg).

I imagine we will want the ability to pass plugins config files in the future?

@frrist frrist force-pushed the feat/opentrace branch 2 times, most recently from 1003957 to 179e64a Compare February 28, 2018 20:54
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. This interface may need to change while implementing/reviewing the plugin itself but this looks like a good baseline.

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.

LGTM

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.

1 nitpick, rest LGTM

@@ -3,6 +3,7 @@ package loader
import (
"github.com/ipfs/go-ipfs/core/coredag"
"github.com/ipfs/go-ipfs/plugin"
"gx/ipfs/QmWLWmRVSiagqP15jczsGME1qpob6HDbtbHAY2he9W5iUo/opentracing-go"
Copy link
Member

Choose a reason for hiding this comment

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

Import grouping

@Kubuxu Kubuxu added RFM and removed status/in-progress In progress labels Mar 10, 2018
@Kubuxu Kubuxu added this to the go-ipfs 0.4.15 milestone Mar 10, 2018
@ghost ghost assigned Kubuxu Mar 20, 2018
@ghost ghost added the status/in-progress In progress label Mar 20, 2018
@Kubuxu Kubuxu mentioned this pull request Mar 20, 2018
@Kubuxu
Copy link
Member

Kubuxu commented Mar 20, 2018

I've rebased it on top of the master to allow #4806 to base off it.

@Kubuxu Kubuxu removed the RFM label Mar 20, 2018
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.

I would say: let's merge it and allow #4806 to improve it in future.

@Kubuxu Kubuxu added RFM and removed status/in-progress In progress labels Mar 23, 2018
define interface for creating tracers for use with opentracing-api

License: MIT
Signed-off-by: ForrestWeston <forrest@protocol.ai>
@ghost ghost added the status/in-progress In progress label Mar 25, 2018
@whyrusleeping whyrusleeping merged commit 7badbeb into master Mar 25, 2018
@whyrusleeping whyrusleeping deleted the feat/opentrace branch March 25, 2018 21:04
@ghost ghost removed the status/in-progress In progress label Mar 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants