Skip to content
Merged
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
167 changes: 167 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# golangci-lint v2 configuration for TiCDC.
# Docs: https://golangci-lint.run/usage/configuration/
version: "2"

linters:
# standard enables: errcheck, govet, ineffassign, staticcheck, unused.
default: standard

enable:
# bodyclose: checks HTTP response bodies are closed.
- bodyclose
# copyloopvar: detects redundant "x := x" in Go 1.22+ loop variables.
- copyloopvar
# depguard: forbids direct imports that bypass repository wrappers.
- depguard
# durationcheck: checks for suspicious duration multiplication.
- durationcheck
# errname: checks sentinel error naming (Err prefix, Error suffix).
- errname
# errorlint: checks Go 1.13 error wrapping conventions.
- errorlint
# gosec: inspects source code for security problems.
- gosec
# importas: enforces consistent import aliases.
- importas
# misspell: finds commonly misspelled English words.
- misspell
# nilerr: finds code that returns nil even if err is not nil.
- nilerr
# noctx: finds http requests without context.Context.
- noctx
# nosprintfhostport: finds misuse of Sprintf for host:port construction.
- nosprintfhostport
# prealloc: finds slices that can be preallocated.
- prealloc
# revive: drop-in replacement for golint with many rules.
- revive
# unconvert: finds unnecessary type conversions.
- unconvert
- modernize

settings:
depguard:
rules:
no-direct-errors:
files:
- $all
- "!pkg/errors/**"
deny:
- pkg: errors$
desc: use github.com/pingcap/ticdc/pkg/errors outside pkg/errors
- pkg: github.com/pingcap/errors$
desc: use github.com/pingcap/ticdc/pkg/errors outside pkg/errors

importas:
alias:
- pkg: github.com/pingcap/ticdc/pkg/errors
alias: ""

revive:
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: empty-block
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
- name: if-return
- name: increment-decrement
- name: indent-error-flow
- name: range
- name: receiver-naming
- name: redefines-builtin-id
- name: superfluous-else
- name: time-naming
- name: unexported-return
- name: unreachable-code
- name: unused-parameter
- name: var-declaration
- name: var-naming

# G104: Audit errors not checked (duplicates errcheck).
# G115: integer overflow conversions are too noisy for this codebase.
gosec:
excludes:
- G104
- G115

# ST1000: don't require package comments.
# ST1003: don't enforce naming conventions on legacy identifiers.
staticcheck:
checks:
- all
- -ST1000
- -ST1003

exclusions:
# Strict: exclude all known generated file patterns.
generated: strict

# Standard presets reduce noise from common false positives.
# Docs: https://golangci-lint.run/usage/false-positives/
presets:
- comments
- common-false-positives

rules:
# Relax certain linters for test files. Test helpers that are
# intentionally unused / unchecked / low-context are expected.
- path: _test\.go
linters:
- errcheck
- gosec
- noctx
- prealloc
- unused
- revive
- ineffassign

# Exclude the integration test directory entirely.
# Replaces golangci-lint v1's --exclude-dirs "^tests/".
- path: tests/
linters:
- all

# Exclude generated protobuf files.
- path: (.*\.)?(pb|pb\.gw)\.go
linters:
- all

# Exclude generated mocks.
- path: _mock\.go
linters:
- all

# Exclude msgp generated files.
- path: _gen\.go
linters:
- all

formatters:
enable:
- gofmt

settings:
gofmt:
simplify: true

run:
timeout: 10m
tests: true
concurrency: 4

output:
formats:
text:
path: stdout
print-linter-name: true
colors: true
sort-order:
- linter
- severity
- file
3 changes: 2 additions & 1 deletion api/v2/changefeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -1773,7 +1773,8 @@ func verifyTable4MQ(
return nil
}

eventRouter, err := eventrouter.NewEventRouter(replicaConfig.Sink, topic, config.IsPulsarScheme(scheme), protocol == config.ProtocolAvro)
isAvroLike := protocol == config.ProtocolAvro || protocol == config.ProtocolDebeziumAvro
eventRouter, err := eventrouter.NewEventRouter(replicaConfig.Sink, topic, config.IsPulsarScheme(scheme), isAvroLike)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/kafka-consumer/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func newWriter(ctx context.Context, o *option) *writer {
w.progresses[i] = newPartitionProgress(int32(i), decoder)
}

