Skip to content

Commit

Permalink
cassandra: updates client driver and test binary (#3612)
Browse files Browse the repository at this point in the history
This updates to the latest Datastax driver and updates our test image to
latest cassandra 4.x version. This also cleans up where our test image
had leftovers from previous versions of cassandra and JREs.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
  • Loading branch information
codefromthecrypt authored Dec 4, 2023
1 parent b51f760 commit 2a6b4fb
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 81 deletions.
7 changes: 3 additions & 4 deletions docker/test-images/zipkin-cassandra/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2015-2021 The OpenZipkin Authors
# Copyright 2015-2023 The OpenZipkin Authors
#
# Licensed 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
Expand All @@ -17,7 +17,6 @@
# Use latest version here: https://github.com/orgs/openzipkin/packages/container/package/java
# This is defined in many places because Docker has no "env" script functionality unless you use
# docker-compose: When updating, update everywhere.
# Note: Cassandra does not support Java 17 yet so use older JRE for testing
ARG java_version=17.0.8_p7

# We copy files from the context into a scratch container first to avoid a problem where docker and
Expand All @@ -35,7 +34,7 @@ FROM ghcr.io/openzipkin/java:${java_version} as install
# Use latest stable version: https://cassandra.apache.org/download/
# This is defined in many places because Docker has no "env" script functionality unless you use
# docker-compose: When updating, update everywhere.
ARG cassandra_version=4.0.9
ARG cassandra_version=4.0.11
ENV CASSANDRA_VERSION=$cassandra_version
WORKDIR /install

Expand All @@ -45,7 +44,7 @@ RUN /tmp/install.sh && rm /tmp/install.sh

FROM ghcr.io/openzipkin/java:${java_version}-jre as zipkin-cassandra
LABEL org.opencontainers.image.description="Cassandra on OpenJDK and Alpine Linux with Zipkin keyspaces pre-installed"
ARG cassandra_version=4.0.7
ARG cassandra_version=4.0.11
LABEL cassandra-version=$cassandra_version
ENV CASSANDRA_VERSION=$cassandra_version

Expand Down
2 changes: 1 addition & 1 deletion docker/test-images/zipkin-cassandra/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## zipkin-cassandra Docker image

The `zipkin-cassandra` testing image runs Cassandra 3.11.x initialized with Zipkin's schema for
The `zipkin-cassandra` testing image runs Cassandra 4.x initialized with Zipkin's schema for
[Cassandra storage](../../../zipkin-storage/cassandra) integration.

Besides norms defined in [docker-java](https://github.com/openzipkin/docker-java), this accepts the
Expand Down
89 changes: 35 additions & 54 deletions docker/test-images/zipkin-cassandra/install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright 2015-2021 The OpenZipkin Authors
# Copyright 2015-2023 The OpenZipkin Authors
#
# Licensed 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
Expand Down Expand Up @@ -38,18 +38,10 @@ cat > pom.xml <<-'EOF'
<artifactId>cassandra-all</artifactId>
<version>${cassandra.version}</version>
<exclusions>
<exclusion>
<groupId>com.github.jbellis</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>net.java.dev.jna</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>com.googlecode.concurrent-trees</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>*</artifactId>
Expand All @@ -60,23 +52,11 @@ cat > pom.xml <<-'EOF'
</exclusion>
</exclusions>
</dependency>
<!-- Override until Cassandra 4.0 per CASSANDRA-9608 -->
<dependency>
<groupId>com.github.jbellis</groupId>
<artifactId>jamm</artifactId>
<version>0.3.3</version>
</dependency>
<!-- Alpine support CASSANDRA-16212 -->
<!-- Use latest to support alpine and additional architecture -->
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.6.0</version>
</dependency>
<!-- NoClassDefFoundError in TrieMemIndex CASSANDRA-16303 (Cassandra 4.0) -->
<dependency>
<groupId>com.googlecode.concurrent-trees</groupId>
<artifactId>concurrent-trees</artifactId>
<version>2.6.1</version>
<version>5.13.0</version>
</dependency>
<!-- log4j not logback -->
<dependency>
Expand All @@ -89,7 +69,7 @@ cat > pom.xml <<-'EOF'
EOF
mvn -q --batch-mode -DoutputDirectory=lib \
-Dcassandra.version=${CASSANDRA_VERSION} \
org.apache.maven.plugins:maven-dependency-plugin:3.1.2:copy-dependencies
org.apache.maven.plugins:maven-dependency-plugin:3.6.1:copy-dependencies
rm pom.xml

# Make sure you use relative paths in references like this, so that installation
Expand Down Expand Up @@ -133,45 +113,46 @@ log4j.appender.stdout.Target=System.out
EOF

cat zipkin-schemas/zipkin2-schema.cql zipkin-schemas/zipkin2-schema-indexes.cql > schema
case ${CASSANDRA_VERSION} in
3.11* )
cqlversion=3.4.4
;;
4* )
# read_repair_chance options were removed and make Cassandra crash starting in v4
# See https://cassandra.apache.org/doc/latest/operating/read_repair.html#background-read-repair
sed -i '/read_repair_chance/d' schema
cqlversion=3.4.5
;;
esac

