Skip to content

Commit

Permalink
Merge pull request #10 from ChainSafe/mmuftic/add-cli-flags
Browse files Browse the repository at this point in the history
Add cli flags
  • Loading branch information
Matija Petrunić authored Sep 24, 2021
2 parents 0c390d1 + 4438c4b commit 70e3a9a
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 5 deletions.
21 changes: 21 additions & 0 deletions cmd/lotus/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions node/config/doc_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ type Pubsub struct {
RemoteTracer string
JsonTracerFile string
ElasticSearchTracer string
ElasticSearchIndex string
TracerSourceAuth string
}

Expand Down
5 changes: 5 additions & 0 deletions node/modules/dtypes/tracer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dtypes

type JsonTracerFile string
type ElasticSearchTracer string
type TracerSourceAuth string
1 change: 1 addition & 0 deletions node/modules/lp2p/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 18 additions & 5 deletions node/modules/tracer/elasticsearch_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down

0 comments on commit 70e3a9a

Please sign in to comment.