Skip to content

Commit

Permalink
Merge pull request #89 from Percona-Lab/PSMDB_export_fix_v3
Browse files Browse the repository at this point in the history
Adjust PSMDB tests for PMM3
  • Loading branch information
sandraromanchenko authored Nov 13, 2024
2 parents a9a4b83 + 47bee28 commit c4e15e7
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 34 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/PMM_PSMDB_PBM.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ on:
default: "perconalab/pmm-server:3-dev-latest"
required: false

push:
branches:
- main
- v3

pull_request:
branches:
- main
- v3

jobs:
test_replica_set:
runs-on: ubuntu-22.04
Expand Down
75 changes: 75 additions & 0 deletions .github/workflows/PMM_PSMDB_PBM_FULL.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: PMM_PSMDB_PBM_FULL

on:
workflow_dispatch:
inputs:
pmm_version:
description: "pmm2-client version"
default: "3-dev-latest"
required: false
pmm_image:
description: "pmm-server docker image"
default: "perconalab/pmm-server:3-dev-latest"
required: false

push:
branches:
- main
- v3

pull_request:
branches:
- main
- v3

jobs:
test_replica_set:
runs-on: ubuntu-22.04
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
psmdb: ["6.0", "7.0", "8.0"]
env:
PMM_CLIENT_VERSION: ${{ inputs.pmm_version || '3-dev-latest' }}
PMM_IMAGE: ${{ inputs.pmm_image || 'perconalab/pmm-server:3-dev-latest' }}
steps:
- uses: actions/checkout@v2
- name: Test RS with PSMDB ${{ matrix.psmdb }}
run: |
PSMDB_VERSION=${{ matrix.psmdb }} ./start-rs.sh
working-directory: ./pmm_psmdb-pbm_setup

test_sharded_cluster:
runs-on: ubuntu-22.04
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
psmdb: ["6.0", "7.0", "8.0"]
env:
PMM_CLIENT_VERSION: ${{ inputs.pmm_version || '3-dev-latest' }}
PMM_IMAGE: ${{ inputs.pmm_image || 'perconalab/pmm-server:3-dev-latest' }}
steps:
- uses: actions/checkout@v2
- name: Test sharded with PSMDB ${{ matrix.psmdb }}
run: |
PSMDB_VERSION=${{ matrix.psmdb }} ./start-sharded.sh
working-directory: ./pmm_psmdb-pbm_setup

