Move index name to config only and add default value
This commit is contained in:
parent
22bbb113e7
commit
4438c4bd87
@ -161,10 +161,6 @@ var DaemonCmd = &cli.Command{
|
|||||||
Name: "trace-to-elasticsearch",
|
Name: "trace-to-elasticsearch",
|
||||||
Usage: "starts tracer and outputs to elasticsearch, flag must contain connection string for elasticsearch",
|
Usage: "starts tracer and outputs to elasticsearch, flag must contain connection string for elasticsearch",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "elasticsearch-index",
|
|
||||||
Usage: "configure elasticearch index name if elasticsearch tracer is configured",
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "trace-source-auth",
|
Name: "trace-source-auth",
|
||||||
Usage: "auth token for trusted source of traces",
|
Usage: "auth token for trusted source of traces",
|
||||||
@ -213,8 +209,6 @@ var DaemonCmd = &cli.Command{
|
|||||||
|
|
||||||
traceToElasticsearch := cctx.String("trace-to-elasticsearch")
|
traceToElasticsearch := cctx.String("trace-to-elasticsearch")
|
||||||
|
|
||||||
elasticsearchIndex := cctx.String("elasticsearch-index")
|
|
||||||
|
|
||||||
traceSourceAuth := cctx.String("trace-source-auth")
|
traceSourceAuth := cctx.String("trace-source-auth")
|
||||||
|
|
||||||
ctx, _ := tag.New(context.Background(),
|
ctx, _ := tag.New(context.Background(),
|
||||||
@ -345,7 +339,6 @@ var DaemonCmd = &cli.Command{
|
|||||||
node.Override(new(dtypes.ShutdownChan), shutdownChan),
|
node.Override(new(dtypes.ShutdownChan), shutdownChan),
|
||||||
node.Override(new(dtypes.JsonTracerFile), traceToJsonFile),
|
node.Override(new(dtypes.JsonTracerFile), traceToJsonFile),
|
||||||
node.Override(new(dtypes.ElasticSearchTracer), traceToElasticsearch),
|
node.Override(new(dtypes.ElasticSearchTracer), traceToElasticsearch),
|
||||||
node.Override(new(dtypes.ElasticSearchTracer), elasticsearchIndex),
|
|
||||||
node.Override(new(dtypes.TracerSourceAuth), traceSourceAuth),
|
node.Override(new(dtypes.TracerSourceAuth), traceSourceAuth),
|
||||||
|
|
||||||
genesis,
|
genesis,
|
||||||
|
@ -2,5 +2,4 @@ package dtypes
|
|||||||
|
|
||||||
type JsonTracerFile string
|
type JsonTracerFile string
|
||||||
type ElasticSearchTracer string
|
type ElasticSearchTracer string
|
||||||
type ElasticSearchIndex string
|
|
||||||
type TracerSourceAuth 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,10 +12,10 @@ 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 {
|
if err != nil {
|
||||||
@ -38,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