jdk11_modules="--add-exports java.base/jdk.internal.misc=ALL-UNNAMED \

# read_repair_chance options were removed and make Cassandra crash starting in v4
# See https://cassandra.apache.org/doc/latest/operating/read_repair.html#background-read-repair
sed -i '/read_repair_chance/d' schema

# Run cassandra on a different port temporarily in order to setup the schema.
#
# We also add exports and opens from both Cassandra v4 and v5, except for
# attach, compiler and rmi because our JRE excludes these modules.
#
# Merging makes adding Cassandra v5 easier and lets us share a common JRE 17+
# with other test images even if Cassandra v4 will never officially support it.
# https://github.com/apache/cassandra/blob/cassandra-4.0.11/conf/jvm11-server.options
# https://github.com/apache/cassandra/blob/cassandra-5.0/conf/jvm17-server.options
java -cp 'classes:lib/*' -Xms64m -Xmx64m -XX:+ExitOnOutOfMemoryError -verbose:gc \
-Djdk.attach.allowAttachSelf=true \
--add-exports java.base/jdk.internal.misc=ALL-UNNAMED \
--add-exports java.base/jdk.internal.ref=ALL-UNNAMED \
--add-exports java.base/sun.nio.ch=ALL-UNNAMED \
--add-exports java.sql/java.sql=ALL-UNNAMED \
--add-exports java.base/java.lang.ref=ALL-UNNAMED \
--add-exports jdk.unsupported/sun.misc=ALL-UNNAMED \
--add-opens java.base/java.lang.module=ALL-UNNAMED \
--add-opens java.base/jdk.internal.loader=ALL-UNNAMED \
--add-opens java.base/jdk.internal.ref=ALL-UNNAMED \
--add-opens java.base/jdk.internal.reflect=ALL-UNNAMED \
--add-opens java.base/jdk.internal.math=ALL-UNNAMED \
--add-opens java.base/jdk.internal.module=ALL-UNNAMED \
--add-opens java.base/jdk.internal.util.jar=ALL-UNNAMED \
--add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED"

jdk17_modules="--add-opens java.base/java.io=ALL-UNNAMED \
--add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED \
--add-opens java.base/java.io=ALL-UNNAMED \
--add-opens java.base/java.nio=ALL-UNNAMED \
--add-opens java.base/sun.nio.ch=ALL-UNNAMED \
--add-opens java.base/java.io=ALL-UNNAMED \
--add-opens java.base/java.lang.reflect=ALL-UNNAMED \
--add-opens java.base/java.lang=ALL-UNNAMED \
--add-opens java.base/java.util=ALL-UNNAMED \
--add-opens java.base/java.nio=ALL-UNNAMED \
--add-opens java.base/java.util.concurrent=ALL-UNNAMED \
--add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED"

