Skip to content

Commit 97ded98

Browse files
committed
consumer,tests: pass schema-registry-uri and upstream-tidb-dsn as flags
1 parent 198feaa commit 97ded98

22 files changed

Lines changed: 102 additions & 68 deletions

File tree

‎cmd/consumer/config.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func loadReplicaConfig(configFile string, upstreamURI *url.URL, opts *options) *
123123

124124
// newCodecConfig builds the decoder config. loadReplicaConfig has already
125125
// applied the sink URI parameters, including protocol, to replicaConfig.Sink.
126-
func newCodecConfig(upstreamURI *url.URL, replicaConfig *config.ReplicaConfig) *common.Config {
126+
func newCodecConfig(upstreamURI *url.URL, replicaConfig *config.ReplicaConfig, schemaRegistryURI string) *common.Config {
127127
protocol, err := config.ParseSinkProtocolFromString(util.GetOrZero(replicaConfig.Sink.Protocol))
128128
if err != nil {
129129
log.Panic("consumer protocol is invalid", zap.Error(err))
@@ -132,6 +132,9 @@ func newCodecConfig(upstreamURI *url.URL, replicaConfig *config.ReplicaConfig) *
132132
if err := codecConfig.Apply(upstreamURI, replicaConfig.Sink); err != nil {
133133
log.Panic("consumer codec configuration is invalid", zap.Error(err))
134134
}
135+
if schemaRegistryURI != "" {
136+
codecConfig.AvroConfluentSchemaRegistry = schemaRegistryURI
137+
}
135138

136139
if replicaConfig.Integrity != nil {
137140
codecConfig.EnableRowChecksum = replicaConfig.Integrity.Enabled()

‎cmd/consumer/consumer.go‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func newConsumer(ctx context.Context, options *options) *consumer {
6767
config.StoreGlobalServerConfig(serverCfg)
6868

6969
upstreamURI := parseRequiredURI(options.upstreamURI)
70-
applyLegacyFlags(upstreamURI, options)
70+
applyUpstreamURIOptions(upstreamURI, options)
7171
sourceType := source.TypeOf(upstreamURI)
7272
consumerID := options.consumerID
7373
if strings.TrimSpace(consumerID) == "" {
@@ -78,7 +78,7 @@ func newConsumer(ctx context.Context, options *options) *consumer {
7878
}
7979

8080
replicaConfig := loadReplicaConfig(options.configFile, upstreamURI, options)
81-
codecConfig := newCodecConfig(upstreamURI, replicaConfig)
81+
codecConfig := newCodecConfig(upstreamURI, replicaConfig, options.schemaRegistryURI)
8282
codecConfig.TimeZone = tz
8383
logConsumerConfig(sourceType, consumerID, upstreamURI, options.downstreamURI, replicaConfig, codecConfig)
8484

@@ -96,10 +96,11 @@ func newConsumer(ctx context.Context, options *options) *consumer {
9696
}
9797

9898
decoder := decode.NewGroup(ctx, decode.Options{
99-
CodecConfig: codecConfig,
100-
ReplicaConfig: replicaConfig,
101-
UpstreamURI: upstreamURI,
102-
Validator: validator,
99+
CodecConfig: codecConfig,
100+
ReplicaConfig: replicaConfig,
101+
UpstreamURI: upstreamURI,
102+
UpstreamTiDBDSN: options.upstreamTiDBDSN,
103+
Validator: validator,
103104
})
104105

105106
c := &consumer{
@@ -149,16 +150,17 @@ func (c *consumer) readSource(ctx context.Context) error {
149150
}
150151
}
151152

152-
func applyLegacyFlags(upstreamURI *url.URL, opts *options) {
153-
legacyParams := []struct {
153+
func applyUpstreamURIOptions(upstreamURI *url.URL, opts *options) {
154+
uriParams := []struct {
154155
key string
155156
value string
156157
}{
157-
{"schema-registry", opts.schemaRegistryURI},
158-
{"upstream-tidb-dsn", opts.upstreamTiDBDSN},
158+
// Kafka and Pulsar TLS transport credentials.
159159
{"ca", opts.ca},
160160
{"cert", opts.cert},
161161
{"key", opts.key},
162+
163+
// Pulsar mTLS and OAuth2 client authentication.
162164
{"auth-tls-certificate-path", opts.authTLSCertificatePath},
163165
{"auth-tls-private-key-path", opts.authTLSPrivateKeyPath},
164166
{"oauth2-private-key", opts.oauth2PrivateKey},
@@ -170,7 +172,7 @@ func applyLegacyFlags(upstreamURI *url.URL, opts *options) {
170172

171173
query := upstreamURI.Query()
172174
changed := false
173-
for _, param := range legacyParams {
175+
for _, param := range uriParams {
174176
if param.value != "" && query.Get(param.key) == "" {
175177
query.Set(param.key, param.value)
176178
changed = true

‎cmd/consumer/decode/decode.go‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,11 @@ type Group struct {
100100

101101
// Options configures a decode group.
102102
type Options struct {
103-
CodecConfig *common.Config
104-
ReplicaConfig *config.ReplicaConfig
105-
UpstreamURI *url.URL
106-
Validator source.Validator
103+
CodecConfig *common.Config
104+
ReplicaConfig *config.ReplicaConfig
105+
UpstreamURI *url.URL
106+
UpstreamTiDBDSN string
107+
Validator source.Validator
107108
}
108109

109110
// NewGroup builds a decode group with concurrency decoupled from source partitions.
@@ -147,7 +148,7 @@ func NewGroup(ctx context.Context, opts Options) *Group {
147148
return group
148149
}
149150

150-
upstreamDB := newUpstreamDB(ctx, opts.UpstreamURI)
151+
upstreamDB := newUpstreamDB(ctx, opts.UpstreamTiDBDSN)
151152
group.upstreamDB = upstreamDB
152153

153154
if codecConfig.LargeMessageHandle.EnableClaimCheck() {
@@ -486,8 +487,7 @@ func (d *Group) decodeStorage(ctx context.Context, future *Future) error {
486487
}
487488
}
488489

489-
func newUpstreamDB(ctx context.Context, upstreamURI *url.URL) *sql.DB {
490-
dsn := upstreamURI.Query().Get("upstream-tidb-dsn")
490+
func newUpstreamDB(ctx context.Context, dsn string) *sql.DB {
491491
if dsn == "" {
492492
return nil
493493
}

‎cmd/consumer/main.go‎

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,39 @@ import (
3333
const profileAddress = "127.0.0.1:6060"
3434

3535
type options struct {
36-
upstreamURI string
37-
downstreamURI string
38-
configFile string
39-
consumerID string
40-
logFile string
41-
logLevel string
42-
consumerGroupID string
43-
schemaRegistryURI string
44-
upstreamTiDBDSN string
45-
timezone string
46-
ca string
47-
cert string
48-
key string
36+
// Common options shared across Kafka, Pulsar, and Storage sources.
37+
upstreamURI string
38+
downstreamURI string
39+
configFile string
40+
consumerID string
41+
logFile string
42+
logLevel string
43+
timezone string
44+
enableProfiling bool
45+
46+
// Kafka options for consumer group, Avro/Debezium schema lookup, and upstream row lookup.
47+
consumerGroupID string
48+
schemaRegistryURI string
49+
upstreamTiDBDSN string
50+
51+
// Transport TLS options shared by Kafka and Pulsar sources.
52+
ca string
53+
cert string
54+
key string
55+
56+
// Pulsar authentication options for mTLS and OAuth2 connections.
4957
authTLSCertificatePath string
5058
authTLSPrivateKeyPath string
5159
oauth2PrivateKey string
5260
oauth2IssuerURL string
5361
oauth2ClientID string
5462
oauth2Scope string
5563
oauth2Audience string
56-
flushInterval time.Duration
57-
fileIndexWidth int
58-
fileIndexWidthSet bool
59-
enableProfiling bool
64+
65+
// Storage options for cloud storage scan cadence and DML file naming.
66+
flushInterval time.Duration
67+
fileIndexWidth int
68+
fileIndexWidthSet bool
6069
}
6170

6271
func main() {
@@ -111,21 +120,32 @@ func newCommand() *cobra.Command {
111120
})
112121

113122
flags := command.Flags()
123+
124+
// Common options (Kafka, Pulsar, and Storage).
114125
flags.StringVar(&options.upstreamURI, "upstream-uri", "", "Kafka, Pulsar, or Storage source URI")
115126
flags.StringVar(&options.downstreamURI, "downstream-uri", "", "downstream sink URI")
116127
flags.StringVar(&options.configFile, "config", "", "consumer configuration file")
117128
flags.StringVar(&options.consumerID, "consumer-id", "",
118129
"Kafka group ID or Pulsar subscription name (random if omitted)")
119130
flags.StringVar(&options.logFile, "log-file", "cdc_consumer.log", "log file path")
120131
flags.StringVar(&options.logLevel, "log-level", "info", "log level")
121-
flags.BoolVar(&options.enableProfiling, "enable-profiling", false, "enable pprof on "+profileAddress)
122-
flags.StringVar(&options.consumerGroupID, "consumer-group-id", "", "legacy alias for --consumer-id")
123-
flags.StringVar(&options.schemaRegistryURI, "schema-registry-uri", "", "Avro schema registry URI")
124-
flags.StringVar(&options.upstreamTiDBDSN, "upstream-tidb-dsn", "", "upstream TiDB DSN")
125132
flags.StringVar(&options.timezone, "tz", "System", "consumer time zone")
133+
flags.BoolVar(&options.enableProfiling, "enable-profiling", false, "enable pprof on "+profileAddress)
134+
135+
// Kafka options (consumer group, Avro schema registry, and handle-key-only / claim-check upstream lookup).
136+
flags.StringVar(&options.consumerGroupID, "consumer-group-id", "",
137+
"Kafka consumer group ID (alias for --consumer-id)")
138+
flags.StringVar(&options.schemaRegistryURI, "schema-registry-uri", "",
139+
"Kafka Avro/Debezium-Avro schema registry URI")
140+
flags.StringVar(&options.upstreamTiDBDSN, "upstream-tidb-dsn", "",
141+
"upstream TiDB DSN for Kafka handle-key-only, simple, and claim-check lookup")
142+
143+
// Kafka and Pulsar TLS transport options.
126144
flags.StringVar(&options.ca, "ca", "", "CA certificate path for Kafka/Pulsar TLS")
127145
flags.StringVar(&options.cert, "cert", "", "client certificate path for Kafka/Pulsar TLS")
128146
flags.StringVar(&options.key, "key", "", "client private key path for Kafka/Pulsar TLS")
147+
148+
// Pulsar authentication options (mTLS and OAuth2).
129149
flags.StringVar(&options.authTLSCertificatePath, "auth-tls-certificate-path", "",
130150
"Pulsar mTLS authentication certificate path")
131151
flags.StringVar(&options.authTLSPrivateKeyPath, "auth-tls-private-key-path", "",
@@ -135,6 +155,8 @@ func newCommand() *cobra.Command {
135155
flags.StringVar(&options.oauth2ClientID, "oauth2-client-id", "", "Pulsar OAuth2 client ID")
136156
flags.StringVar(&options.oauth2Scope, "oauth2-scope", "", "Pulsar OAuth2 scope")
137157
flags.StringVar(&options.oauth2Audience, "oauth2-audience", "", "Pulsar OAuth2 audience")
158+
159+
// Storage options (scan interval and DML file index formatting).
138160
flags.DurationVar(&options.flushInterval, "flush-interval", 2*time.Second, "storage scan interval")
139161
flags.IntVar(&options.fileIndexWidth, "file-index-width",
140162
config.DefaultFileIndexWidth, "storage file index width")

‎tests/integration_tests/_utils/run_consumer‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/bin/bash
22

3-
# Parameters: work directory, upstream URI, optional config, optional log suffix.
3+
# Parameters: work directory, upstream URI, optional config, optional log suffix, extra consumer flags.
44
set -eu
55

66
workdir=$1
77
upstream_uri=$2
88
consumer_config=${3:-}
99
log_suffix=${4:-}
10+
shift 4 2>/dev/null || shift $#
1011
consumer_id="${TEST_NAME:-consumer}-$$"
1112
case "$upstream_uri" in
1213
pulsar*) consumer_id=pulsar-test-subscription ;;
@@ -21,6 +22,9 @@ args=(
2122
if [ -n "$consumer_config" ]; then
2223
args+=(--config "$consumer_config")
2324
fi
25+
if [ "$#" -gt 0 ]; then
26+
args+=("$@")
27+
fi
2428

2529
echo "[$(date)] <<<<<< START consumer in ${TEST_NAME:-consumer} case >>>>>>"
2630
cd "$workdir"

‎tests/integration_tests/avro_basic/run.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function run() {
4848
schema_registry_uri="http://127.0.0.1:8088"
4949
cdc_cli_changefeed create --start-ts=$start_ts --sink-uri=$SINK_URI --config=$CUR/conf/changefeed.toml --schema-registry=$schema_registry_uri
5050

51-
run_consumer $WORK_DIR "$SINK_URI&schema-registry=$(printf '%s' "$schema_registry_uri" | jq -sRr @uri)" $CUR/conf/changefeed.toml
51+
run_consumer $WORK_DIR "$SINK_URI" $CUR/conf/changefeed.toml "" --schema-registry-uri "$schema_registry_uri"
5252

5353
run_sql_file $CUR/data/data.sql ${UP_TIDB_HOST} ${UP_TIDB_PORT}
5454

‎tests/integration_tests/canal_json_claim_check/run.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function run() {
3232

3333
cdc_cli_changefeed create --start-ts=$start_ts --sink-uri="$SINK_URI" --config="$CUR/conf/changefeed.toml"
3434

35-
run_consumer "$WORK_DIR" "${SINK_URI}&upstream-tidb-dsn=$(printf '%s' "root@tcp(${UP_TIDB_HOST}:${UP_TIDB_PORT})/?" | jq -sRr @uri)" "$CUR/conf/changefeed.toml"
35+
run_consumer "$WORK_DIR" "$SINK_URI" "$CUR/conf/changefeed.toml" "" --upstream-tidb-dsn "root@tcp(${UP_TIDB_HOST}:${UP_TIDB_PORT})/?"
3636

3737
run_sql_file $CUR/data/data.sql ${UP_TIDB_HOST} ${UP_TIDB_PORT}
3838

‎tests/integration_tests/canal_json_handle_key_only/run.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function run() {
3030

3131
cdc_cli_changefeed create --start-ts=$start_ts --sink-uri="$SINK_URI" --config="$CUR/conf/changefeed.toml"
3232

33-
run_consumer "$WORK_DIR" "${SINK_URI}&upstream-tidb-dsn=$(printf '%s' "root@tcp(${UP_TIDB_HOST}:${UP_TIDB_PORT})/?" | jq -sRr @uri)" "$CUR/conf/changefeed.toml"
33+
run_consumer "$WORK_DIR" "$SINK_URI" "$CUR/conf/changefeed.toml" "" --upstream-tidb-dsn "root@tcp(${UP_TIDB_HOST}:${UP_TIDB_PORT})/?"
3434

3535
run_sql_file $CUR/data/data.sql ${UP_TIDB_HOST} ${UP_TIDB_PORT}
3636

‎tests/integration_tests/column_selector/run.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function run_kafka() {
4747
SINK_URI="kafka://127.0.0.1:9092/$TOPIC_NAME?protocol=canal-json&partition-num=1&enable-tidb-extension=true"
4848
cdc_cli_changefeed create --start-ts=$start_ts --sink-uri="$SINK_URI" -c $CHANGEFEED_ID --config="$CUR/conf/changefeed.toml"
4949

50-
run_consumer "$WORK_DIR" "${SINK_URI}&upstream-tidb-dsn=$(printf '%s' "root@tcp(${UP_TIDB_HOST}:${UP_TIDB_PORT})/?" | jq -sRr @uri)" "$CUR/conf/changefeed.toml"
50+
run_consumer "$WORK_DIR" "$SINK_URI" "$CUR/conf/changefeed.toml" "" --upstream-tidb-dsn "root@tcp(${UP_TIDB_HOST}:${UP_TIDB_PORT})/?"
5151

5252
run_sql_file $CUR/data/data.sql ${UP_TIDB_HOST} ${UP_TIDB_PORT}
5353
run_checksum_checker

‎tests/integration_tests/debezium_avro/run.sh‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ EOF
7575

7676
cdc_cli_changefeed create -c "debezium-avro-$mode" --sink-uri="$sink_uri" \
7777
--config="$config_file" --schema-registry="$schema_registry_uri"
78-
run_consumer "$WORK_DIR" "$sink_uri&schema-registry=$(printf '%s' "$schema_registry_uri" | jq -sRr @uri)" "$config_file" "-$mode"
78+
run_consumer "$WORK_DIR" "$sink_uri" "$config_file" "-$mode" --schema-registry-uri "$schema_registry_uri"
7979
run_sql_file "$WORK_DIR/handling-$mode.sql" "$UP_TIDB_HOST" "$UP_TIDB_PORT"
8080
kafka_dump --topic "$topic" --schema-registry-uri "$schema_registry_uri" \
8181
--timeout 90s --until-table handling_modes --until-count 6 >"$WORK_DIR/handling-$mode.jsonl"
@@ -115,7 +115,7 @@ function run() {
115115
cdc_cli_changefeed create --start-ts="$start_ts" --sink-uri="$SINK_URI" -c "$changefeed_id" --schema-registry="$schema_registry_uri"
116116
sleep 5 # wait for changefeed to start
117117

118-
run_consumer "$WORK_DIR" "$SINK_URI&schema-registry=$(printf '%s' "$schema_registry_uri" | jq -sRr @uri)" ""
118+
run_consumer "$WORK_DIR" "$SINK_URI" "" "" --schema-registry-uri "$schema_registry_uri"
119119

120120
run_sql_file "$CUR/data/workload.sql" "$UP_TIDB_HOST" "$UP_TIDB_PORT"
121121
run_sql_file "$CUR/data/ddl.sql" "$UP_TIDB_HOST" "$UP_TIDB_PORT"

0 commit comments

Comments
 (0)