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

ref(kafka): Validate topics on startup #3543

Merged
merged 11 commits into from
May 22, 2024
Merged

Conversation

Dav1dde
Copy link
Member

@Dav1dde Dav1dde commented May 6, 2024

This PR adds Kafka topics validation when Relay is starting up. This is done to prevent misconfiguration of Relay leading to errors when producing events.

Closes: #3404

@Dav1dde Dav1dde self-assigned this May 6, 2024
@iambriccardo iambriccardo assigned iambriccardo and unassigned Dav1dde May 13, 2024
@iambriccardo iambriccardo marked this pull request as ready for review May 14, 2024 07:06
@iambriccardo iambriccardo requested a review from a team as a code owner May 14, 2024 07:06
@@ -999,6 +999,9 @@ pub struct Processing {
/// Kafka topic names.
#[serde(default)]
pub topics: TopicAssignments,
/// Whether to validate the supplied topics by calling Kafka's metadata endpoints.
#[serde(default)]
pub validate_kafka_topics: bool,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub validate_kafka_topics: bool,
pub kafka_validate_topics: bool,

fn validate_topic(&self) -> Result<(), ClientError> {
let client = self.producer.client();
let metadata = client
.fetch_metadata(Some(&self.topic_name), Duration::from_secs(5))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Timeout?

client_builder = client_builder.add_kafka_topic_config(*topic, kafka_config)?;
client_builder = client_builder
.add_kafka_topic_config(*topic, kafka_config, config.validate_kafka_topics())
.context(ServiceError::Kafka)?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean map_err here?

Suggested change
.context(ServiceError::Kafka)?;
.map_err(ServiceError::Kafka)?;

@Dav1dde
Copy link
Member Author

Dav1dde commented May 14, 2024

:shipit:

@@ -736,7 +736,7 @@ impl KafkaOutcomesProducer {
for topic in &[KafkaTopic::Outcomes, KafkaTopic::OutcomesBilling] {
let kafka_config = &config.kafka_config(*topic).context(ServiceError::Kafka)?;
client_builder = client_builder
.add_kafka_topic_config(*topic, kafka_config)
.add_kafka_topic_config(*topic, kafka_config, config.kafka_validate_topics())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: To make this more builder pattern, it would be nice to have a method call outside of the loop

    .add_kafka_topic_config(*topic, kafka_config)
}

builder.set_topic_validation(conig.kafka_validate_topics());
builder.build()

assert relay.wait_for_exit() != 0

error = str(mini_sentry.test_failures.pop(0))
assert "failed to validate the topic with name" in error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What topic does this fail on?

@iambriccardo iambriccardo removed their assignment May 22, 2024
@iambriccardo iambriccardo merged commit 5c63716 into master May 22, 2024
22 checks passed
@iambriccardo iambriccardo deleted the dav1d/validate-topics branch May 22, 2024 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[INC-696] Validate Kafka configuration on startup
3 participants