Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
Introspection types for core (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 authored and raulk committed Feb 10, 2020
1 parent e075dc9 commit c72a961
Show file tree
Hide file tree
Showing 9 changed files with 7,470 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require (
github.com/btcsuite/btcd v0.20.1-beta
github.com/coreos/go-semver v0.3.0
github.com/gogo/protobuf v1.3.1
github.com/golang/protobuf v1.3.2
github.com/ipfs/go-cid v0.0.4
github.com/jbenet/goprocess v0.1.3
github.com/libp2p/go-flow-metrics v0.0.3
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 h1:ZgQEtGgCBiWRM
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/gxed/hashland/keccakpg v0.0.1 h1:wrk3uMNaMxbXiHibbPO4S0ymqJMm41WiudyFSs7UnsU=
Expand Down
12 changes: 12 additions & 0 deletions host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/libp2p/go-libp2p-core/connmgr"
"github.com/libp2p/go-libp2p-core/event"
"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 Down Expand Up @@ -73,3 +74,14 @@ type Host interface {
// EventBus returns the hosts eventbus
EventBus() event.Bus
}

// IntrospectableHost is implemented by Host implementations that are
// introspectable, that is, that expose an introspection server.
type IntrospectableHost interface {

// Introspector returns the Introspector instance, with which the caller
// can:
// - register data providers.
// - fetch introspection data.
Introspector() introspect.Introspector
}
9 changes: 9 additions & 0 deletions introspect/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Package introspect is EXPERIMENTAL. It is subject to heavy change, and it
// WILL change. For now, it is the simplest implementation to power the
// proof-of-concept of the libp2p introspection framework.
//
// Package introspect contains the abstract skeleton of the introspection system
// of go-libp2p. It holds the introspection data schema, and the primitives that
// allow subsystems to register data providers, and clients to fetch the current
// state of the system.
package introspect
25 changes: 25 additions & 0 deletions introspect/introspect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package introspect

import introspect_pb "github.com/libp2p/go-libp2p-core/introspect/pb"

// ProtoVersion is the current version of the introspection protocol.
const ProtoVersion uint32 = 1

// EXPERIMENTAL. Introspector allows other sub-systems/modules to register
// metrics/data providers AND also enables clients to fetch the current state of
// the system.
type Introspector interface {

// EXPERIMENTAL. RegisterDataProviders allows sub-systems/modules to
// register callbacks that supply introspection data.
RegisterDataProviders(p *DataProviders) error

// EXPERIMENTAL. FetchFullState returns the full state of the system, by
// calling all known data providers and returning a merged cross-cut of the
// running system.
FetchFullState() (*introspect_pb.State, error)

// EXPERIMENTAL. ListenAddrs returns the addresses on which the
// introspection server endpoint is listening for clients.
ListenAddrs() []string
}
11 changes: 11 additions & 0 deletions introspect/pb/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
PB = $(wildcard *.proto)
GO = $(PB:.proto=.pb.go)

all: $(GO)

%.pb.go: %.proto
protoc --proto_path=$(PWD):$(PWD)/../..:$(GOPATH)/src --gogofaster_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types:. $<

clean:
rm -f *.pb.go
rm -f *.go
Loading

0 comments on commit c72a961

Please sign in to comment.