Skip to content

Commit

Permalink
support export traces to jaeger (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
zl03jsj authored Jul 21, 2021
1 parent e33108b commit f82dfab
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.idea
.vscode

messager.toml.local
./venus-messager
./*.log
*.db
Expand Down
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"github.com/ipfs-force-community/metrics"
"time"

gatewayTypes "github.com/ipfs-force-community/venus-gateway/types"
Expand All @@ -17,6 +18,7 @@ type Config struct {
Wallet WalletConfig `toml:"wallet"`
Gateway GatewayConfig `toml:"gateway"`
RateLimit RateLimitConfig `toml:"rateLimit"`
Trace metrics.TraceConfig `toml:"tracing"`
}

type NodeConfig struct {
Expand Down Expand Up @@ -137,5 +139,11 @@ func DefaultConfig() *Config {
},
},
RateLimit: RateLimitConfig{Redis: ""},
Trace: metrics.TraceConfig{
JaegerEndpoint: "localhost:6831",
ProbabilitySampler: 1.0,
JaegerTracingEnabled: false,
ServerName: "venus-messenger",
},
}
}
24 changes: 13 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"encoding/hex"
"fmt"
"github.com/filecoin-project/venus-messager/metrics"
"net"
_ "net/http/pprof"
"os"
Expand Down Expand Up @@ -65,7 +66,7 @@ var runCmd = &cli.Command{
Usage: "url for auth server",
},

//node
// node
&cli.StringFlag{
Name: "node-url",
Usage: "url for connection lotus/venus",
Expand All @@ -75,7 +76,7 @@ var runCmd = &cli.Command{
Usage: "token auth for lotus/venus",
},

//database
// database
&cli.StringFlag{
Name: "db-type",
Usage: "which db to use. sqlite/mysql",
Expand Down Expand Up @@ -167,7 +168,6 @@ func runAction(ctx *cli.Context) error {
log.Infof("auth info url: %s\n", cfg.JWT.AuthURL)
log.Infof("gateway info enable: %v, url: %s, token: %s\n", cfg.Gateway.RemoteEnable, cfg.Gateway.Url, cfg.Node.Token)
log.Infof("rate limit info: redis: %s \n", cfg.RateLimit.Redis)

client, closer, err := service.NewNodeClient(ctx.Context, &cfg.Node)
if err != nil {
return xerrors.Errorf("connect to node failed %v", err)
Expand Down Expand Up @@ -205,33 +205,35 @@ func runAction(ctx *cli.Context) error {
shutdownChan := make(chan struct{})
provider := fx.Options(
fx.Logger(fxLogger{log}),
//prover
fx.Supply(cfg, &cfg.DB, &cfg.API, &cfg.JWT, &cfg.Node, &cfg.Log, &cfg.MessageService, &cfg.MessageState, &cfg.Wallet, &cfg.Gateway, &cfg.RateLimit),
// prover
fx.Supply(cfg, &cfg.DB, &cfg.API, &cfg.JWT, &cfg.Node, &cfg.Log, &cfg.MessageService, &cfg.MessageState, &cfg.Wallet, &cfg.Gateway, &cfg.RateLimit, &cfg.Trace),
fx.Supply(log),
fx.Supply(client),
fx.Supply(walletClient),
fx.Supply((ShutdownChan)(shutdownChan)),

fx.Provide(service.NewMessageState),
//db
// db
fx.Provide(models.SetDataBase),
//service
// service
service.MessagerService(),
//api
// api
fx.Provide(api.NewMessageImp),
//jwt
// jwt
fx.Provide(jwt.NewJwtClient),
//middleware

// middleware

fx.Provide(func() net.Listener {
return lst
}),
)

invoker := fx.Options(
//invoke
// invoke
fx.Invoke(models.AutoMigrate),
fx.Invoke(service.StartNodeEvents),
fx.Invoke(metrics.SetupJaeger),
fx.Invoke(api.RunAPI),
)
app := fx.New(gatewayProvider, provider, invoker)
Expand Down
31 changes: 31 additions & 0 deletions metrics/trace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package metrics

import (
"context"
"github.com/ipfs-force-community/metrics"
"go.uber.org/fx"

"github.com/filecoin-project/venus-messager/log"
)

func SetupJaeger(lc fx.Lifecycle, tcfg *metrics.TraceConfig, log *log.Logger) error {
log.Infof("tracing config:enabled: %v, serverName:%s, jaeger-url:%s, sample:%.2f\n",
tcfg.JaegerTracingEnabled, tcfg.ServerName,
tcfg.JaegerEndpoint, tcfg.ProbabilitySampler)

if !tcfg.JaegerTracingEnabled {
return nil
}

exporter, err := metrics.RegisterJaeger(tcfg.ServerName, tcfg)
if err != nil {
return err
}
lc.Append(fx.Hook{
OnStop: func(ctx context.Context) error {
metrics.UnregisterJaeger(exporter)
return nil
},
})
return nil
}

0 comments on commit f82dfab

Please sign in to comment.