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

Add Gradle sub-projects to enable parallel running of Kafka tests #26153

Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* License); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.beam.gradle.kafka

import org.gradle.api.Project
import org.gradle.api.artifacts.ConfigurationContainer
import org.gradle.api.tasks.testing.Test

import javax.inject.Inject

class KafkaTestUtilities {
abstract static class KafkaBatchIT extends Test {

@Inject
KafkaBatchIT(String delimited, String undelimited, Boolean sdfCompatible, ConfigurationContainer configurations, Project runningProject){
group = "Verification"
description = "Runs KafkaIO IT tests with Kafka clients API $delimited"
outputs.upToDateWhen { false }
testClassesDirs = runningProject.findProject(":sdks:java:io:kafka").sourceSets.test.output.classesDirs
classpath = configurations."kafkaVersion$undelimited" + runningProject.sourceSets.test.runtimeClasspath + runningProject.findProject(":sdks:java:io:kafka").sourceSets.test.runtimeClasspath

def pipelineOptions = [
'--sourceOptions={' +
'"numRecords": "1000",' +
'"keySizeBytes": "10",' +
'"valueSizeBytes": "90"' +
'}',
"--readTimeout=120",
"--kafkaTopic=beam",
"--withTestcontainers=true",
"--kafkaContainerVersion=5.5.2",
Comment on lines +39 to +46
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we have these as variables that are then concatenated in the pipelineOptions?

]

systemProperty "beamTestPipelineOptions", groovy.json.JsonOutput.toJson(pipelineOptions)
include '**/KafkaIOIT.class'

filter {
excludeTestsMatching "*InStreaming"
if (!sdfCompatible) {
excludeTestsMatching "*DynamicPartitions" //admin client create partitions does not exist in kafka 0.11.0.3 and kafka sdf does not appear to work for kafka versions <2.0.1
excludeTestsMatching "*SDFResumesCorrectly" //Kafka SDF does not work for kafka versions <2.0.1
excludeTestsMatching "*StopReadingFunction" //Kafka SDF does not work for kafka versions <2.0.1
excludeTestsMatching "*WatermarkUpdateWithSparseMessages" //Kafka SDF does not work for kafka versions <2.0.1
}
}
}
}
}
59 changes: 13 additions & 46 deletions sdks/java/io/kafka/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ def kafkaVersions = [
'251': "2.5.1",
]

def sdfKafkaVersions = [
'201',
'211',
'222',
'231',
'241',
'251'
]

kafkaVersions.each{k,v -> configurations.create("kafkaVersion$k")}

dependencies {
Expand Down Expand Up @@ -125,48 +116,24 @@ kafkaVersions.each {kv ->
}
}

kafkaVersions.each {kv ->
task "kafkaVersion${kv.key}BatchIT"(type: Test) {
group = "Verification"
description = "Runs KafkaIO IT tests with Kafka clients API $kv.value"
outputs.upToDateWhen { false }
testClassesDirs = sourceSets.test.output.classesDirs
classpath = configurations."kafkaVersion${kv.key}" + sourceSets.test.runtimeClasspath

def pipelineOptions = [
'--sourceOptions={' +
'"numRecords": "1000",' +
'"keySizeBytes": "10",' +
'"valueSizeBytes": "90"' +
'}',
"--readTimeout=120",
"--kafkaTopic=beam",
"--withTestcontainers=true",
"--kafkaContainerVersion=5.5.2",
]

systemProperty "beamTestPipelineOptions", groovy.json.JsonOutput.toJson(pipelineOptions)
include '**/KafkaIOIT.class'

filter {
excludeTestsMatching "*InStreaming"
if (!(kv.key in sdfKafkaVersions)) {
excludeTestsMatching "*DynamicPartitions" //admin client create partitions does not exist in kafka 0.11.0.3 and kafka sdf does not appear to work for kafka versions <2.0.1
excludeTestsMatching "*SDFResumesCorrectly" //Kafka SDF does not work for kafka versions <2.0.1
excludeTestsMatching "*StopReadingFunction" //Kafka SDF does not work for kafka versions <2.0.1
excludeTestsMatching "*WatermarkUpdateWithSparseMessages" //Kafka SDF does not work for kafka versions <2.0.1
}
}
}
}

