This is an automated email from the ASF dual-hosted git repository.
houston pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new 87dc2e9 SOLR-14858: Add docker test for the prometheus exporter (#509)
87dc2e9 is described below
commit 87dc2e97dff06981884ca7b712eec6cd56614804
Author: Houston Putman <[email protected]>
AuthorDate: Tue Jan 11 17:45:31 2022 -0500
SOLR-14858: Add docker test for the prometheus exporter (#509)
Add the server WEB-INF/lib directory to the classpath of the solr-exporter,
for use in the Docker image.
---
solr/CHANGES.txt | 3 ++
solr/contrib/prometheus-exporter/bin/solr-exporter | 15 +-----
solr/docker/templates/Dockerfile.body.template | 4 +-
.../docker/tests/cases/prometheus-exporter/test.sh | 53 ++++++++++++++++++++++
solr/docker/tests/shared.sh | 28 +++++++++++-
5 files changed, 85 insertions(+), 18 deletions(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 0e37054..f7b5d06 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-exporter
index e53c461..872925f 100755
--- a/solr/contrib/prometheus-exporter/bin/solr-exporter
+++ b/solr/contrib/prometheus-exporter/bin/solr-exporter
@@ -73,15 +73,7 @@ then
REPO="$BASEDIR"/lib
fi
-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')
do
CLASSPATH="$CLASSPATH":"$JAR"
@@ -90,10 +82,7 @@ for JAR in $(find "$BASEDIR"/../../dist -name
'solr-prometheus-exporter-*.jar')
do
CLASSPATH="$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 settings
JAVA_MEM_OPTS=
diff --git a/solr/docker/templates/Dockerfile.body.template
b/solr/docker/templates/Dockerfile.body.template
index 0f462d2..19e8477 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 want
RUN 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.sh
new file mode 100755
index 0000000..c615d3c
--- /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.sh
index a07661c..a0dd04c 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_name
container_name=$1
@@ -59,6 +78,11 @@ function wait_for_server_started {
if [ -n "${2:-}" ]; then
sleep_time=$2
fi
+ local log_grep
+ log_grep='(o\.e\.j\.s\.Server Started|Started SocketConnector)'
+ if [ -n "${3:-}" ]; then
+ log_grep=$3
+ fi
echo "Waiting for container start: $container_name"
local TIMEOUT_SECONDS
TIMEOUT_SECONDS=$(( 5 * 60 ))
@@ -68,7 +92,7 @@ function wait_for_server_started {
log="${BUILD_DIR}/${container_name}.log"
while true; do
docker 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}" ; then
docker logs "$container_name"
break
fi
@@ -76,7 +100,7 @@ function wait_for_server_started {
local container_status
container_status=$(docker inspect --format='{{.State.Status}}'
"$container_name")
if [[ $container_status == 'exited' ]]; then
- echo "container exited"
+ docker logs "$container_name"
exit 1
fi