Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DNM] log(ticdc): always print log from the sarama inside to make debug life easier #11867

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -417,5 +417,7 @@ replace sourcegraph.com/sourcegraph/appdash => github.com/sourcegraph/appdash v0

replace sourcegraph.com/sourcegraph/appdash-data => github.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67

replace github.com/IBM/sarama => github.com/3AceShowHand/sarama v0.0.0-20241204051647-318559e536ae

// tls10server=1
godebug tlsrsakex=1
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0Zeo
cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk=
cloud.google.com/go/storage v1.39.1 h1:MvraqHKhogCOTXTlct/9C3K3+Uy2jBmFYb3/Sp6dVtY=
cloud.google.com/go/storage v1.39.1/go.mod h1:xK6xZmxZmo+fyP7+DEF6FhNc24/JAe95OLyOHCXFH1o=
github.com/3AceShowHand/sarama v0.0.0-20241204051647-318559e536ae h1:TZxjgE3hc0iM0GIxz1RywfrEheWz8CsSYAEXyo6EZV8=
github.com/3AceShowHand/sarama v0.0.0-20241204051647-318559e536ae/go.mod h1:xdpu7sd6OE1uxNdjYTSKUfY8FaKkJES9/+EyjSgiGQk=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
Expand Down
11 changes: 4 additions & 7 deletions pkg/logutil/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,11 @@ func initMySQLLogger() error {

// initSaramaLogger hacks logger used in sarama lib
func initSaramaLogger(level zapcore.Level) error {
// only available less than info level
if !zapcore.InfoLevel.Enabled(level) {
logger, err := zap.NewStdLogAt(log.L().With(zap.String("component", "sarama")), level)
if err != nil {
return errors.Trace(err)
}
sarama.Logger = logger
logger, err := zap.NewStdLogAt(log.L().With(zap.String("component", "sarama")), level)
if err != nil {
return errors.Trace(err)
}
sarama.Logger = logger
return nil
}

Expand Down
18 changes: 17 additions & 1 deletion pkg/sink/codec/common/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ package common
import (
"encoding/binary"
"encoding/json"
"strconv"
"time"

"github.com/IBM/sarama"
"github.com/pingcap/tiflow/cdc/model"
"github.com/pingcap/tiflow/pkg/config"
"github.com/tikv/client-go/v2/oracle"
Expand Down Expand Up @@ -50,7 +52,21 @@ type Message struct {
// We didn't append any `Headers` when send the message, so ignore the calculations related to it.
// If `ProducerMessage` Headers fields used, this method should also adjust.
func (m *Message) Length() int {
return len(m.Key) + len(m.Value) + MaxRecordOverhead
headers := m.Headers()
var headerLen int
for _, header := range headers {
headerLen += len(header.Key) + len(header.Value) + 2*binary.MaxVarintLen32
}
return headerLen + len(m.Key) + len(m.Value) + MaxRecordOverhead
}

// Headers returns the headers of Kafka message
func (m *Message) Headers() []sarama.RecordHeader {
headers := []sarama.RecordHeader{
{Key: []byte("commitTs"), Value: []byte(strconv.FormatUint(m.Ts, 10))},
{Key: []byte("table"), Value: []byte(m.GetTable())},
}
return headers
}

// PhysicalTime returns physical time part of Ts in time.Time
Expand Down
2 changes: 2 additions & 0 deletions pkg/sink/kafka/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ func (p *saramaAsyncProducer) AsyncSend(ctx context.Context, topic string, parti
msg := &sarama.ProducerMessage{
Topic: topic,
Partition: partition,
Headers: message.Headers(),
Key: sarama.StringEncoder(message.Key),
Value: sarama.ByteEncoder(message.Value),
Metadata: message.Callback,
Expand All @@ -266,5 +267,6 @@ func (p *saramaAsyncProducer) AsyncSend(ctx context.Context, topic string, parti
return errors.Trace(ctx.Err())
case p.producer.Input() <- msg:
}
log.Info("async send msg", zap.Int32("partition", partition), zap.Any("commitTs", message.Ts), zap.String("table", message.GetTable()), zap.String("shcema", message.GetSchema()))
return nil
}
Loading