From 0764ec6f16279abe20fbfff8629982ea8db02ea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C4=8Ctvrtka?= <62988319+JiriCtvrtka@users.noreply.github.com> Date: Mon, 15 Jan 2024 09:57:42 +0100 Subject: [PATCH] PMM-12712 Shards collector. (#762) * PMM-12712 Shard ID and count. * PMM-12712 Name and count. * PMM-12712 Sharded collector. * PMM-12712 Remove missed print. * PMM-12712 Revert test changes. * PMM-12712 Revert old not related changes. * PMM-12712 Another changes. * PMM-12712 Missed print. * PMM-12712 Align naming with task description. * PMM-12712 Add mongos test client. * PMM-12712 Lint. * PMM-12712 Lint. * PMM-12712 Typo. * PMM-12712 Lint. * PMM-12712 Test higher sleep. * Revert "PMM-12712 Test higher sleep." This reverts commit 88451ba6b8a01d7c9b97daf4ac17a1c19a28f82b. * PMM-12712 Test of pipeline. * PMM-12712 Change. * PMM-12712 Test. * PMM-12712 Test. * PMM-12712 Test. * PMM-12712 Correct aggregation to get chunks info. * PMM-12712 Another progress. * PMM-12702 Small refactor. * PMM-12712 Test. * PMM-12712 Fix, tests. * PMM-12712 Temp. * PMM-12712 Improve sharded test. * PMM-12712 Change in workflow. * PMM-12712 Remove print. * PMM-12712 Init script changes. * PMM-12712 Remove print. * PMM-12712 Bigger sleep. * PMM-12712 Refactor. * PMM-12712 Small refactor. * PMM-12712 Another refactor. * PMM-12712 Fix after refactor. * PMM-12712 Alias. * PMM-12712 Alias for shell in older versions. * PMM-12712 Static test shard. * PMM-12712 Fix another tests, mongo 4 shell script. * PMM-12712 Big sleep test. * PMM-12712 Michael's fix. * PMM-12712 Sleep. * PMM-12712 Env. * PMM-12712 Test. * PMM-12712 Fix test. * PMM-12712 Bigger sleep after changes. * PMM-12712 Remove duplicate lines. * PMM-12712 Renaming from sharded to shards. * PMM-12712 Better script to detect proper mongo client. * PMM-12712 Init script refactor. * PMM-12712 Fix. * PMM-12712 Small refactor. * Update main.go Co-authored-by: Michael Okoko <10512379+idoqo@users.noreply.github.com> * Update exporter/shards_collector.go Co-authored-by: Michael Okoko <10512379+idoqo@users.noreply.github.com> * PMM-12712 Remove mongo 6 for now, skip test for shards. * PMM-12712 Revert sleep length. * PMM-12712 Mongo client based on vendor. --------- Co-authored-by: Michael Okoko <10512379+idoqo@users.noreply.github.com> --- docker-compose.yml | 4 + docker/scripts/init-shard.sh | 20 +++- docker/scripts/setup.sh | 18 ++- exporter/exporter.go | 10 ++ exporter/shards_collector.go | 189 ++++++++++++++++++++++++++++++ exporter/shards_collector_test.go | 69 +++++++++++ internal/tu/testutils.go | 11 ++ main.go | 2 + 8 files changed, 318 insertions(+), 5 deletions(-) create mode 100644 exporter/shards_collector.go create mode 100644 exporter/shards_collector_test.go diff --git a/docker-compose.yml b/docker-compose.yml index b5530552b..92e51f9ef 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -56,6 +56,7 @@ services: - MONGO3=mongo-1-3 - ARBITER=mongo-1-arbiter - RS=rs1 + - VERSION=${TEST_MONGODB_IMAGE} entrypoint: [ "/scripts/setup.sh" ] networks: - rs1 @@ -112,6 +113,7 @@ services: - MONGO3=mongo-2-3 - ARBITER=mongo-2-arbiter - RS=rs2 + - VERSION=${TEST_MONGODB_IMAGE} entrypoint: [ "/scripts/setup.sh" ] networks: - rs2 @@ -162,6 +164,7 @@ services: - MONGO3=mongo-cnf-3 - RS=cnf-serv - PORT=27017 + - VERSION=${TEST_MONGODB_IMAGE} entrypoint: [ "/scripts/setup.sh","cnf_servers" ] networks: - cnf-serv @@ -205,6 +208,7 @@ services: - PORT1=27017 - PORT2=27017 - PORT3=27017 + - VERSION=${TEST_MONGODB_IMAGE} entrypoint: [ "/scripts/init-shard.sh" ] restart: on-failure:20 diff --git a/docker/scripts/init-shard.sh b/docker/scripts/init-shard.sh index 8467b74f8..f5de49498 100755 --- a/docker/scripts/init-shard.sh +++ b/docker/scripts/init-shard.sh @@ -1,4 +1,16 @@ #!/bin/bash +# `mongosh` is used starting from MongoDB 5.x +MONGODB_CLIENT="mongosh --quiet" +PARSED=(${VERSION//:/ }) +MONGODB_VERSION=${PARSED[1]} +MONGODB_VENDOR=${PARSED[0]} +if [ "`echo ${MONGODB_VERSION} | cut -c 1`" = "4" ]; then + MONGODB_CLIENT="mongo" +fi +if [ "`echo ${MONGODB_VERSION} | cut -c 1`" = "5" ] && [ ${MONGODB_VENDOR} == "percona/percona-server-mongodb" ]; then + MONGODB_CLIENT="mongo" +fi +echo "MongoDB vendor, client and version: ${MONGODB_VENDOR} ${MONGODB_CLIENT} ${MONGODB_VERSION}" mongodb1=`getent hosts ${MONGOS} | awk '{ print $1 }'` @@ -17,7 +29,7 @@ mongodb33=`getent hosts ${MONGO33} | awk '{ print $1 }'` port=${PORT:-27017} echo "Waiting for startup.." -until mongo --host ${mongodb1}:${port} --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)' &>/dev/null; do +until ${MONGODB_CLIENT} --host ${mongodb1}:${port} --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)' &>/dev/null; do printf '.' sleep 1 done @@ -25,8 +37,12 @@ done echo "Started.." echo init-shard.sh time now: `date +"%T" ` -mongo --host ${mongodb1}:${port} </dev/null; do +until ${MONGODB_CLIENT} --host ${mongodb1}:${port} --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)' &>/dev/null; do printf '.' sleep 1 done @@ -20,7 +32,7 @@ echo setup.sh time now: `date +"%T" ` function cnf_servers() { echo "setup cnf servers on ${MONGO1}(${mongodb1}:${port})" - mongo --host ${mongodb1}:${port} <