Conversation
|
|
||
| @Override | ||
| public String getId() { | ||
| public synchronized String getId() { |
There was a problem hiding this comment.
Nasty bug discovered during my experiments with Kafka module, concurrent access was giving null for the second invocation
There was a problem hiding this comment.
Have you tried making id volatile. This should work and is cheaper under contention that synchronized method
There was a problem hiding this comment.
not a performance critical part (being called just a few times), doesn't make sense to over-optimize it :)
There was a problem hiding this comment.
Isn't volatile as simple? Doesn't really matter for me in this case 😁
|
|
||
| withEnv("KAFKA_ZOOKEEPER_CONNECT", "localhost:2181"); | ||
| withClasspathResourceMapping("tc-zookeeper.properties", "/zookeeper.properties", BindMode.READ_ONLY); | ||
| withCommand("sh", "-c", "zookeeper-server-start /zookeeper.properties & /etc/confluent/docker/run"); |
There was a problem hiding this comment.
I've decided to implement all-in-one container simply to speed it up. Starting from Kafka 0.11, Zookeeper is no longer have to be exposed to the clients and becomes a detail of implementation of Kafka, so IMO it's fine
There was a problem hiding this comment.
I would personally prefer to have those as separate containers. or at least provide this as an option to configure. this will allow testing scenarios of network partitions between zookeeper and kafka nodes.
| withEnv("KAFKA_BROKER_ID", "1"); | ||
| withEnv("KAFKA_LISTENERS", "PLAINTEXT://0.0.0.0:9092,BROKER://127.0.0.1:9093"); | ||
| withEnv("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP", "BROKER:PLAINTEXT,PLAINTEXT:PLAINTEXT"); | ||
| withEnv("KAFKA_INTER_BROKER_LISTENER_NAME", "BROKER"); |
There was a problem hiding this comment.
This line makes the whole thing work :D Otherwise, Kafka would try to communicate with itself with host's port (yes, even in 1-node scenario (sic!) )
There was a problem hiding this comment.
I'm not directly familiar with Kafka or the 7 environment variables that are being set in this method. Is it possible that someone might want to use alternative values for some of these? If so, they could happily subclass and re-set the env vars they want, so that's OK.
However, would it be worth having a comment in the code (similar to your Github comment!) to say which settings are just critical to getting Kafka to work in the Dockerised environment and shouldn't be changed?
| } | ||
|
|
||
| public String getSocatContainerImage() { | ||
| return (String) properties.getOrDefault("socat.container.image", "alpine/socat:latest"); |
There was a problem hiding this comment.
I had to use :latest :(
https://hub.docker.com/r/alpine/socat/tags/
Even tho there is a tag, it seems to be old and didn't work for me. But I assume it's fine to use latest here because socat itself is supposed to be backward compatible and shouldn't break over the time
There was a problem hiding this comment.
Or would it be more responsible to maintain our own image? 😕
There was a problem hiding this comment.
once we get our name on Docker Hub - sure, for now I would stick with Alpine's
|
Yay111 |
|
|
||
| private final AtomicInteger nextAmbassadorPort = new AtomicInteger(2000); | ||
| private final Map<String, Map<Integer, Integer>> ambassadorPortMappings = new ConcurrentHashMap<>(); | ||
| private final SocatContainer ambassadorContainer = new SocatContainer(); |
There was a problem hiding this comment.
Shouldn't this changes happen in a different PR? It's a quite big one.
There was a problem hiding this comment.
there is little to no activity around DockerComposeContainer, so I would keep it as part of this PR until you have objections :)
There was a problem hiding this comment.
I'll try this change on Windows tonight 😉
There was a problem hiding this comment.
All good on Docker for Windows 💪
| protected void configure() { | ||
| withCommand("-c", | ||
| targets.entrySet().stream() | ||
| .map(entry -> "socat TCP-LISTEN:" + entry.getKey() + ",fork,reuseaddr TCP:" + entry.getValue()) |
There was a problem hiding this comment.
Are we sure that strange hostname values won't break the shell if we concat the String like this?
There was a problem hiding this comment.
AFAIK any valid hostname should be valid shell argument
| } | ||
|
|
||
| public String getSocatContainerImage() { | ||
| return (String) properties.getOrDefault("socat.container.image", "alpine/socat:latest"); |
There was a problem hiding this comment.
Or would it be more responsible to maintain our own image? 😕
| this("4.0.0"); | ||
| } | ||
|
|
||
| public KafkaContainer(String confluencePlatformVersion) { |
There was a problem hiding this comment.
AFAIK it's confluent, not confluence.
WDYT about allowing non-confluent images? We are i.e. using https://hub.docker.com/r/ches/kafka/ for our acceptance-tests. This image is missing KAFKA_INTER_BROKER_LISTENER_NAME, but it should be trivial to update the image accordingly, the other ENV params should be equal.
There was a problem hiding this comment.
AFAIK it's confluent, not confluence.
👍 😄
WDYT about allowing non-confluent images
We add too much customization, if one wants to use his custom image, I would rather recommend him to build it on top of GenericContainer
| withEnv("KAFKA_LOG_FLUSH_INTERVAL_MESSAGES", Long.MAX_VALUE + ""); | ||
| } | ||
|
|
||
| public KafkaContainer withEmbeddedZookeeper() { |
There was a problem hiding this comment.
This works because confluent images contain zookeeper?
|
Yo, @bsideup any estimation when this will be released? :) |
|
|
||
| public SocatContainer() { | ||
| super(TestcontainersConfiguration.getInstance().getSocatContainerImage()); | ||
| withCreateContainerCmdModifier(it -> it.withEntrypoint("/bin/sh")); |
There was a problem hiding this comment.
Just a thought - please could we set the container's name to something that people will be able to identify? (i.e. stop people wondering "what's this random socat container?"). A name like "testcontainers-socat-" + base58chars would probably work.
I realise that the image richnorth/ambassador or the random container names it was spawned with were never great in the first place, but we have a chance to do better 😄
rnorth
left a comment
There was a problem hiding this comment.
Only a few minor comments from me. I'm not a Kafka user so I put more weight on the fact that you and @kiview are using this already to know that it's good 😄
Please could you also add a suitable CHANGELOG entry and probably a docs update? Otherwise looks great to me!
…omment to KafkaContainer
|
@rnorth done 👍 |
| this("4.0.0"); | ||
| } | ||
|
|
||
| public KafkaContainer(String confluentPlatformVersion) { |
There was a problem hiding this comment.
Maybe I missed something, but don't we need a custom wait strategy? Or is port based wait strategy already enough?
There was a problem hiding this comment.
yes, Kafka is ready to be used when the port is open
There was a problem hiding this comment.
I at least had some instances, where I got the following error when creating a topic:
ERROR org.apache.kafka.common.errors.InvalidReplicationFactorException: replication factor: 1 larger than available brokers: 0 (kafka.admin.TopicCommand$).
This did not happen for me, when I used
.waitingFor(new LogMessageWaitStrategy().withRegEx(/(?s).*started \(kafka\.server\.KafkaServer\).*/))
There was a problem hiding this comment.
"Started Kafka" != "Initialized Kafka", your clients should be able to sync the cluster state before doing operations (and most of them do).
Waiting for cluster initialization instead of just startup will just make the tests slower while it should be handled by your consumers / producers
There was a problem hiding this comment.
I see, in this case we were using the bundled helper scripts, like kafka-topics.sh (but this is mostly a rudiment from having to use kafka with GenericContainer).
* Add Kafka module * Replace AmbassadorContainer with SocatContainer in DockerComposeContainer * make it possible to use KafkaContainer with external Zookeeper * fix typo * fix Kafka tests * Add to CHANGELOG.md, name SocatContainer, add listeners explanation comment to KafkaContainer * listen on alias * rename myNetworkAlias -> networkAlias
No description provided.