Merge pull request #10 from ChainSafe/mmuftic/add-cli-flags
Add cli flags
This commit is contained in:
commit
70e3a9aff8
@ -153,6 +153,18 @@ var DaemonCmd = &cli.Command{
|
|||||||
Name: "restore-config",
|
Name: "restore-config",
|
||||||
Usage: "config file to use when restoring from backup",
|
Usage: "config file to use when restoring from backup",
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "trace-to-json",
|
||||||
|
Usage: "starts tracer and outputs to json file defined with this flag",
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "trace-to-elasticsearch",
|
||||||
|
Usage: "starts tracer and outputs to elasticsearch, flag must contain connection string for elasticsearch",
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "trace-source-auth",
|
||||||
|
Usage: "auth token for trusted source of traces",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
isLite := cctx.Bool("lite")
|
isLite := cctx.Bool("lite")
|
||||||
@ -193,6 +205,12 @@ var DaemonCmd = &cli.Command{
|
|||||||
return fmt.Errorf("unrecognized profile type: %q", profile)
|
return fmt.Errorf("unrecognized profile type: %q", profile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
traceToJsonFile := cctx.String("trace-to-json")
|
||||||
|
|
||||||
|
traceToElasticsearch := cctx.String("trace-to-elasticsearch")
|
||||||
|
|
||||||
|
traceSourceAuth := cctx.String("trace-source-auth")
|
||||||
|
|
||||||
ctx, _ := tag.New(context.Background(),
|
ctx, _ := tag.New(context.Background(),
|
||||||
tag.Insert(metrics.Version, build.BuildVersion),
|
tag.Insert(metrics.Version, build.BuildVersion),
|
||||||
tag.Insert(metrics.Commit, build.CurrentCommit),
|
tag.Insert(metrics.Commit, build.CurrentCommit),
|
||||||
@ -319,6 +337,9 @@ var DaemonCmd = &cli.Command{
|
|||||||
|
|
||||||
node.Override(new(dtypes.Bootstrapper), isBootstrapper),
|
node.Override(new(dtypes.Bootstrapper), isBootstrapper),
|
||||||
node.Override(new(dtypes.ShutdownChan), shutdownChan),
|
node.Override(new(dtypes.ShutdownChan), shutdownChan),
|
||||||
|
node.Override(new(dtypes.JsonTracerFile), traceToJsonFile),
|
||||||
|
node.Override(new(dtypes.ElasticSearchTracer), traceToElasticsearch),
|
||||||
|
node.Override(new(dtypes.TracerSourceAuth), traceSourceAuth),
|
||||||
|
|
||||||
genesis,
|
genesis,
|
||||||
liteModeDeps,
|
liteModeDeps,
|
||||||
|
@ -537,6 +537,18 @@ Type: Array of multiaddress peerinfo strings, must include peerid (/p2p/12D3K...
|
|||||||
Name: "ElasticSearchTracer",
|
Name: "ElasticSearchTracer",
|
||||||
Type: "string",
|
Type: "string",
|
||||||
|
|
||||||
|
Comment: ``,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "ElasticSearchIndex",
|
||||||
|
Type: "string",
|
||||||
|
|
||||||
|
Comment: ``,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "TracerSourceAuth",
|
||||||
|
Type: "string",
|
||||||
|
|
||||||
Comment: ``,
|
Comment: ``,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -311,6 +311,7 @@ type Pubsub struct {
|
|||||||
RemoteTracer string
|
RemoteTracer string
|
||||||
JsonTracerFile string
|
JsonTracerFile string
|
||||||
ElasticSearchTracer string
|
ElasticSearchTracer string
|
||||||
|
ElasticSearchIndex string
|
||||||
TracerSourceAuth string
|
TracerSourceAuth string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
node/modules/dtypes/tracer.go
Normal file
5
node/modules/dtypes/tracer.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package dtypes
|
||||||
|
|
||||||
|
type JsonTracerFile string
|
||||||
|
type ElasticSearchTracer string
|
||||||
|
type TracerSourceAuth string
|
@ -377,6 +377,7 @@ func GossipSub(in GossipIn) (service *pubsub.PubSub, err error) {
|
|||||||
if in.Cfg.ElasticSearchTracer != "" {
|
if in.Cfg.ElasticSearchTracer != "" {
|
||||||
elasticSearchTransport, err := tracer.NewElasticSearchTransport(
|
elasticSearchTransport, err := tracer.NewElasticSearchTransport(
|
||||||
in.Cfg.ElasticSearchTracer,
|
in.Cfg.ElasticSearchTracer,
|
||||||
|
in.Cfg.ElasticSearchIndex,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -12,17 +12,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ElasticSearch_INDEX = "lotus-pubsub"
|
ElasticSearch_INDEX_DEFAULT = "lotus-pubsub"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewElasticSearchTransport(connectionString string) (TracerTransport, error) {
|
func NewElasticSearchTransport(connectionString string, elasticsearchIndex string) (TracerTransport, error) {
|
||||||
conUrl, err := url.Parse(connectionString)
|
conUrl, err := url.Parse(connectionString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
username := conUrl.User.Username()
|
username := conUrl.User.Username()
|
||||||
password, _ := conUrl.User.Password()
|
password, _ := conUrl.User.Password()
|
||||||
cfg := elasticsearch.Config{
|
cfg := elasticsearch.Config{
|
||||||
Addresses: []string{
|
Addresses: []string{
|
||||||
"https://" + conUrl.Host,
|
conUrl.Scheme + "://" + conUrl.Host,
|
||||||
},
|
},
|
||||||
Username: username,
|
Username: username,
|
||||||
Password: password,
|
Password: password,
|
||||||
@ -34,13 +38,22 @@ func NewElasticSearchTransport(connectionString string) (TracerTransport, error)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var esIndex string
|
||||||
|
if elasticsearchIndex != "" {
|
||||||
|
esIndex = elasticsearchIndex
|
||||||
|
} else {
|
||||||
|
esIndex = ElasticSearch_INDEX_DEFAULT
|
||||||
|
}
|
||||||
|
|
||||||
return &elasticSearchTransport{
|
return &elasticSearchTransport{
|
||||||
cl: es,
|
cl: es,
|
||||||
|
esIndex: esIndex,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type elasticSearchTransport struct {
|
type elasticSearchTransport struct {
|
||||||
cl *elasticsearch.Client
|
cl *elasticsearch.Client
|
||||||
|
esIndex string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (est *elasticSearchTransport) Transport(evt TracerTransportEvent) error {
|
func (est *elasticSearchTransport) Transport(evt TracerTransportEvent) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user