# Run cassandra on a different port temporarily in order to setup the schema.
# We also add exports and opens from Cassandra 4, except RMI, which isn't in our JRE image.
# See https://github.com/apache/cassandra/blob/cassandra-4.0.9/conf/jvm11-server.options
java -cp 'classes:lib/*' -Xms64m -Xmx64m -XX:+ExitOnOutOfMemoryError -verbose:gc \
-Djdk.attach.allowAttachSelf=true \
${jdk11_modules} \
${jdk17_modules} \
--add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED \
-Dcassandra.storage_port=${temp_storage_port} \
-Dcassandra.native_transport_port=${temp_native_transport_port} \
-Dcassandra.storagedir=${PWD} \
Expand All @@ -181,7 +162,7 @@ java -cp 'classes:lib/*' -Xms64m -Xmx64m -XX:+ExitOnOutOfMemoryError -verbose:gc
org.apache.cassandra.service.CassandraDaemon > temp_cassandra.out 2>&1 &
temp_cassandra_pid=$!

function is_cassandra_alive() {
is_cassandra_alive() {
if ! kill -0 ${temp_cassandra_pid}; then
cat temp_cassandra.out
maybe_crash_file=hs_err_pid${temp_cassandra_pid}.log
Expand All @@ -199,14 +180,14 @@ apk add --update --no-cache python3 py3-pip
# to be compiled, but something isn't right with aarch64 when installing
# cqlsh it needs to build cffi. To unblock support for aarch64, adding
# the following are necessary for compiling cffi. If pip someday changes and
# doesn't compile cffi on arrch64 then we can remove these dependencies.
# doesn't compile cffi on aarch64 then we can remove these dependencies.
apk add --update --no-cache gcc python3-dev musl-dev libffi-dev
# PEP 668 protects against mixing system and pip packages. Setup virtual env to avoid this.
python3 -m venv .venv
source .venv/bin/activate
. .venv/bin/activate
pip install -Iq cqlsh
function cql() {
cqlsh --cqlversion=${cqlversion} "$@" 127.0.0.1 ${temp_native_transport_port}
cql() {
cqlsh "$@" 127.0.0.1 ${temp_native_transport_port}
}

# Excessively long timeout to avoid having to create an ENV variable, decide its name, etc.
Expand Down
42 changes: 25 additions & 17 deletions docker/test-images/zipkin-cassandra/start-cassandra
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright 2015-2020 The OpenZipkin Authors
# Copyright 2015-2023 The OpenZipkin Authors
#
# Licensed 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
Expand Down Expand Up @@ -40,36 +40,44 @@ export HEALTHCHECK_IP=${IP}
export HEALTHCHECK_PORT=9042
export HEALTHCHECK_KIND=tcp

jdk11_modules="--add-exports java.base/jdk.internal.misc=ALL-UNNAMED \
echo Starting Cassandra
# -cp 'classes:lib/*' allows layers to patch the image without packaging or
# overwriting jars.
#
# We also add exports and opens from both Cassandra v4 and v5, except for
# attach, compiler and rmi because our JRE excludes these modules.
#
# Merging makes adding Cassandra v5 easier and lets us share a common JRE 17+
# with other test images even if Cassandra v4 will never officially support it.
# https://github.com/apache/cassandra/blob/cassandra-4.0.11/conf/jvm11-server.options
# https://github.com/apache/cassandra/blob/cassandra-5.0/conf/jvm17-server.options
exec java -cp 'classes:lib/*' ${JAVA_OPTS} \
-Xbootclasspath/a:${JAMM_JAR} -javaagent:${JAMM_JAR} \
-Djdk.attach.allowAttachSelf=true \
--add-exports java.base/jdk.internal.misc=ALL-UNNAMED \
--add-exports java.base/jdk.internal.ref=ALL-UNNAMED \
--add-exports java.base/sun.nio.ch=ALL-UNNAMED \
--add-exports java.sql/java.sql=ALL-UNNAMED \
--add-exports java.base/java.lang.ref=ALL-UNNAMED \
--add-exports jdk.unsupported/sun.misc=ALL-UNNAMED \
--add-opens java.base/java.lang.module=ALL-UNNAMED \
--add-opens java.base/jdk.internal.loader=ALL-UNNAMED \
--add-opens java.base/jdk.internal.ref=ALL-UNNAMED \
--add-opens java.base/jdk.internal.reflect=ALL-UNNAMED \
--add-opens java.base/jdk.internal.math=ALL-UNNAMED \
--add-opens java.base/jdk.internal.module=ALL-UNNAMED \
--add-opens java.base/jdk.internal.util.jar=ALL-UNNAMED \
--add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED"

jdk17_modules="--add-opens java.base/java.io=ALL-UNNAMED \
--add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED \
--add-opens java.base/java.io=ALL-UNNAMED \
--add-opens java.base/java.nio=ALL-UNNAMED \
--add-opens java.base/sun.nio.ch=ALL-UNNAMED \
--add-opens java.base/java.io=ALL-UNNAMED \
--add-opens java.base/java.lang.reflect=ALL-UNNAMED \
--add-opens java.base/java.lang=ALL-UNNAMED \
--add-opens java.base/java.util=ALL-UNNAMED \
--add-opens java.base/java.nio=ALL-UNNAMED \
--add-opens java.base/java.util.concurrent=ALL-UNNAMED \
--add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED"

echo Starting Cassandra
# -cp 'classes:lib/*' allows layers to patch the image without packaging or overwriting jars
#
# We also add exports and opens from Cassandra 4, except RMI, which isn't in our JRE image.
# See https://github.com/apache/cassandra/blob/cassandra-4.0-beta3/conf/jvm11-server.options
exec java -cp 'classes:lib/*' ${JAVA_OPTS} \
-Xbootclasspath/a:${JAMM_JAR} -javaagent:${JAMM_JAR} \
-Djdk.attach.allowAttachSelf=true \
${jdk11_modules} \
${jdk17_modules} \
--add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED \
-Djava.io.tmpdir=/tmp \
-Dcassandra-foreground=yes \
-Dcassandra.storagedir=${PWD} \
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<!-- It's easy for Jackson dependencies to get misaligned, so we manage it ourselves. -->
<jackson.version>2.15.0</jackson.version>

<java-driver.version>4.11.3</java-driver.version>
<java-driver.version>4.17.0</java-driver.version>
<micrometer.version>1.9.3</micrometer.version>

<snappy.version>1.1.10.3</snappy.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2020 The OpenZipkin Authors
* Copyright 2015-2023 The OpenZipkin Authors
*
* Licensed 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
Expand All @@ -15,8 +15,8 @@

import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.auth.AuthProvider;
import com.datastax.oss.driver.api.core.auth.ProgrammaticPlainTextAuthProvider;
import com.datastax.oss.driver.api.core.config.DriverOption;
import com.datastax.oss.driver.internal.core.auth.ProgrammaticPlainTextAuthProvider;
import java.util.Map;
import java.util.Set;
import zipkin2.Call;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2020 The OpenZipkin Authors
* Copyright 2015-2023 The OpenZipkin Authors
*
* Licensed 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
Expand All @@ -15,8 +15,8 @@

import com.datastax.oss.driver.api.core.AllNodesFailedException;
import com.datastax.oss.driver.api.core.auth.Authenticator;
import com.datastax.oss.driver.api.core.auth.ProgrammaticPlainTextAuthProvider;
import com.datastax.oss.driver.api.core.metadata.EndPoint;
import com.datastax.oss.driver.internal.core.auth.ProgrammaticPlainTextAuthProvider;
import java.nio.ByteBuffer;
import org.junit.Test;
import zipkin2.CheckResult;
Expand Down

0 comments on commit 2a6b4fb

Please sign in to comment.