Skip to content

Commit

Permalink
Move Cassandra version check to docker.sh (#4087)
Browse files Browse the repository at this point in the history
Alternative solution, closes #4056

This keeps the create.sh script simpler and not aware of cqlsh.

Signed-off-by: Yuri Shkuro <github@ysh.us>
Co-authored-by: Albert <26584478+albertteoh@users.noreply.github.com>
  • Loading branch information
yurishkuro and albertteoh committed Dec 7, 2022
1 parent 2da8b72 commit 3c8ffd1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
3 changes: 1 addition & 2 deletions pkg/es/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ func addLoggerOptions(options []elastic.ClientOptionFunc, logLevel string) ([]el
prodConfig := zap.NewProductionConfig()

var lvl zapcore.Level
var loggerOpts []zapgrpc.Option
var setLogger func(logger elastic.Logger) elastic.ClientOptionFunc

switch logLevel {
Expand All @@ -490,7 +489,7 @@ func addLoggerOptions(options []elastic.ClientOptionFunc, logLevel string) ([]el
}

// Elastic client requires a "Printf"-able logger.
l := zapgrpc.NewLogger(esLogger, loggerOpts...)
l := zapgrpc.NewLogger(esLogger)
options = append(options, setLogger(l))
return options, nil
}
Expand Down
15 changes: 3 additions & 12 deletions plugin/storage/cassandra/schema/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function usage {
>&2 echo " DEPENDENCIES_TTL - time to live for dependencies data, in seconds (default: 0, no TTL)"
>&2 echo " KEYSPACE - keyspace (default: jaeger_v1_{datacenter})"
>&2 echo " REPLICATION_FACTOR - replication factor for prod (default: 2 for prod, 1 for test)"
>&2 echo " VERSION - Cassandra backend version, 3 or 4 (default: 4). Ignored if template is is provided."
>&2 echo ""
>&2 echo "The template-file argument must be fully qualified path to a v00#.cql.tmpl template file."
>&2 echo "If omitted, the template file with the highest available version will be used."
Expand All @@ -20,17 +21,7 @@ function usage {

trace_ttl=${TRACE_TTL:-172800}
dependencies_ttl=${DEPENDENCIES_TTL:-0}

# Extract cassandra version
#
# $ cqlsh -e "show version"
# [cqlsh 5.0.1 | Cassandra 3.11.11 | CQL spec 3.4.4 | Native protocol v4]
#
cas_version=$(cqlsh -e "show version" \
| awk -F "|" '{print $2}' \
| awk -F " " '{print $2}' \
| awk -F "." '{print $1}' \
)
cas_version=${VERSION:-4}

template=$1
if [[ "$template" == "" ]]; then
Expand All @@ -54,7 +45,7 @@ elif [[ "$MODE" == "prod" ]]; then
datacenter=$DATACENTER
replication_factor=${REPLICATION_FACTOR:-2}
replication="{'class': 'NetworkTopologyStrategy', '$datacenter': '${replication_factor}' }"
elif [[ "$MODE" == "test" ]]; then
elif [[ "$MODE" == "test" ]]; then
datacenter=${DATACENTER:-'test'}
replication_factor=${REPLICATION_FACTOR:-1}
replication="{'class': 'SimpleStrategy', 'replication_factor': '${replication_factor}'}"
Expand Down
34 changes: 23 additions & 11 deletions plugin/storage/cassandra/schema/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ MODE=${MODE:-"test"}
TEMPLATE=${TEMPLATE:-""}
USER=${CASSANDRA_USERNAME:-""}
PASSWORD=${CASSANDRA_PASSWORD:-""}
SCHEMA_SCRIPT=${SCHEMA_SCRIPT:-"/cassandra-schema/create.sh"}

CQLSH_CMD="${CQLSH} ${CQLSH_SSL} ${CQLSH_HOST} ${CQLSH_PORT}"
if [ ! -z "$PASSWORD" ]; then
CQLSH_CMD="${CQLSH_CMD} -u ${USER} -p ${PASSWORD}"
fi

total_wait=0
while true
do
if [ -z "$PASSWORD" ]; then
${CQLSH} ${CQLSH_SSL} ${CQLSH_HOST} ${CQLSH_PORT} -e "describe keyspaces"
else
${CQLSH} ${CQLSH_SSL} ${CQLSH_HOST} ${CQLSH_PORT} -u ${USER} -p ${PASSWORD} -e "describe keyspaces"
fi
echo "Checking if Cassandra is up at ${CQLSH_HOST}:${CQLSH_PORT}."
${CQLSH_CMD} -e "describe keyspaces"
if (( $? == 0 )); then
break
else
Expand All @@ -36,11 +39,20 @@ do
fi
done

echo "Generating the schema for the keyspace ${KEYSPACE} and datacenter ${DATACENTER}"
# Extract cassandra version
#
# $ cqlsh -e "show version"
# [cqlsh 5.0.1 | Cassandra 3.11.11 | CQL spec 3.4.4 | Native protocol v4]
VERSION=
if [ -z "$TEMPLATE" ]; then
VERSION=$(${CQLSH_CMD} -e "show version" \
| awk -F "|" '{print $2}' \
| awk -F " " '{print $2}' \
| awk -F "." '{print $1}' \
)
echo "Cassandra version detected: ${VERSION}"
fi

echo "Generating the schema for the keyspace ${KEYSPACE} and datacenter ${DATACENTER}."

if [ -z "$PASSWORD" ]; then
MODE="${MODE}" DATACENTER="${DATACENTER}" KEYSPACE="${KEYSPACE}" /cassandra-schema/create.sh "${TEMPLATE}" | ${CQLSH} ${CQLSH_SSL} ${CQLSH_HOST} ${CQLSH_PORT}
else
MODE="${MODE}" DATACENTER="${DATACENTER}" KEYSPACE="${KEYSPACE}" /cassandra-schema/create.sh "${TEMPLATE}" | ${CQLSH} ${CQLSH_SSL} ${CQLSH_HOST} ${CQLSH_PORT} -u ${USER} -p ${PASSWORD}
fi
MODE="${MODE}" DATACENTER="${DATACENTER}" KEYSPACE="${KEYSPACE}" VERSION="${VERSION}" ${SCHEMA_SCRIPT} "${TEMPLATE}" | ${CQLSH_CMD}

0 comments on commit 3c8ffd1

Please sign in to comment.