isAvroLike := o.protocol == config.ProtocolAvro
isAvroLike := o.protocol == config.ProtocolAvro || o.protocol == config.ProtocolDebeziumAvro
eventRouter, err := eventrouter.NewEventRouter(o.sinkConfig, o.topic, false, isAvroLike)
if err != nil {
log.Panic("initialize the event router failed",
Expand Down Expand Up @@ -509,7 +509,7 @@ func (w *writer) onDDL(ddl *event.DDLEvent) {
}
switch w.protocol {
case config.ProtocolCanalJSON, config.ProtocolOpen, config.ProtocolAvro, config.ProtocolSimple,
config.ProtocolDebezium:
config.ProtocolDebezium, config.ProtocolDebeziumAvro:
default:
return
}
Expand Down
1 change: 1 addition & 0 deletions cmd/kafka-consumer/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ func TestOnDDLMarksRoutedCreateTableLikePartitionTableForAvro(t *testing.T) {
func TestAppendRow2GroupKeepsDebeziumPartitionTableFallback(t *testing.T) {
for _, protocol := range []config.Protocol{
config.ProtocolDebezium,
config.ProtocolDebeziumAvro,
} {
t.Run(protocol.String(), func(t *testing.T) {
replicaCfg := config.GetDefaultReplicaConfig()
Expand Down
2 changes: 1 addition & 1 deletion downstreamadapter/sink/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func GetProtocol(protocolStr string) (config.Protocol, error) {
// GetFileExtension returns the extension for specific protocol
func GetFileExtension(protocol config.Protocol) string {
switch protocol {
case config.ProtocolAvro, config.ProtocolCanalJSON, config.ProtocolMaxwell,
case config.ProtocolAvro, config.ProtocolDebeziumAvro, config.ProtocolCanalJSON, config.ProtocolMaxwell,
config.ProtocolOpen, config.ProtocolSimple:
return ".json"
case config.ProtocolCraft:
Expand Down
2 changes: 1 addition & 1 deletion downstreamadapter/sink/kafka/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func newKafkaSinkComponent(
return comp, protocol, err
}

isAvroLike := protocol == config.ProtocolAvro
isAvroLike := protocol == config.ProtocolAvro || protocol == config.ProtocolDebeziumAvro
comp.eventRouter, err = eventrouter.NewEventRouter(
sinkConfig, topic, false, isAvroLike)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/config/changefeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,9 @@ func (info *ChangeFeedInfo) RmUnusedFields() {
info.rmMQOnlyFields()
} else {
// remove schema registry for MQ downstream with
// protocol other than avro
if util.GetOrZero(info.Config.Sink.Protocol) != ProtocolAvro.String() {
// protocol other than avro or debezium-avro
protocol := util.GetOrZero(info.Config.Sink.Protocol)
if protocol != ProtocolAvro.String() && protocol != ProtocolDebeziumAvro.String() {
info.Config.Sink.SchemaRegistry = nil
}
}
Expand Down
35 changes: 35 additions & 0 deletions pkg/config/changefeed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,41 @@ func TestChangeFeedInfoToChangefeedConfigBatchFields(t *testing.T) {
assertBatchFields(util.AddressOf(123), util.AddressOf(456))
}

func TestChangeFeedInfoRmUnusedFieldsKeepsSchemaRegistryForAvroProtocols(t *testing.T) {
t.Parallel()

tests := []struct {
protocol Protocol
keepRegistry bool
}{
{protocol: ProtocolAvro, keepRegistry: true},
{protocol: ProtocolDebeziumAvro, keepRegistry: true},
{protocol: ProtocolDebezium, keepRegistry: false},
}

for _, tt := range tests {
t.Run(tt.protocol.String(), func(t *testing.T) {
t.Parallel()

cfg := GetDefaultReplicaConfig()
cfg.Sink.Protocol = util.AddressOf(tt.protocol.String())
cfg.Sink.SchemaRegistry = util.AddressOf("http://127.0.0.1:8088")
info := &ChangeFeedInfo{
SinkURI: "kafka://127.0.0.1:9092/topic",
Config: cfg,
}

info.RmUnusedFields()
if tt.keepRegistry {
require.NotNil(t, info.Config.Sink.SchemaRegistry)
require.Equal(t, "http://127.0.0.1:8088", *info.Config.Sink.SchemaRegistry)
} else {
require.Nil(t, info.Config.Sink.SchemaRegistry)
}
})
}
}

func TestChangeFeedInfoStringMasksSensitiveData(t *testing.T) {
cfg := GetDefaultReplicaConfig()
cfg.Sink.SchemaRegistry = util.AddressOf("https://registry.example.com?access-key=registry-secret-sentinel")
Expand Down
5 changes: 3 additions & 2 deletions pkg/config/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ type SinkConfig struct {
DispatchRules []*DispatchRule `toml:"dispatchers" json:"dispatchers,omitempty"`

ColumnSelectors []*ColumnSelector `toml:"column-selectors" json:"column-selectors,omitempty"`
// SchemaRegistry is only available when the downstream is MQ using avro protocol.
// SchemaRegistry is only available when the downstream is MQ using avro protocol
// or debezium protocol with Confluent Avro encoding.
SchemaRegistry *string `toml:"schema-registry" json:"schema-registry,omitempty"`
// EncoderConcurrency is only available when the downstream is MQ.
EncoderConcurrency *int `toml:"encoder-concurrency" json:"encoder-concurrency,omitempty"`
Expand Down Expand Up @@ -976,7 +977,7 @@ func (s *SinkConfig) ValidateProtocol(scheme string) error {
if s.OpenProtocol != nil {
outputOldValue = s.OpenProtocol.OutputOldValue
}
case ProtocolDebezium:
case ProtocolDebezium, ProtocolDebeziumAvro:
if s.Debezium != nil {
outputOldValue = s.Debezium.OutputOldValue
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/sink_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const (
ProtocolCsv
ProtocolDebezium
ProtocolSimple
ProtocolDebeziumAvro
)

// IsBatchEncode returns whether the protocol is a batch encoder.
Expand Down Expand Up @@ -71,6 +72,8 @@ func ParseSinkProtocolFromString(protocol string) (Protocol, error) {
return ProtocolCsv, nil
case "debezium":
return ProtocolDebezium, nil
case "debezium-avro":
return ProtocolDebeziumAvro, nil
case "simple":
return ProtocolSimple, nil
default:
Expand Down Expand Up @@ -101,6 +104,8 @@ func (p Protocol) String() string {
return "debezium"
case ProtocolSimple:
return "simple"
case ProtocolDebeziumAvro:
return "debezium-avro"
default:
panic("unreachable")
}
Expand Down
Loading
Loading