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

experimental introspection support -- Project Phantom Drift PoC #964

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b5a2ce9
host changes for introspection
aarshkshah1992 Jan 22, 2020
ece8853
changes as per review
aarshkshah1992 Jan 24, 2020
ab66df8
changes as per review
aarshkshah1992 Jan 24, 2020
1690b40
fix import issue
aarshkshah1992 Jan 28, 2020
0903bf8
fix nil error in host
aarshkshah1992 Jan 28, 2020
b81aecf
finished introspection changes
aarshkshah1992 Jan 28, 2020
691c345
end to end tests
aarshkshah1992 Jan 29, 2020
570621a
fix fmt
aarshkshah1992 Jan 29, 2020
1f4ed27
reformulate host options for introspection.
raulk Feb 10, 2020
ff247cd
update go.mod (go-libp2p-{introspector,swarm,core}).
raulk Feb 10, 2020
8e9bfcb
Merge branch 'master' into feat/introspection
raulk Feb 10, 2020
866ac1d
making routing host introspectable
aarshkshah1992 Feb 12, 2020
bdb4b04
Merge pull request #794 from aarshkshah1992/feat/routed-host-introspe…
aarshkshah1992 Feb 12, 2020
d7f277a
first draft
aarshkshah1992 Apr 14, 2020
56f8ce3
introspection 2.0
aarshkshah1992 Apr 14, 2020
f8e1fe9
updated introspector deps
aarshkshah1992 Apr 15, 2020
e3aa900
upgraded versions
aarshkshah1992 Apr 15, 2020
49689ea
finish host changes
aarshkshah1992 Apr 16, 2020
cc7b841
finished chages
aarshkshah1992 Apr 17, 2020
9fa05d6
merged master
aarshkshah1992 Apr 17, 2020
00fa286
upgraded introspector
aarshkshah1992 Apr 17, 2020
a6300bc
change encoding of messages
aarshkshah1992 Apr 17, 2020
b317328
swarm should send 0 traffic for now
aarshkshah1992 Apr 23, 2020
dc74d13
timestamping changes
aarshkshah1992 Apr 24, 2020
4a4c3bc
fix conn issue
aarshkshah1992 Apr 24, 2020
0b8a0e5
update introspector and ws endpoint.
raulk Jun 4, 2020
cb231bf
Merge branch 'master' into feat/introspection2.0
raulk Jun 4, 2020
cb6b9c1
minor fixes.
raulk Jun 4, 2020
099c00d
remove replace directives from go.mod.
raulk Jun 4, 2020
3426b7d
update dependencies; minor refactor.
raulk Jun 5, 2020
65fa34d
Merge branch 'master' into feat/introspection2.0
raulk Jun 5, 2020
8c891b9
more tests and polishing.
raulk Jun 5, 2020
a1cc324
minor fixes.
raulk Jun 5, 2020
45f3dd8
fix import nits.
raulk Jun 5, 2020
762d2a9
nits.
raulk Jun 5, 2020
29a83a1
remove unused evalForTest mechanism.
raulk Jun 5, 2020
09b4f33
capture a multierror on close.
raulk Jun 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
changes as per review
  • Loading branch information
aarshkshah1992 committed Jan 24, 2020
commit ece88530ecbb1a53db1dfd6ddd7f04a88241c749
6 changes: 2 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/libp2p/go-libp2p-core/connmgr"
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/host"
coreit "github.com/libp2p/go-libp2p-core/introspection"
"github.com/libp2p/go-libp2p-core/introspect"
"github.com/libp2p/go-libp2p-core/metrics"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
Expand Down Expand Up @@ -80,8 +80,7 @@ type Config struct {
EnableAutoRelay bool
StaticRelays []peer.AddrInfo

Introspector coreit.Introspector
IntrospectionServerAddr string
Introspector introspect.Introspector
}

// NewNode constructs a new libp2p Host from the Config.
Expand Down Expand Up @@ -137,7 +136,6 @@ func (cfg *Config) NewNode(ctx context.Context) (host.Host, error) {
EnablePing: !cfg.DisablePing,
UserAgent: cfg.UserAgent,
Introspector: introspector,
IntrospectionServerAddr: cfg.IntrospectionServerAddr,
})