//Because this runs many integration jobs in parallel, each of which use a
//container, it can fail locally due to performance limitations on a desktop.
//To avoid this, use --max-workers=N, where N is less than half your CPUs.
//4 is a good start for parallelism without overloading your computer.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is concerning to me, especially because Jenkins runs several jobs at the same time. If you run 2 of these jobs (or even worse, 4) on the same Jenkins machine, does the worker fall over?

I wonder if there's a version of this change that does some parallelization by default, but not this much (e.g. it spins up at most 4 containers at once)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are running fine on the Jenkins workers right now. I've tried to limit parallelism to just one sub-project, but I can only manage to configure the entire build to have a max number of workes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll take another stab at this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, it looks like I can't configure parallelism differently for a subproject.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could add artificial dependencies between some of these tasks, to try and limit parallelism, but that would be a janky fix

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok - I can live without it at first. If we see these tests failing (at a higher than normal rate) with Jenkins infra-like issues, we should consider clawing this back though

task kafkaVersionsCompatibilityTest {
group = "Verification"
description = 'Runs KafkaIO with different Kafka client APIs'
def testNames = createTestList(kafkaVersions, "Test")
def batchItTestNames = createTestList(kafkaVersions, "BatchIT")
dependsOn testNames
dependsOn batchItTestNames
dependsOn (":sdks:java:io:kafka:kafka-01103:kafkaVersion01103BatchIT")
dependsOn (":sdks:java:io:kafka:kafka-100:kafkaVersion100BatchIT")
dependsOn (":sdks:java:io:kafka:kafka-111:kafkaVersion111BatchIT")
dependsOn (":sdks:java:io:kafka:kafka-201:kafkaVersion201BatchIT")
dependsOn (":sdks:java:io:kafka:kafka-211:kafkaVersion211BatchIT")
dependsOn (":sdks:java:io:kafka:kafka-222:kafkaVersion222BatchIT")
dependsOn (":sdks:java:io:kafka:kafka-231:kafkaVersion231BatchIT")
dependsOn (":sdks:java:io:kafka:kafka-241:kafkaVersion241BatchIT")
dependsOn (":sdks:java:io:kafka:kafka-251:kafkaVersion251BatchIT")
}

static def createTestList(Map<String, String> prefixMap, String suffix) {
Expand Down
23 changes: 23 additions & 0 deletions sdks/java/io/kafka/kafka-01103/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* License); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
project.ext {
delimited="0.11.0.3"
undelimited="01103"
}

apply from: "../kafka-integration-test.gradle"
23 changes: 23 additions & 0 deletions sdks/java/io/kafka/kafka-100/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* License); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
project.ext {
delimited="1.0.0"
undelimited="100"
}

apply from: "../kafka-integration-test.gradle"
23 changes: 23 additions & 0 deletions sdks/java/io/kafka/kafka-111/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* License); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
project.ext {
delimited="1.1.1"
undelimited="111"
}

apply from: "../kafka-integration-test.gradle"
23 changes: 23 additions & 0 deletions sdks/java/io/kafka/kafka-201/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* License); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
project.ext {
delimited="2.0.1"
undelimited="201"
}

apply from: "../kafka-integration-test.gradle"
23 changes: 23 additions & 0 deletions sdks/java/io/kafka/kafka-211/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* License); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
project.ext {
delimited="2.1.1"
undelimited="211"
}

apply from: "../kafka-integration-test.gradle"
23 changes: 23 additions & 0 deletions sdks/java/io/kafka/kafka-222/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* License); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
project.ext {
delimited="2.2.2"
undelimited="222"
}

apply from: "../kafka-integration-test.gradle"
23 changes: 23 additions & 0 deletions sdks/java/io/kafka/kafka-231/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* License); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
project.ext {
delimited="2.3.1"
undelimited="231"
}

apply from: "../kafka-integration-test.gradle"
23 changes: 23 additions & 0 deletions sdks/java/io/kafka/kafka-241/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* License); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
project.ext {
delimited="2.4.1"
undelimited="241"
}

apply from: "../kafka-integration-test.gradle"
23 changes: 23 additions & 0 deletions sdks/java/io/kafka/kafka-251/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* License); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
project.ext {
delimited="2.5.1"
undelimited="251"
}

apply from: "../kafka-integration-test.gradle"
Loading