diff --git a/cmd/lotus/daemon.go b/cmd/lotus/daemon.go index 486ac8ed7..9579d9534 100644 --- a/cmd/lotus/daemon.go +++ b/cmd/lotus/daemon.go @@ -153,6 +153,18 @@ var DaemonCmd = &cli.Command{ Name: "restore-config", 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 { isLite := cctx.Bool("lite") @@ -193,6 +205,12 @@ var DaemonCmd = &cli.Command{ 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(), tag.Insert(metrics.Version, build.BuildVersion), tag.Insert(metrics.Commit, build.CurrentCommit), @@ -319,6 +337,9 @@ var DaemonCmd = &cli.Command{ node.Override(new(dtypes.Bootstrapper), isBootstrapper), 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, liteModeDeps, diff --git a/node/config/doc_gen.go b/node/config/doc_gen.go index fd4ec0366..f22156170 100644 --- a/node/config/doc_gen.go +++ b/node/config/doc_gen.go @@ -537,6 +537,18 @@ Type: Array of multiaddress peerinfo strings, must include peerid (/p2p/12D3K... Name: "ElasticSearchTracer", Type: "string", + Comment: ``, + }, + { + Name: "ElasticSearchIndex", + Type: "string", + + Comment: ``, + }, + { + Name: "TracerSourceAuth", + Type: "string", + Comment: ``, }, }, diff --git a/node/config/types.go b/node/config/types.go index aa061baef..630ae61fd 100644 --- a/node/config/types.go +++ b/node/config/types.go @@ -311,6 +311,7 @@ type Pubsub struct { RemoteTracer string JsonTracerFile string ElasticSearchTracer string + ElasticSearchIndex string TracerSourceAuth string } diff --git a/node/modules/dtypes/tracer.go b/node/modules/dtypes/tracer.go new file mode 100644 index 000000000..622f4baf4 --- /dev/null +++ b/node/modules/dtypes/tracer.go @@ -0,0 +1,5 @@ +package dtypes + +type JsonTracerFile string +type ElasticSearchTracer string +type TracerSourceAuth string diff --git a/node/modules/lp2p/pubsub.go b/node/modules/lp2p/pubsub.go index a8ba126e0..818832562 100644 --- a/node/modules/lp2p/pubsub.go +++ b/node/modules/lp2p/pubsub.go @@ -377,6 +377,7 @@ func GossipSub(in GossipIn) (service *pubsub.PubSub, err error) { if in.Cfg.ElasticSearchTracer != "" { elasticSearchTransport, err := tracer.NewElasticSearchTransport( in.Cfg.ElasticSearchTracer, + in.Cfg.ElasticSearchIndex, ) if err != nil { return nil, err diff --git a/node/modules/tracer/elasticsearch_transport.go b/node/modules/tracer/elasticsearch_transport.go index 8823b8199..d0d7b84a1 100644 --- a/node/modules/tracer/elasticsearch_transport.go +++ b/node/modules/tracer/elasticsearch_transport.go @@ -12,17 +12,21 @@ import ( ) 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) + if err != nil { + return nil, err + } + username := conUrl.User.Username() password, _ := conUrl.User.Password() cfg := elasticsearch.Config{ Addresses: []string{ - "https://" + conUrl.Host, + conUrl.Scheme + "://" + conUrl.Host, }, Username: username, Password: password, @@ -34,13 +38,22 @@ func NewElasticSearchTransport(connectionString string) (TracerTransport, error) return nil, err } + var esIndex string + if elasticsearchIndex != "" { + esIndex = elasticsearchIndex + } else { + esIndex = ElasticSearch_INDEX_DEFAULT + } + return &elasticSearchTransport{ - cl: es, + cl: es, + esIndex: esIndex, }, nil } type elasticSearchTransport struct { - cl *elasticsearch.Client + cl *elasticsearch.Client + esIndex string } func (est *elasticSearchTransport) Transport(evt TracerTransportEvent) error {