if err != nil {
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ github.com/libp2p/go-libp2p-core v0.3.0/go.mod h1:ACp3DmS3/N64c2jDzcV429ukDpicbL
github.com/libp2p/go-libp2p-crypto v0.1.0/go.mod h1:sPUokVISZiy+nNuTTH/TY+leRSxnFj/2GLjtOTW90hI=
github.com/libp2p/go-libp2p-discovery v0.2.0 h1:1p3YSOq7VsgaL+xVHPi8XAmtGyas6D2J6rWBEfz/aiY=
github.com/libp2p/go-libp2p-discovery v0.2.0/go.mod h1:s4VGaxYMbw4+4+tsoQTqh7wfxg97AEdo4GYBt6BadWg=
github.com/libp2p/go-libp2p-introspection v0.0.0-20200123110920-ee44b5738886 h1:aCvSYZQ487Xt/ELd6QM4J/Qws5jGy0DmrHwJIUMGi40=
github.com/libp2p/go-libp2p-loggables v0.1.0 h1:h3w8QFfCt2UJl/0/NW4K829HX/0S4KD31PQ7m8UXXO8=
github.com/libp2p/go-libp2p-loggables v0.1.0/go.mod h1:EyumB2Y6PrYjr55Q3/tiJ/o3xoDasoRYM7nOzEpoa90=
github.com/libp2p/go-libp2p-mplex v0.2.0/go.mod h1:Ejl9IyjvXJ0T9iqUTE1jpYATQ9NM3g+OtR+EMMODbKo=
Expand Down
40 changes: 13 additions & 27 deletions p2p/host/basic/basic_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/libp2p/go-libp2p-core/connmgr"
"github.com/libp2p/go-libp2p-core/event"
"github.com/libp2p/go-libp2p-core/host"
coreit "github.com/libp2p/go-libp2p-core/introspection"
"github.com/libp2p/go-libp2p-core/introspect"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/peerstore"
Expand All @@ -37,7 +37,7 @@ import (
// peer (for all addresses).
const maxAddressResolution = 32

var _ coreit.IntrospectorRegistry = (*BasicHost)(nil)
var _ host.IntrospectableHost = (*BasicHost)(nil)

var log = logging.Logger("basichost")

Expand Down Expand Up @@ -94,8 +94,7 @@ type BasicHost struct {
evtLocalProtocolsUpdated event.Emitter
}

// introspector is the host introspector used to register subsystem metric providers & fetch the current system state when asked
introspector coreit.Introspector
introspector introspect.Introspector
}

var _ host.Host = (*BasicHost)(nil)
Expand Down Expand Up @@ -133,10 +132,7 @@ type HostOpts struct {
UserAgent string

// Introspector is used by host subsystems to register themselves as metrics providers & fetch the current state.
Introspector coreit.Introspector

// IntrospectionServerAddr is the address for the introspection server
IntrospectionServerAddr string
Introspector introspect.Introspector
}

// NewHost constructs a new *BasicHost and activates it by attaching its stream and connection handlers to the given inet.Network.
Expand Down Expand Up @@ -202,14 +198,19 @@ func NewHost(ctx context.Context, net network.Network, opts *HostOpts) (*BasicHo
net.SetStreamHandler(h.newStreamHandler)

// register runtime provider
if err := h.introspector.RegisterProviders(&coreit.ProvidersTree{Runtime: h.runtimeDataProvider()}); err != nil {
if err := h.introspector.RegisterProviders(&introspect.ProvidersMap{Runtime: func() (*introspect.Runtime, error) {
return &introspect.Runtime{Implementation: "go-libp2p",
Platform: runtime2.GOOS,
PeerId: h.ID().Pretty(),
}, nil
}}); err != nil {
log.Errorf("failed to register a runtime provider, err=%s", err)
}

// start introspection server
// TODO What happens if address is not configured or not available ?
// TODO How do we configure a "default address"
shutDownFnc := introspection.StartServer(opts.IntrospectionServerAddr, h.introspector)
shutDownFnc := introspection.StartServer(h.introspector)

h.proc = goprocessctx.WithContextAndTeardown(ctx, func() error {
if h.natmgr != nil {
Expand All @@ -230,16 +231,8 @@ func NewHost(ctx context.Context, net network.Network, opts *HostOpts) (*BasicHo
return h, nil
}

func (h *BasicHost) runtimeDataProvider() *coreit.RuntimeProviders {
// TODO What is the version here ?
runtime := &coreit.Runtime{Implementation: "go-libp2p",
Platform: runtime2.GOOS,
PeerId: h.ID().Pretty(),
}

return &coreit.RuntimeProviders{Get: func() (*coreit.Runtime, error) {
return runtime, nil
}}
func (h *BasicHost) Introspector() introspect.Introspector {
return h.introspector
}

// New constructs and sets up a new *BasicHost with given Network and options.
Expand Down Expand Up @@ -828,13 +821,6 @@ func (h *BasicHost) AllAddrs() []ma.Multiaddr {
return dedupAddrs(finalAddrs)
}

// TODO Do this for routed & relay hosts as well
// RegisterProvider allows the host to be an IntrospectorRegistry. Please look at the docs for the IntrospectorRegistry
// interface in go-libp2p-core for more details.
func (h *BasicHost) RegisterProviders(p *coreit.ProvidersTree) error {
return h.introspector.RegisterProviders(p)
}

// Close shuts down the Host's services (network, etc).
func (h *BasicHost) Close() error {
// You're thinking of adding some teardown logic here, right? Well
Expand Down