test_diff_auth:
runs-on: ubuntu-22.04
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
psmdb: ["6.0", "7.0", "8.0"]
env:
PMM_CLIENT_VERSION: ${{ inputs.pmm_version || '3-dev-latest' }}
PMM_IMAGE: ${{ inputs.pmm_image || 'perconalab/pmm-server:3-dev-latest' }}
steps:
- uses: actions/checkout@v3
- name: Test auth with PSMDB ${{ matrix.psmdb }}
run: |
PSMDB_VERSION=${{ matrix.psmdb }} ./test-auth.sh
working-directory: ./pmm_psmdb_diffauth_setup
4 changes: 2 additions & 2 deletions pmm_psmdb-pbm_setup/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ RUN set -ex; \
export GNUPGHOME="$(mktemp -d)"; \
export PERCONA_TELEMETRY_URL="https://check-dev.percona.com/v1/telemetry/GenericReport"; \
yum install -y gnupg2; \
if [ $PSMDB_VERSION != "latest" ]; then export PSMDB_REPO="$(echo "${PSMDB_VERSION}" | awk -F '.' '{print "psmdb-"$1$2}')" ; else export PSMDB_REPO=psmdb-60 ; fi ; \
if [ $PSMDB_VERSION != "latest" ]; then export PSMDB_REPO="$(echo "${PSMDB_VERSION}" | awk -F '.' '{print "psmdb-"$1$2}')" ; else export PSMDB_REPO=psmdb-80 ; fi ; \
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys 4D1BB29D63D98E422B2113B19334A25F8507EFA5 99DB70FAE1D7CE227FB6488205B555B38483C65D 94E279EB8D8F25B21810ADF121EA45AB2F86D6A1; \
gpg --batch --export --armor 4D1BB29D63D98E422B2113B19334A25F8507EFA5 > ${GNUPGHOME}/PERCONA-PACKAGING-KEY; \
gpg --batch --export --armor 99DB70FAE1D7CE227FB6488205B555B38483C65D > ${GNUPGHOME}/RPM-GPG-KEY-centosofficial; \
Expand All @@ -38,7 +38,7 @@ RUN set -ex; \
percona-release enable pmm3-client ${PMM_REPO} && \
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm && \
yum update --refresh -y && \
if [ $PSMDB_VERSION == "latest" ]; then \
if [[ $PSMDB_VERSION == "latest" || "$PSMDB_VERSION" =~ ^[0-9]\.[0-9]$ ]] ; then \
yum -y install percona-server-mongodb \
percona-server-mongodb-tools \
percona-server-mongodb-server \
Expand Down
38 changes: 38 additions & 0 deletions pmm_psmdb-pbm_setup/test/expected_metrics.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
mongodb_up
mongodb_mongod_global_lock_client
mongodb_mongod_global_lock_current_queue
mongodb_mongod_instance_uptime_seconds
mongodb_mongod_locks_time_acquiring_global_microseconds_total
mongodb_mongod_metrics_cursor_open
mongodb_mongod_metrics_cursor_timed_out_total
mongodb_mongod_metrics_document_total
mongodb_mongod_metrics_get_last_error_wtime_num_total
mongodb_mongod_metrics_get_last_error_wtime_total_milliseconds
mongodb_mongod_metrics_get_last_error_wtimeouts_total
mongodb_mongod_metrics_operation_total
mongodb_mongod_metrics_query_executor_total
mongodb_mongod_metrics_ttl_deleted_documents_total
mongodb_mongod_metrics_ttl_passes_total
mongodb_mongod_op_counters_repl_total
mongodb_mongod_op_latencies_latency_total
mongodb_mongod_op_latencies_ops_total
mongodb_mongod_storage_engine
mongodb_mongod_wiredtiger_blockmanager_bytes_total
mongodb_mongod_wiredtiger_cache_bytes
mongodb_mongod_wiredtiger_cache_bytes_total
mongodb_mongod_wiredtiger_cache_evicted_total
mongodb_mongod_wiredtiger_cache_max_bytes
mongodb_mongod_wiredtiger_cache_overhead_percent
mongodb_mongod_wiredtiger_cache_pages
mongodb_mongod_wiredtiger_cache_pages_total
mongodb_mongod_wiredtiger_concurrent_transactions_available_tickets
mongodb_mongod_wiredtiger_concurrent_transactions_out_tickets
mongodb_mongod_wiredtiger_concurrent_transactions_total_tickets
mongodb_mongod_wiredtiger_log_bytes_total
mongodb_mongod_wiredtiger_log_operations_total
mongodb_mongod_wiredtiger_log_records_scanned_total
mongodb_mongod_wiredtiger_log_records_total
mongodb_mongod_wiredtiger_session_open_sessions_total
mongodb_mongod_wiredtiger_transactions_checkpoint_milliseconds
mongodb_mongod_wiredtiger_transactions_checkpoint_milliseconds_total
mongodb_mongod_wiredtiger_transactions_total
48 changes: 37 additions & 11 deletions pmm_psmdb-pbm_setup/test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@


