Code cleanup
This commit is contained in:
parent
e20cd0ef27
commit
707faf57b5
@ -374,7 +374,9 @@ func GossipSub(in GossipIn) (service *pubsub.PubSub, err error) {
|
|||||||
}
|
}
|
||||||
jsonTransport := tracer.NewJsonTracerTransport(out)
|
jsonTransport := tracer.NewJsonTracerTransport(out)
|
||||||
transports = append(transports, jsonTransport)
|
transports = append(transports, jsonTransport)
|
||||||
} else if in.Cfg.ElasticSearchTracer != "" {
|
}
|
||||||
|
|
||||||
|
if in.Cfg.ElasticSearchTracer != "" {
|
||||||
elasticSearchTransport, err := tracer.NewElasticSearchTransport()
|
elasticSearchTransport, err := tracer.NewElasticSearchTransport()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -8,10 +8,11 @@ import (
|
|||||||
|
|
||||||
"github.com/elastic/go-elasticsearch/v7"
|
"github.com/elastic/go-elasticsearch/v7"
|
||||||
"github.com/elastic/go-elasticsearch/v7/esapi"
|
"github.com/elastic/go-elasticsearch/v7/esapi"
|
||||||
logging "github.com/ipfs/go-log/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var rpclog = logging.Logger("elasticsearch")
|
const (
|
||||||
|
ElasticSearch_INDEX = "pubsub"
|
||||||
|
)
|
||||||
|
|
||||||
func NewElasticSearchTransport() (TracerTransport, error) {
|
func NewElasticSearchTransport() (TracerTransport, error) {
|
||||||
es, err := elasticsearch.NewDefaultClient()
|
es, err := elasticsearch.NewDefaultClient()
|
||||||
@ -31,7 +32,7 @@ type elasticSearchTransport struct {
|
|||||||
|
|
||||||
func (est *elasticSearchTransport) Transport(jsonEvent []byte) error {
|
func (est *elasticSearchTransport) Transport(jsonEvent []byte) error {
|
||||||
req := esapi.IndexRequest{
|
req := esapi.IndexRequest{
|
||||||
Index: "PeerScore",
|
Index: ElasticSearch_INDEX,
|
||||||
DocumentID: "1", // todo
|
DocumentID: "1", // todo
|
||||||
Body: strings.NewReader(string(jsonEvent)),
|
Body: strings.NewReader(string(jsonEvent)),
|
||||||
Refresh: "true",
|
Refresh: "true",
|
||||||
@ -51,8 +52,6 @@ func (est *elasticSearchTransport) Transport(jsonEvent []byte) error {
|
|||||||
var r map[string]interface{}
|
var r map[string]interface{}
|
||||||
if err := json.NewDecoder(res.Body).Decode(&r); err != nil {
|
if err := json.NewDecoder(res.Body).Decode(&r); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
rpclog.Infof("[%s] %s; version=%d", res.Status(), r["result"], int(r["_version"].(float64)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user