Skip to content

Commit d3ff8e7

Browse files
authoredApr 16, 2024··
feat!: replace the influx tracer with a local one (#1290)
manual of backport of #1279
1 parent 9c7b49f commit d3ff8e7

34 files changed

+1299
-949
lines changed
 

‎.golangci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ linters:
66
enable:
77
- asciicheck
88
- bodyclose
9-
- depguard
109
- dogsled
1110
- dupl
1211
- errcheck

‎cmd/cometbft/commands/run_node.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ func AddNodeFlags(cmd *cobra.Command) {
9696
"database directory")
9797

9898
cmd.PersistentFlags().String(
99-
trace.FlagInfluxDBURL,
100-
config.Instrumentation.InfluxURL,
101-
trace.FlagInfluxDBURLDescription,
99+
trace.FlagTracePushConfig,
100+
config.Instrumentation.TracePushConfig,
101+
trace.FlagTracePushConfigDescription,
102102
)
103103

104104
cmd.PersistentFlags().String(
105-
trace.FlagInfluxDBToken,
106-
config.Instrumentation.InfluxToken,
107-
trace.FlagInfluxDBTokenDescription,
105+
trace.FlagTracePullAddress,
106+
config.Instrumentation.TracePullAddress,
107+
trace.FlagTracePullAddressDescription,
108108
)
109109

110110
cmd.PersistentFlags().String(

‎config/config.go

+26-29
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ var (
6262
minSubscriptionBufferSize = 100
6363
defaultSubscriptionBufferSize = 200
6464

65-
// DefaultInfluxTables is a list of tables that are used for storing traces.
65+
// DefaultTracingTables is a list of tables that are used for storing traces.
6666
// This global var is filled by an init function in the schema package. This
6767
// allows for the schema package to contain all the relevant logic while
6868
// avoiding import cycles.
69-
DefaultInfluxTables = []string{}
69+
DefaultTracingTables = ""
7070
)
7171

7272
// Config defines the top level configuration for a CometBFT node
@@ -1188,24 +1188,24 @@ type InstrumentationConfig struct {
11881188
// Instrumentation namespace.
11891189
Namespace string `mapstructure:"namespace"`
11901190

1191-
// InfluxURL is the influxdb url.
1192-
InfluxURL string `mapstructure:"influx_url"`
1191+
// TracePushConfig is the relative path of the push config. This second
1192+
// config contains credentials for where and how often to.
1193+
TracePushConfig string `mapstructure:"trace_push_config"`
11931194

1194-
// InfluxToken is the influxdb token.
1195-
InfluxToken string `mapstructure:"influx_token"`
1195+
// TracePullAddress is the address that the trace server will listen on for
1196+
// pulling data.
1197+
TracePullAddress string `mapstructure:"trace_pull_address"`
11961198

1197-
// InfluxOrg is the influxdb organization.
1198-
InfluxOrg string `mapstructure:"influx_org"`
1199+
// TraceType is the type of tracer used. Options are "local" and "noop".
1200+
TraceType string `mapstructure:"trace_type"`
11991201

1200-
// InfluxBucket is the influxdb bucket.
1201-
InfluxBucket string `mapstructure:"influx_bucket"`
1202+
// TraceBufferSize is the number of traces to write in a single batch.
1203+
TraceBufferSize int `mapstructure:"trace_push_batch_size"`
12021204

1203-
// InfluxBatchSize is the number of points to write in a single batch.
1204-
InfluxBatchSize int `mapstructure:"influx_batch_size"`
1205-
1206-
// InfluxTables is the list of tables that will be traced. See the
1207-
// pkg/trace/schema for a complete list of tables.
1208-
InfluxTables []string `mapstructure:"influx_tables"`
1205+
// TracingTables is the list of tables that will be traced. See the
1206+
// pkg/trace/schema for a complete list of tables. It is represented as a
1207+
// comma separate string. For example: "consensus_round_state,mempool_tx".
1208+
TracingTables string `mapstructure:"tracing_tables"`
12091209

12101210
// PyroscopeURL is the pyroscope url used to establish a connection with a
12111211
// pyroscope continuous profiling server.
@@ -1229,11 +1229,11 @@ func DefaultInstrumentationConfig() *InstrumentationConfig {
12291229
PrometheusListenAddr: ":26660",
12301230
MaxOpenConnections: 3,
12311231
Namespace: "cometbft",
1232-
InfluxURL: "",
1233-
InfluxOrg: "celestia",
1234-
InfluxBucket: "e2e",
1235-
InfluxBatchSize: 20,
1236-
InfluxTables: DefaultInfluxTables,
1232+
TracePushConfig: "",
1233+
TracePullAddress: "",
1234+
TraceType: "noop",
1235+
TraceBufferSize: 1000,
1236+
TracingTables: DefaultTracingTables,
12371237
PyroscopeURL: "",
12381238
PyroscopeTrace: false,
12391239
PyroscopeProfileTypes: []string{
@@ -1264,21 +1264,18 @@ func (cfg *InstrumentationConfig) ValidateBasic() error {
12641264
if cfg.PyroscopeTrace && cfg.PyroscopeURL == "" {
12651265
return errors.New("pyroscope_trace can't be enabled if profiling is disabled")
12661266
}
1267-
// if there is not InfluxURL configured, then we do not need to validate the rest
1267+
// if there is not TracePushConfig configured, then we do not need to validate the rest
12681268
// of the config because we are not connecting.
1269-
if cfg.InfluxURL == "" {
1269+
if cfg.TracePushConfig == "" {
12701270
return nil
12711271
}
1272-
if cfg.InfluxToken == "" {
1272+
if cfg.TracePullAddress == "" {
12731273
return fmt.Errorf("token is required")
12741274
}
1275-
if cfg.InfluxOrg == "" {
1275+
if cfg.TraceType == "" {
12761276
return fmt.Errorf("org is required")
12771277
}
1278-
if cfg.InfluxBucket == "" {
1279-
return fmt.Errorf("bucket is required")
1280-
}
1281-
if cfg.InfluxBatchSize <= 0 {
1278+
if cfg.TraceBufferSize <= 0 {
12821279
return fmt.Errorf("batch size must be greater than 0")
12831280
}
12841281
return nil

‎config/toml.go

+14-13
Original file line numberDiff line numberDiff line change
@@ -547,25 +547,26 @@ max_open_connections = {{ .Instrumentation.MaxOpenConnections }}
547547
# Instrumentation namespace
548548
namespace = "{{ .Instrumentation.Namespace }}"
549549
550-
# The URL of the influxdb instance to use for remote event
551-
# collection. If empty, remote event collection is disabled.
552-
influx_url = "{{ .Instrumentation.InfluxURL }}"
550+
# TracePushConfig is the relative path of the push config.
551+
# This second config contains credentials for where and how often to
552+
# push trace data to. For example, if the config is next to this config,
553+
# it would be "push_config.json".
554+
trace_push_config = "{{ .Instrumentation.TracePushConfig }}"
553555
554-
# The influxdb token to use for remote event collection.
555-
influx_token = "{{ .Instrumentation.InfluxToken }}"
556+
# The tracer pull address specifies which address will be used for pull based
557+
# event collection. If empty, the pull based server will not be started.
558+
trace_pull_address = "{{ .Instrumentation.TracePullAddress }}"
556559
557-
# The influxdb bucket to use for remote event collection.
558-
influx_bucket = "{{ .Instrumentation.InfluxBucket }}"
559-
560-
# The influxdb org to use for event remote collection.
561-
influx_org = "{{ .Instrumentation.InfluxOrg }}"
560+
# The tracer to use for collecting trace data.
561+
trace_type = "{{ .Instrumentation.TraceType }}"
562562
563563
# The size of the batches that are sent to the database.
564-
influx_batch_size = {{ .Instrumentation.InfluxBatchSize }}
564+
trace_push_batch_size = {{ .Instrumentation.TraceBufferSize }}
565565
566566
# The list of tables that are updated when tracing. All available tables and
567-
# their schema can be found in the pkg/trace/schema package.
568-
influx_tables = [{{ range .Instrumentation.InfluxTables }}{{ printf "%q, " . }}{{end}}]
567+
# their schema can be found in the pkg/trace/schema package. It is represented as a
568+
# comma separate string. For example: "consensus_round_state,mempool_tx".
569+
tracing_tables = "{{ .Instrumentation.TracingTables }}"
569570
570571
# The URL of the pyroscope instance to use for continuous profiling.
571572
# If empty, continuous profiling is disabled.

‎consensus/reactor.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type Reactor struct {
5050
rs *cstypes.RoundState
5151

5252
Metrics *Metrics
53-
traceClient *trace.Client
53+
traceClient trace.Tracer
5454
}
5555

5656
type ReactorOption func(*Reactor)
@@ -63,7 +63,7 @@ func NewReactor(consensusState *State, waitSync bool, options ...ReactorOption)
6363
waitSync: waitSync,
6464
rs: consensusState.GetRoundState(),
6565
Metrics: NopMetrics(),
66-
traceClient: &trace.Client{},
66+
traceClient: trace.NoOpTracer(),
6767
}
6868
conR.BaseReactor = *p2p.NewBaseReactor("Consensus", conR)
6969

@@ -338,7 +338,7 @@ func (conR *Reactor) ReceiveEnvelope(e p2p.Envelope) {
338338
case *BlockPartMessage:
339339
ps.SetHasProposalBlockPart(msg.Height, msg.Round, int(msg.Part.Index))
340340
conR.Metrics.BlockParts.With("peer_id", string(e.Src.ID())).Add(1)
341-
schema.WriteBlockPart(conR.traceClient, msg.Height, msg.Round, e.Src.ID(), msg.Part.Index, schema.TransferTypeDownload)
341+
schema.WriteBlockPart(conR.traceClient, msg.Height, msg.Round, e.Src.ID(), msg.Part.Index, schema.Download)
342342
conR.conS.peerMsgQueue <- msgInfo{msg, e.Src.ID()}
343343
default:
344344
conR.Logger.Error(fmt.Sprintf("Unknown message type %v", reflect.TypeOf(msg)))
@@ -357,7 +357,7 @@ func (conR *Reactor) ReceiveEnvelope(e p2p.Envelope) {
357357
cs.Validators.Size(), cs.LastCommit.Size()
358358
cs.mtx.RUnlock()
359359

360-
schema.WriteVote(conR.traceClient, height, round, msg.Vote, e.Src.ID(), schema.TransferTypeDownload)
360+
schema.WriteVote(conR.traceClient, height, round, msg.Vote, e.Src.ID(), schema.Download)
361361

362362
ps.EnsureVoteBitArrays(height, valSize)
363363
ps.EnsureVoteBitArrays(height-1, lastCommitSize)
@@ -599,7 +599,7 @@ OUTER_LOOP:
599599
Part: *parts,
600600
},
601601
}, logger) {
602-
schema.WriteBlockPart(conR.traceClient, rs.Height, rs.Round, peer.ID(), part.Index, schema.TransferTypeUpload)
602+
schema.WriteBlockPart(conR.traceClient, rs.Height, rs.Round, peer.ID(), part.Index, schema.Upload)
603603
ps.SetHasProposalBlockPart(prs.Height, prs.Round, index)
604604
}
605605
continue OUTER_LOOP
@@ -783,7 +783,7 @@ OUTER_LOOP:
783783
if vote != nil {
784784
logger.Debug("Picked Catchup commit to send", "height", prs.Height)
785785
schema.WriteVote(conR.traceClient, rs.Height, rs.Round, vote,
786-
ps.peer.ID(), schema.TransferTypeUpload)
786+
ps.peer.ID(), schema.Upload)
787787
continue OUTER_LOOP
788788
}
789789
}
@@ -812,7 +812,7 @@ func (conR *Reactor) pickSendVoteAndTrace(votes types.VoteSetReader, rs *cstypes
812812
vote := ps.PickSendVote(votes)
813813
if vote != nil { // if a vote is sent, trace it
814814
schema.WriteVote(conR.traceClient, rs.Height, rs.Round, vote,
815-
ps.peer.ID(), schema.TransferTypeUpload)
815+
ps.peer.ID(), schema.Upload)
816816
return true
817817
}
818818
return false
@@ -1046,7 +1046,7 @@ func ReactorMetrics(metrics *Metrics) ReactorOption {
10461046
return func(conR *Reactor) { conR.Metrics = metrics }
10471047
}
10481048

1049-
func ReactorTracing(traceClient *trace.Client) ReactorOption {
1049+
func ReactorTracing(traceClient trace.Tracer) ReactorOption {
10501050
return func(conR *Reactor) { conR.traceClient = traceClient }
10511051
}
10521052

‎consensus/state.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ type State struct {
143143
// for reporting metrics
144144
metrics *Metrics
145145

146-
traceClient *trace.Client
146+
traceClient trace.Tracer
147147
}
148148

149149
// StateOption sets an optional parameter on the State.
@@ -174,7 +174,7 @@ func NewState(
174174
evpool: evpool,
175175
evsw: cmtevents.NewEventSwitch(),
176176
metrics: NopMetrics(),
177-
traceClient: &trace.Client{},
177+
traceClient: trace.NoOpTracer(),
178178
}
179179

180180
// set function defaults (may be overwritten before calling Start)
@@ -217,7 +217,7 @@ func StateMetrics(metrics *Metrics) StateOption {
217217
}
218218

219219
// SetTraceClient sets the remote event collector.
220-
func SetTraceClient(ec *trace.Client) StateOption {
220+
func SetTraceClient(ec trace.Tracer) StateOption {
221221
return func(cs *State) { cs.traceClient = ec }
222222
}
223223

@@ -1845,7 +1845,7 @@ func (cs *State) recordMetrics(height int64, block *types.Block) {
18451845
blockSize := block.Size()
18461846

18471847
// trace some metadata about the block
1848-
schema.WriteBlock(cs.traceClient, block, blockSize)
1848+
schema.WriteBlockSummary(cs.traceClient, block, blockSize)
18491849

18501850
cs.metrics.NumTxs.Set(float64(len(block.Data.Txs)))
18511851
cs.metrics.TotalTxs.Add(float64(len(block.Data.Txs)))

0 commit comments

Comments
 (0)
Please sign in to comment.