def test_pmm_services():
req = requests.post(f"https://{pmm_server_url}/v1/inventory/Services/List", json={},
req = requests.get(f"https://{pmm_server_url}/v1/inventory/services", json={},
headers={"authorization": "Basic YWRtaW46cGFzc3dvcmQ="}, verify=False)
print('\nGetting all mongodb services:')
mongodb = req.json()['mongodb']
print(mongodb)
assert mongodb
assert "service_id" in mongodb[0]['service_id']
assert "service_id" in mongodb[0]
for service in mongodb:
assert "rs" or "mongos" in service['service_name']
if not "mongos" in service['service_name']:
Expand All @@ -49,11 +49,11 @@ def test_pmm_add_location():
'bucket_name': 'bcp'
}
}
req = requests.post(f"https://{pmm_server_url}/v1/management/backup/Locations/Add", json=data,
req = requests.post(f"https://{pmm_server_url}/v1/backups/locations", json=data,
headers={"authorization": "Basic YWRtaW46cGFzc3dvcmQ="}, verify=False)
print('\nAdding new location:')
print(req.json())
assert "location_id" in req.json()['location_id']
assert "location_id" in req.json()
pytest.location_id = req.json()['location_id']


Expand All @@ -64,21 +64,23 @@ def test_pmm_logical_backup():
'name': 'test',
'description': 'test',
'retries': 0,
'data_model': 'LOGICAL'
'data_model': 'DATA_MODEL_LOGICAL'
}
req = requests.post(f"https://{pmm_server_url}/v1/management/backup/Backups/Start", json=data,

print(data)
req = requests.post(f"https://{pmm_server_url}/v1/backups:start", json=data,
headers={"authorization": "Basic YWRtaW46cGFzc3dvcmQ="}, verify=False)
print('\nCreating logical backup:')
print(req.json())
assert "artifact_id" in req.json()['artifact_id']
assert "artifact_id" in req.json()
pytest.artifact_id = req.json()['artifact_id']


def test_pmm_artifact():
backup_complete = False
for i in range(600):
done = False
req = requests.post(f"https://{pmm_server_url}/v1/management/backup/Artifacts/List", json={},
req = requests.get(f"https://{pmm_server_url}/v1/backups/artifacts", json={},
headers={"authorization": "Basic YWRtaW46cGFzc3dvcmQ="}, verify=False)
assert req.json()['artifacts']
for artifact in req.json()['artifacts']:
Expand Down Expand Up @@ -118,11 +120,11 @@ def test_pmm_start_restore():
'service_id': pytest.service_id,
'artifact_id': pytest.artifact_id
}
req = requests.post(f"https://{pmm_server_url}/v1/management/backup/Backups/Restore", json=data,
req = requests.post(f"https://{pmm_server_url}/v1/backups/restores:start", json=data,
headers={"authorization": "Basic YWRtaW46cGFzc3dvcmQ="}, verify=False)
print('\nRestoring logical backup:')
print(req.json())
assert "restore_id" in req.json()['restore_id']
assert "restore_id" in req.json()
pytest.restore_id = req.json()['restore_id']


Expand All @@ -132,7 +134,7 @@ def test_pmm_restore():
restore_complete = False
for i in range(600):
done = False
req = requests.post(f"https://{pmm_server_url}/v1/management/backup/RestoreHistory/List", json={},
req = requests.get(f"https://{pmm_server_url}/v1/backups/restores", json={},
headers={"authorization": "Basic YWRtaW46cGFzc3dvcmQ="}, verify=False)
assert req.json()['items']
for item in req.json()['items']:
Expand Down Expand Up @@ -166,3 +168,27 @@ def test_pbm_restore():
restore_complete = True

assert restore_complete

def test_metrics():
pmm_admin_list = json.loads(docker_rs101.check_output('pmm-admin list --json', timeout=30))
for agent in pmm_admin_list['agent']:
if agent['agent_type'] == 'AGENT_TYPE_MONGODB_EXPORTER':
agent_id = agent['agent_id']
agent_port = agent['port']
break
try:
command = f"curl -s http://pmm:{agent_id}@127.0.0.1:{agent_port}/metrics"
metrics = docker_rs101.run(command, timeout=30)
assert metrics.exit_status == 0, f"Curl command failed with exit status {metrics.exit_status}"
except Exception as e:
pytest.fail(f"Fail to get metrics from exporter")

try:
with open("expected_metrics.txt", "r") as f:
expected_metrics = {line.strip() for line in f if line.strip()}
except FileNotFoundError:
pytest.fail("Expected metrics file not found")

for metric in expected_metrics:
if metric not in metrics.stdout:
pytest.fail(f"Metric '{metric}' is missing from the exporter output")
2 changes: 1 addition & 1 deletion pmm_psmdb_diffauth_setup/init/setup_psmdb.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var db = connect("mongodb://dba:secret@localhost:27017/admin");
var db = connect("mongodb://root:root@localhost:27017/admin");
db.getSiblingDB("admin").createRole({
"role": "pbmAnyAction",
"privileges": [{
Expand Down
7 changes: 6 additions & 1 deletion pmm_psmdb_diffauth_setup/test-auth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ docker compose -f docker-compose-pmm-psmdb.yml exec -T psmdb-server mgodatagen -
tests=${TESTS:-yes}
if [ $tests = "yes" ]; then
echo "running tests"
docker compose -f docker-compose-pmm-psmdb.yml run test pytest -s -x --verbose test.py
output=$(docker compose -f docker-compose-pmm-psmdb.yml run test pytest -s --verbose test.py)
else
echo "skipping tests"
fi
Expand All @@ -90,3 +90,8 @@ if [ $cleanup = "yes" ]; then
else
echo "skipping cleanup"
fi

echo "$output"
if echo "$output" | grep -q "\bFAILED\b"; then
exit 1
fi
38 changes: 38 additions & 0 deletions pmm_psmdb_diffauth_setup/test/expected_metrics.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
mongodb_up
mongodb_mongod_global_lock_client
mongodb_mongod_global_lock_current_queue
mongodb_mongod_instance_uptime_seconds
mongodb_mongod_locks_time_acquiring_global_microseconds_total
mongodb_mongod_metrics_cursor_open
mongodb_mongod_metrics_cursor_timed_out_total
mongodb_mongod_metrics_document_total
mongodb_mongod_metrics_get_last_error_wtime_num_total
mongodb_mongod_metrics_get_last_error_wtime_total_milliseconds
mongodb_mongod_metrics_get_last_error_wtimeouts_total
mongodb_mongod_metrics_operation_total
mongodb_mongod_metrics_query_executor_total
mongodb_mongod_metrics_ttl_deleted_documents_total
mongodb_mongod_metrics_ttl_passes_total
mongodb_mongod_op_counters_repl_total
mongodb_mongod_op_latencies_latency_total
mongodb_mongod_op_latencies_ops_total
mongodb_mongod_storage_engine
mongodb_mongod_wiredtiger_blockmanager_bytes_total
mongodb_mongod_wiredtiger_cache_bytes
mongodb_mongod_wiredtiger_cache_bytes_total
mongodb_mongod_wiredtiger_cache_evicted_total
mongodb_mongod_wiredtiger_cache_max_bytes
mongodb_mongod_wiredtiger_cache_overhead_percent
mongodb_mongod_wiredtiger_cache_pages
mongodb_mongod_wiredtiger_cache_pages_total
mongodb_mongod_wiredtiger_concurrent_transactions_available_tickets
mongodb_mongod_wiredtiger_concurrent_transactions_out_tickets
mongodb_mongod_wiredtiger_concurrent_transactions_total_tickets
mongodb_mongod_wiredtiger_log_bytes_total
mongodb_mongod_wiredtiger_log_operations_total
mongodb_mongod_wiredtiger_log_records_scanned_total
mongodb_mongod_wiredtiger_log_records_total
mongodb_mongod_wiredtiger_session_open_sessions_total
mongodb_mongod_wiredtiger_transactions_checkpoint_milliseconds
mongodb_mongod_wiredtiger_transactions_checkpoint_milliseconds_total
mongodb_mongod_wiredtiger_transactions_total
24 changes: 15 additions & 9 deletions pmm_psmdb_diffauth_setup/test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,26 @@ def run_test(add_db_command):

pmm_admin_list = json.loads(docker_pmm_client.check_output('pmm-admin list --json', timeout=30))
for agent in pmm_admin_list['agent']:
if agent['agent_type'] == 'MONGODB_EXPORTER':
if agent['agent_type'] == 'AGENT_TYPE_MONGODB_EXPORTER':
agent_id = agent['agent_id']
agent_port = agent['port']
break
try:
command = f"curl -s http://pmm:{agent_id}@127.0.0.1:{agent_port}/metrics"
metrics = docker_pmm_client.run(command, timeout=30)
assert metrics.exit_status == 0, f"Curl command failed with exit status {metrics.exit_status}"
except Exception as e:
pytest.fail(f"Fail to get metrics from exporter")

url = f'http://localhost:{agent_port}/metrics'
try:
response = docker_pmm_client.check_output(f"curl --request GET --url {url} --header 'Content-Type: "
f"application/json' --user 'pmm:{agent_id}'")
pattern = r'mongodb_up (\d+)'
result = re.search(pattern, response)
assert result is not None, "MongoDB related data isn't exported"
except AssertionError:
pytest.fail(f"Connection to {url} failed")
with open("expected_metrics.txt", "r") as f:
expected_metrics = {line.strip() for line in f if line.strip()}
except FileNotFoundError:
pytest.fail("Expected metrics file not found")

for metric in expected_metrics:
if metric not in metrics.stdout:
pytest.fail(f"Metric '{metric}' is missing from the exporter output")


def test_simple_auth_wo_tls():
Expand Down

0 comments on commit c4e15e7

Please sign in to comment.