-
Notifications
You must be signed in to change notification settings - Fork 852
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
Add topic properties to Migrator #3207
Changes from 2 commits
b720a03
840ed26
a91f7b2
90fb453
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,12 +226,10 @@ func init() { | |
// message from it. | ||
mgr.Logger().Errorf("Failed to create topic %q and ACLs: %s", topic, err) | ||
} | ||
|
||
continue | ||
} else { | ||
mgr.Logger().Infof("Created topic %q", topic) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a debug message which gets printed if the topic already exists... |
||
} | ||
|
||
mgr.Logger().Infof("Created topic %q", topic) | ||
|
||
if err := createACLs(ctx, topic, inputClient, outputClient); err != nil { | ||
mgr.Logger().Errorf("Failed to create ACLs for topic %q: %s", topic, err) | ||
} | ||
|
@@ -294,10 +292,10 @@ func init() { | |
} else { | ||
return fmt.Errorf("failed to create topic %q and ACLs: %s", record.Topic, err) | ||
} | ||
} else { | ||
mgr.Logger().Infof("Created topic %q", record.Topic) | ||
} | ||
|
||
mgr.Logger().Infof("Created topic %q", record.Topic) | ||
|
||
if err := createACLs(ctx, record.Topic, details.Client, client); err != nil { | ||
mgr.Logger().Errorf("Failed to create ACLs for topic %q: %s", record.Topic, err) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,39 @@ func createTopic(ctx context.Context, topic string, replicationFactorOverride bo | |
} | ||
} | ||
|
||
if _, err := outputAdminClient.CreateTopic(ctx, partitions, rp, nil, topic); err != nil { | ||
topicConfigs, err := inputAdminClient.DescribeTopicConfigs(ctx, topic) | ||
if err != nil { | ||
return fmt.Errorf("failed to fetch configs for topic %q from source broker: %s", topic, err) | ||
} | ||
|
||
rc, err := topicConfigs.On(topic, nil) | ||
if err != nil { | ||
return fmt.Errorf("failed to fetch configs for topic %q from source broker: %s", topic, err) | ||
} | ||
|
||
destinationConfigs := make(map[string]*string) | ||
for _, c := range rc.Configs { | ||
// Source: https://docs.redpanda.com/current/reference/properties/topic-properties/ | ||
if c.Key == "cleanup.policy" || | ||
c.Key == "flush.bytes" || | ||
c.Key == "flush.ms" || | ||
c.Key == "initial.retention.local.target.ms" || | ||
c.Key == "retention.bytes" || | ||
c.Key == "retention.ms" || | ||
c.Key == "segment.ms" || | ||
c.Key == "segment.bytes" || | ||
c.Key == "compression.type" || | ||
c.Key == "message.timestamp.type" || | ||
c.Key == "max.message.bytes" || | ||
c.Key == "replication.factor" || | ||
c.Key == "write.caching" || | ||
c.Key == "redpanda.iceberg.mode" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe simpler as a switch or a slices.Contain? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went for a map since that's what Copilot suggested when I asked it to make the code look nicer 😅 |
||
|
||
destinationConfigs[c.Key] = c.Value | ||
} | ||
} | ||
|
||
if _, err := outputAdminClient.CreateTopic(ctx, partitions, rp, destinationConfigs, topic); err != nil { | ||
if !errors.Is(err, kerr.TopicAlreadyExists) { | ||
return fmt.Errorf("failed to create topic %q: %s", topic, err) | ||
} | ||
|
@@ -72,11 +104,11 @@ func createACLs(ctx context.Context, topic string, inputClient *kgo.Client, outp | |
// Only topic ACLs are migrated, group ACLs are not migrated. | ||
// Users are not migrated because we can't read passwords. | ||
|
||
aclBuilder := kadm.NewACLs().Topics(topic). | ||
builder := kadm.NewACLs().Topics(topic). | ||
ResourcePatternType(kadm.ACLPatternLiteral).Operations().Allow().Deny().AllowHosts().DenyHosts() | ||
var inputACLResults kadm.DescribeACLsResults | ||
var err error | ||
if inputACLResults, err = inputAdminClient.DescribeACLs(ctx, aclBuilder); err != nil { | ||
if inputACLResults, err = inputAdminClient.DescribeACLs(ctx, builder); err != nil { | ||
return fmt.Errorf("failed to fetch ACLs for topic %q: %s", topic, err) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The template linter is a bit annoying, since it doesn't check if there are any unrecognised fields... Something to improve in Benthos.