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

remove 'ipfs diag net' from codebase #3916

Merged
merged 1 commit into from
May 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ include $(dir)/Rules.mk
dir := exchange/bitswap/message/pb
include $(dir)/Rules.mk

dir := diagnostics/pb
include $(dir)/Rules.mk

dir := pin/internal/pb
include $(dir)/Rules.mk

Expand Down
198 changes: 1 addition & 197 deletions core/commands/diag.go
Original file line number Diff line number Diff line change
@@ -1,210 +1,14 @@
package commands

import (
"bytes"
"errors"
"io"
"strings"
"text/template"
"time"

cmds "github.com/ipfs/go-ipfs/commands"
diag "github.com/ipfs/go-ipfs/diagnostics"
)

type DiagnosticConnection struct {
ID string
// TODO use milliseconds or microseconds for human readability
NanosecondsLatency uint64
Count int
}

var (
visD3 = "d3"
visDot = "dot"
visText = "text"
visFmts = []string{visD3, visDot, visText}
)

type DiagnosticPeer struct {
ID string
UptimeSeconds uint64
BandwidthBytesIn uint64
BandwidthBytesOut uint64
Connections []DiagnosticConnection
}

type DiagnosticOutput struct {
Peers []DiagnosticPeer
}

var DefaultDiagnosticTimeout = time.Second * 20
import cmds "github.com/ipfs/go-ipfs/commands"

var DiagCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Generate diagnostic reports.",
},

Subcommands: map[string]*cmds.Command{
"net": diagNetCmd,
"sys": sysDiagCmd,
"cmds": ActiveReqsCmd,
},
}

var diagNetCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Generate a network diagnostics report.",
ShortDescription: `
Sends out a message to each node in the network recursively
requesting a listing of data about them including number of
connected peers and latencies between them.

The given timeout will be decremented 2s at every network hop,
ensuring peers try to return their diagnostics before the initiator's
timeout. If the timeout is too small, some peers may not be reached.
30s and 60s are reasonable timeout values, though networks vary.
The default timeout is 20 seconds.

The 'vis' option may be used to change the output format.
Three formats are supported:
* text - Easy to read. Default.
* d3 - json ready to be fed into d3view
* dot - graphviz format

The 'd3' format will output a json object ready to be consumed by
the chord network viewer, available at the following hash:

/ipfs/QmbesKpGyQGd5jtJFUGEB1ByPjNFpukhnKZDnkfxUiKn38

To view your diag output, 'ipfs add' the d3 vis output, and
open the following link:

http://gateway.ipfs.io/ipfs/QmbesKpGyQGd5jtJFUGEB1ByPjNFpukhnKZDnkfxUiKn38/chord#<your hash>

The 'dot' format can be fed into graphviz and other programs
that consume the dot format to generate graphs of the network.
`,
},

Options: []cmds.Option{
cmds.StringOption("vis", "Output format. One of: "+strings.Join(visFmts, ", ")).Default(visText),
},

Run: func(req cmds.Request, res cmds.Response) {
n, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

if !n.OnlineMode() {
res.SetError(errNotOnline, cmds.ErrClient)
return
}

vis, _, err := req.Option("vis").String()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

timeoutS, _, err := req.Option("timeout").String()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
timeout := DefaultDiagnosticTimeout
if timeoutS != "" {
t, err := time.ParseDuration(timeoutS)
if err != nil {
res.SetError(errors.New("error parsing timeout"), cmds.ErrNormal)
return
}
timeout = t
}

info, err := n.Diagnostics.GetDiagnostic(req.Context(), timeout)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

switch vis {
case visD3:
res.SetOutput(bytes.NewReader(diag.GetGraphJson(info)))
case visDot:
buf := new(bytes.Buffer)
w := diag.DotWriter{W: buf}
err := w.WriteGraph(info)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
res.SetOutput(io.Reader(buf))
case visText:
output, err := stdDiagOutputMarshal(standardDiagOutput(info))
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
res.SetOutput(output)
default:
res.SetError(err, cmds.ErrNormal)
return
}
},
}

func stdDiagOutputMarshal(output *DiagnosticOutput) (io.Reader, error) {
buf := new(bytes.Buffer)
err := printDiagnostics(buf, output)
if err != nil {
return nil, err
}
return buf, nil
}

func standardDiagOutput(info []*diag.DiagInfo) *DiagnosticOutput {
output := make([]DiagnosticPeer, len(info))
for i, peer := range info {
connections := make([]DiagnosticConnection, len(peer.Connections))
for j, conn := range peer.Connections {
connections[j] = DiagnosticConnection{
ID: conn.ID,
NanosecondsLatency: uint64(conn.Latency.Nanoseconds()),
Count: conn.Count,
}
}

output[i] = DiagnosticPeer{
ID: peer.ID,
UptimeSeconds: uint64(peer.LifeSpan.Seconds()),
BandwidthBytesIn: peer.BwIn,
BandwidthBytesOut: peer.BwOut,
Connections: connections,
}
}
return &DiagnosticOutput{output}
}

func printDiagnostics(out io.Writer, info *DiagnosticOutput) error {
diagTmpl := `
{{ range $peer := .Peers }}
ID {{ $peer.ID }} up {{ $peer.UptimeSeconds }} seconds connected to {{ len .Connections }}:{{ range $connection := .Connections }}
ID {{ $connection.ID }} connections: {{ $connection.Count }} latency: {{ $connection.NanosecondsLatency }} ns{{ end }}
{{end}}
`

templ, err := template.New("DiagnosticOutput").Parse(diagTmpl)
if err != nil {
return err
}

err = templ.Execute(out, info)
if err != nil {
return err
}

return nil
}
29 changes: 0 additions & 29 deletions core/commands/diag_test.go

This file was deleted.

3 changes: 0 additions & 3 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
bserv "github.com/ipfs/go-ipfs/blockservice"
diag "github.com/ipfs/go-ipfs/diagnostics"
exchange "github.com/ipfs/go-ipfs/exchange"
bitswap "github.com/ipfs/go-ipfs/exchange/bitswap"
bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network"
Expand Down Expand Up @@ -127,7 +126,6 @@ type IpfsNode struct {
Routing routing.IpfsRouting // the routing system. recommend ipfs-dht
Exchange exchange.Interface // the block exchange + strategy (bitswap)
Namesys namesys.NameSystem // the name system, resolves paths to hashes
Diagnostics *diag.Diagnostics // the diagnostics service
Ping *ping.PingService
Reprovider *rp.Reprovider // the value reprovider system
IpnsRepub *ipnsrp.Republisher
Expand Down Expand Up @@ -317,7 +315,6 @@ func (n *IpfsNode) HandlePeerFound(p pstore.PeerInfo) {
// initialized with the host and _before_ we start listening.
func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, host p2phost.Host, routingOption RoutingOption) error {
// setup diagnostics service
n.Diagnostics = diag.NewDiagnostics(n.Identity, host)
n.Ping = ping.NewPingService(host)

// setup routing service
Expand Down
16 changes: 0 additions & 16 deletions diagnostics/README.md

This file was deleted.

Loading