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

verify kafka topics naming convention #544

Merged
merged 1 commit into from
Feb 21, 2025
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ jobs:
- name: Check Kafka logs for unexpected warnings
run: bin/verify_kafka_warnings

- name: Check test topics naming convention
run: bin/verify_topics_naming

diffend:
runs-on: ubuntu-latest
strategy:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- [Change] Do not fully hide config-disabled features but make them disabled.
- [Change] Remove per-consumer process duplicated details from Subscriptions and Jobs tabs.
- [Refactor] Make sure all temporary topics have a `it-` prefix in their name.
- [Refactor] Introduce a `bin/verify_topics_naming` script to ensure proper test topics naming convention.
- [Fix] Fix incorrect names in some of the tables headers.
- [Fix] Normalize position of commanding buttons in regards to other UI elements.
- [Fix] Fix incorrect indentation of some of the info messages.
Expand Down
35 changes: 35 additions & 0 deletions bin/verify_topics_naming
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env ruby

# This script verifies that we do not create (except few needed exceptions) test topics that do
# not start with the "it-" prefix which is our standard.
#
# This ensures that we can clearly identify all test topics for removal in case of doing dev work
# on a long-lived Kafka cluster without option to fully reset it.
#
# It also ensures we have one convention that we can follow.

require 'bundler'
Bundler.setup(:default, :test, :integrations)
require 'karafka'

module Karafka
class App
setup do |config|
config.kafka = { 'bootstrap.servers': '127.0.0.1:9092' }
end
end
end

# Please note that "__" starting topics are not here by default. It is expected.
invalid = Karafka::Admin
.cluster_info
.topics
.map { |topic| topic[:topic_name] }
.select { |topic| !topic.start_with?('it-') }
.select { |topic| topic.length <= 6 }

invalid.each do |invalid_name|
puts "#{invalid_name} does not start with the \"it-\" prefix"
end

exit invalid.empty? ? 0 : 1