Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

feat: add first poc for a Kafka proxy #7

Merged
merged 2 commits into from Jun 28, 2021

Conversation

smoya
Copy link
Collaborator

@smoya smoya commented Jun 23, 2021

Description

This PR adds contains the first POC of a Kafka Proxy that validates messages. As a poc, there has no real validation logic behind but the functionality is ready to make it happen: Right now it only prints a log line whenever a message is literally the string invalid message.

The PR also includes a docker-compose.yml and a Dockerfile so we can run a one node Kafka cluster and do some testing. Readme update is pending.

If you wanna play in the meantime, you can just run docker compose up and produce/consume messages by:

Consume: docker compose exec broker /bin/kafka-console-consumer --topic demo --from-beginning --bootstrap-server proxy:28002
Produce: docker compose exec broker /bin/kafka-console-producer --topic demo --bootstrap-server proxy:28002 and start writing messages (stdin).

As notes for developers, I managed to completely turn off my old POC (yeah, never pushed but I can share it with you as I have it locally) where I had to manage almost all the protocol handling manually (yeah, dealing with bits and bytes) and which was only supporting a particular Kafka request protocol version.
Now I'm using https://github.com/grepplabs/kafka-proxy which it has almost everything we need. In fact I had to fork it and tune it up a bit (Adding support for request handlers per Key. See the fork here. I plan to create a PR to the main project once I have more time to improve those changes I did.
I'm also using parts of the code of https://github.com/Shopify/sarama project for decoding and validating the ProduceRequest. I could not use the project directly because some of the interfaces I needed are private. I opened an issue few days ago regarding this: IBM/sarama#1967.

One of the biggest achievements on using https://github.com/grepplabs/kafka-proxy is that it supports most of the AUTH mechanisms and also all the Kafka protocol request versions (YEEEEI!).

Next steps

  • The plan is, from here, to start validating actual AsyncAPI spec files somehow

How to review this PR
Even though this is a POC, most of this code could be used as the foundation of the first versions of the gateway.
That means you should review it as any other PR. Some things that were not included on this PR with the idea of doing it in another one are:

  • Tests of the logic in main.go
  • README update

Some things that were explicitly excluded from this PR were:

  • Tests for code copied from Sarama (most of the code in /kafka)

Related issue(s)
asyncapi/shape-up-process#70

@smoya smoya marked this pull request as ready for review June 23, 2021 14:07
@@ -0,0 +1,47 @@
linters:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@@ -0,0 +1,57 @@
# Makefile based on https://gist.github.com/thomaspoignant/5b72d579bd5f311904d973652180c705
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

replace github.com/grepplabs/kafka-proxy => github.com/smoya/kafka-proxy v0.2.9-0.20210623125118-a94cf71a065c
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here is the replace directive in order to use my forked version of grepplabs/kafka-proxy

@@ -8,8 +8,11 @@
# Test binary, built with `go test -c`
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@@ -0,0 +1,118 @@
package main
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This file is actually the code of the app :)

Copy link

@fmvilas fmvilas left a comment

Choose a reason for hiding this comment

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

:shipit:

@smoya smoya merged commit 32263a9 into asyncapi-archived-repos:master Jun 28, 2021
@smoya smoya deleted the kafka-proxy-poc branch June 28, 2021 10:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants