From 9c121b0c73794ad8dfdf261c46487f27f252f5b9 Mon Sep 17 00:00:00 2001 From: Maciej Mensfeld Date: Fri, 21 Feb 2025 21:22:58 +0100 Subject: [PATCH] verify kafka topics naming convention --- .github/workflows/ci.yml | 3 +++ CHANGELOG.md | 1 + bin/verify_topics_naming | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100755 bin/verify_topics_naming diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c6a92d5..ffec43fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/CHANGELOG.md b/CHANGELOG.md index dd3f71c2..25fc2770 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/bin/verify_topics_naming b/bin/verify_topics_naming new file mode 100755 index 00000000..aa56a827 --- /dev/null +++ b/bin/verify_topics_naming @@ -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