Apache Solr open-source search software
SOLR-14858: Add docker test for the prometheus exporter (#509)
Houston Putmanf41f1231f483
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 5f9238cc547..260b277ec22 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -469,6 +469,9 @@ Other Changes* SOLR-15845: Add a new SolrVersion class to manage Solr's version independently from the Lucene version we consume (janhoy)+* SOLR-14858: Add the server WEB-INF/lib directory to the classpath for the solr-exporter script. Will allow the script+ to work when the dist/solrj-lib jars are missing in the Docker image. (Houston Putman)+Bug Fixes---------------------* SOLR-15849: Fix the connection reset problem caused by the incorrect use of 4LW with \n when monitoring zooKeeper status (Fa Ming).diff --git a/solr/contrib/prometheus-exporter/bin/solr-exporter b/solr/contrib/prometheus-exporter/bin/solr-exporterindex e53c46149db..872925fac7a 100755--- a/solr/contrib/prometheus-exporter/bin/solr-exporter+++ b/solr/contrib/prometheus-exporter/bin/solr-exporter@@ -73,15 +73,7 @@ thenREPO="$BASEDIR"/libfi-CLASSPATH=$CLASSPATH_PREFIX:$BASEDIR/conf-for JAR in $(find "$REPO" -name '*.jar')-do- CLASSPATH="$CLASSPATH":"$JAR"-done-for JAR in $(find "$BASEDIR"/../../dist/solrj-lib -name '*.jar')-do- CLASSPATH="$CLASSPATH":"$JAR"-done+CLASSPATH=$CLASSPATH_PREFIX:"$BASEDIR/conf":"$REPO/*":"$BASEDIR/../../dist/solrj-lib/*"for JAR in $(find "$BASEDIR"/../../dist -name 'solr-solrj-*.jar')doCLASSPATH="$CLASSPATH":"$JAR"@@ -90,10 +82,7 @@ for JAR in $(find "$BASEDIR"/../../dist -name 'solr-prometheus-exporter-*.jar')doCLASSPATH="$CLASSPATH":"$JAR"done-for JAR in $(find "$BASEDIR"/../../server/lib/ext -name '*.jar')-do- CLASSPATH="$CLASSPATH":"$JAR"-done+CLASSPATH="$CLASSPATH":"$BASEDIR/../../server/solr-webapp/webapp/WEB-INF/lib/*":"$BASEDIR/../../server/lib/ext/*"# Memory settingsJAVA_MEM_OPTS=diff --git a/solr/docker/templates/Dockerfile.body.template b/solr/docker/templates/Dockerfile.body.templateindex 0f462d2287f..19e84776083 100644--- a/solr/docker/templates/Dockerfile.body.template+++ b/solr/docker/templates/Dockerfile.body.template@@ -26,9 +26,7 @@#-##-#-# remove what we don't want; ensure permissions are right-# In the header templates, all solr files/directories are set to 0644 permissions, so we need to update that.-# TODO; arguably these permissions should have been set correctly previously in the TAR+# add symlink to /opt/solr, remove what we don't wantRUN set -ex; \(cd /opt; ln -s solr-*/ solr); \rm -Rf /opt/solr/docs /opt/solr/dist/solr-solrj-*.jar /opt/solr/dist/solrj-lib /opt/solr/dist/solr-core-*.jar;diff --git a/solr/docker/tests/cases/prometheus-exporter/test.sh b/solr/docker/tests/cases/prometheus-exporter/test.shnew file mode 100755index 00000000000..c615d3c5ba0--- /dev/null+++ b/solr/docker/tests/cases/prometheus-exporter/test.sh@@ -0,0 +1,53 @@+#!/bin/bash+# 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.++set -euo pipefail++TEST_DIR="${TEST_DIR:-$(dirname -- "${BASH_SOURCE[0]}")}"+source "${TEST_DIR}/../../shared.sh"++container_cleanup "${container_name}-solr"++echo "Running $container_name"+docker run --name "${container_name}-solr" -d "$tag" "solr-demo"++wait_for_container_and_solr "${container_name}-solr"++solr_ip=$(docker inspect --format="{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" "${container_name}-solr")++docker run --name "$container_name" --add-host "solr-host:${solr_ip}" -d \+ --env "SOLR_URL=http://solr-host:8983/solr" \+ --env "SCRAPE_INTERVAL=1" \+ "$tag" "solr-exporter"++wait_for_container_and_solr_exporter "${container_name}"++echo "Submitting Solr query"+docker exec --user=solr "${container_name}-solr" wget -q -O - 'http://localhost:8983/solr/demo/select?q=id%3Adell' > /dev/null++echo "Checking prometheus data"+data=$(docker exec --user=solr "$container_name" wget -q -O - 'http://localhost:8989/metrics')++if ! grep -E -q 'solr_metrics_core_query_local_count{category="QUERY",searchHandler="/select",core="demo",base_url="http://solr-host:8983/solr",} [0-9]+.0' <<<"$data"; then+ echo "Test $TEST_NAME $tag failed; did not find correct data"+ echo "$data"+ exit 1+fi++container_cleanup "${container_name}-solr"+container_cleanup "$container_name"++echo "Test $TEST_NAME $tag succeeded"diff --git a/solr/docker/tests/shared.sh b/solr/docker/tests/shared.shindex a07661c4999..a0dd04c3c9b 100755--- a/solr/docker/tests/shared.sh+++ b/solr/docker/tests/shared.sh@@ -51,6 +51,25 @@ function wait_for_container_and_solr {sleep 4}+function wait_for_container_and_solr_exporter {+ local container_name+ container_name=$1+ wait_for_server_started "$container_name" 0 'org.apache.solr.prometheus.exporter.SolrExporter; Solr Prometheus Exporter is running'++ printf '\nWaiting for Solr Prometheus Exporter...\n'+ local status+ status=$(docker exec --env SOLR_PORT=8989 "$container_name" wait-for-solr.sh --max-attempts 15 --wait-seconds 1)+# echo "Got status from Solr Prometheus Exporter: $status"+ if ! grep -E -i -q 'Solr is running' <<<"$status"; then+ echo "Solr Prometheus Exporter did not start"+ container_cleanup "$container_name"+ exit 1+ else+ echo "Solr Prometheus Exporter is running"+ fi+ sleep 4+}+function wait_for_server_started {local container_namecontainer_name=$1@@ -59,6 +78,11 @@ function wait_for_server_started {if [ -n "${2:-}" ]; thensleep_time=$2fi+ local log_grep+ log_grep='(o\.e\.j\.s\.Server Started|Started SocketConnector)'+ if [ -n "${3:-}" ]; then+ log_grep=$3+ fiecho "Waiting for container start: $container_name"local TIMEOUT_SECONDSTIMEOUT_SECONDS=$(( 5 * 60 ))@@ -68,7 +92,7 @@ function wait_for_server_started {log="${BUILD_DIR}/${container_name}.log"while true; dodocker logs "$container_name" > "${log}" 2>&1- if grep -E -q '(o\.e\.j\.s\.Server Started|Started SocketConnector)' "${log}" ; then+ if grep -E -q "${log_grep}" "${log}" ; thendocker logs "$container_name"breakfi@@ -76,7 +100,7 @@ function wait_for_server_started {local container_statuscontainer_status=$(docker inspect --format='{{.State.Status}}' "$container_name")if [[ $container_status == 'exited' ]]; then- echo "container exited"+ docker logs "$container_name"exit 1fi