0d05cb26bf
* initial commit of inspector gadget wireup * change name of comman dline tool, setup grpc server * Get inspector cli working with grpc client * Wired up CountNodes command * WIP getting buckets response working * Added GetBucket command * WIP working on get buckets command * WIP working on bucket list * Still WIP * WIP getting bucket counts to work * Some clean up of unnecessary changes * List Buckets and Get Bucket are working * Removing logs, getting ready for review * initial commit of inspector gadget wireup * change name of comman dline tool, setup grpc server * Get inspector cli working with grpc client * Wired up CountNodes command * WIP getting buckets response working * Added GetBucket command * WIP working on get buckets command * WIP working on bucket list * Still WIP * WIP getting bucket counts to work * Some clean up of unnecessary changes * List Buckets and Get Bucket are working * Removing logs, getting ready for review * Fix error return * Trying to get tests passing * Adds method on dht mock for tests * Add dbx files back * Fix package import error in dbx file * Adds copyrights to pass linter * tidy go mod * Updates from code review * Updates inspector to take flag arguments for address * Format list-buckets output more prettier
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
// Copyright (C) 2018 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package inspector
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zeebo/errs"
|
|
"go.uber.org/zap"
|
|
monkit "gopkg.in/spacemonkeygo/monkit.v2"
|
|
|
|
"storj.io/storj/pkg/kademlia"
|
|
"storj.io/storj/pkg/overlay"
|
|
"storj.io/storj/pkg/pb"
|
|
"storj.io/storj/pkg/provider"
|
|
)
|
|
|
|
var (
|
|
mon = monkit.Package()
|
|
// Error is the main inspector error class for this package
|
|
Error = errs.Class("inspector server error:")
|
|
)
|
|
|
|
// Config is passed to CaptPlanet for bootup and configuration
|
|
type Config struct {
|
|
Enabled bool `help:"enable or disable the inspector" default:"true"`
|
|
}
|
|
|
|
// Run starts up the server and loads configs
|
|
func (c Config) Run(ctx context.Context, server *provider.Provider) (err error) {
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
kad := kademlia.LoadFromContext(ctx)
|
|
if kad == nil {
|
|
return Error.New("programmer error: kademlia responsibility unstarted")
|
|
}
|
|
|
|
ol := overlay.LoadFromContext(ctx)
|
|
if ol == nil {
|
|
return Error.New("programmer error: overlay responsibility unstarted")
|
|
}
|
|
|
|
srv := &Server{
|
|
dht: kad,
|
|
cache: ol,
|
|
logger: zap.L(),
|
|
metrics: monkit.Default,
|
|
}
|
|
|
|
pb.RegisterInspectorServer(server.GRPC(), srv)
|
|
|
|
return server.Run(ctx)
|
|
}
|