Skip to content

Commit c4e15e7

Browse files
Merge pull request #89 from Percona-Lab/PSMDB_export_fix_v3
Adjust PSMDB tests for PMM3
2 parents a9a4b83 + 47bee28 commit c4e15e7

File tree

9 files changed

+212
-34
lines changed

9 files changed

+212
-34
lines changed

.github/workflows/PMM_PSMDB_PBM.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@ on:
2020
default: "perconalab/pmm-server:3-dev-latest"
2121
required: false
2222

23-
push:
24-
branches:
25-
- main
26-
- v3
27-
28-
pull_request:
29-
branches:
30-
- main
31-
- v3
32-
3323
jobs:
3424
test_replica_set:
3525
runs-on: ubuntu-22.04
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: PMM_PSMDB_PBM_FULL
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
pmm_version:
7+
description: "pmm2-client version"
8+
default: "3-dev-latest"
9+
required: false
10+
pmm_image:
11+
description: "pmm-server docker image"
12+
default: "perconalab/pmm-server:3-dev-latest"
13+
required: false
14+
15+
push:
16+
branches:
17+
- main
18+
- v3
19+
20+
pull_request:
21+
branches:
22+
- main
23+
- v3
24+
25+
jobs:
26+
test_replica_set:
27+
runs-on: ubuntu-22.04
28+
timeout-minutes: 20
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
psmdb: ["6.0", "7.0", "8.0"]
33+
env:
34+
PMM_CLIENT_VERSION: ${{ inputs.pmm_version || '3-dev-latest' }}
35+
PMM_IMAGE: ${{ inputs.pmm_image || 'perconalab/pmm-server:3-dev-latest' }}
36+
steps:
37+
- uses: actions/checkout@v2
38+
- name: Test RS with PSMDB ${{ matrix.psmdb }}
39+
run: |
40+
PSMDB_VERSION=${{ matrix.psmdb }} ./start-rs.sh
41+
working-directory: ./pmm_psmdb-pbm_setup
42+
43+
test_sharded_cluster:
44+
runs-on: ubuntu-22.04
45+
timeout-minutes: 20
46+
strategy:
47+
fail-fast: false
48+
matrix:
49+
psmdb: ["6.0", "7.0", "8.0"]
50+
env:
51+
PMM_CLIENT_VERSION: ${{ inputs.pmm_version || '3-dev-latest' }}
52+
PMM_IMAGE: ${{ inputs.pmm_image || 'perconalab/pmm-server:3-dev-latest' }}
53+
steps:
54+
- uses: actions/checkout@v2
55+
- name: Test sharded with PSMDB ${{ matrix.psmdb }}
56+
run: |
57+
PSMDB_VERSION=${{ matrix.psmdb }} ./start-sharded.sh
58+
working-directory: ./pmm_psmdb-pbm_setup
59+
60+
test_diff_auth:
61+
runs-on: ubuntu-22.04
62+
timeout-minutes: 20
63+
strategy:
64+
fail-fast: false
65+
matrix:
66+
psmdb: ["6.0", "7.0", "8.0"]
67+
env:
68+
PMM_CLIENT_VERSION: ${{ inputs.pmm_version || '3-dev-latest' }}
69+
PMM_IMAGE: ${{ inputs.pmm_image || 'perconalab/pmm-server:3-dev-latest' }}
70+
steps:
71+
- uses: actions/checkout@v3
72+
- name: Test auth with PSMDB ${{ matrix.psmdb }}
73+
run: |
74+
PSMDB_VERSION=${{ matrix.psmdb }} ./test-auth.sh
75+
working-directory: ./pmm_psmdb_diffauth_setup

pmm_psmdb-pbm_setup/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ RUN set -ex; \
2222
export GNUPGHOME="$(mktemp -d)"; \
2323
export PERCONA_TELEMETRY_URL="https://check-dev.percona.com/v1/telemetry/GenericReport"; \
2424
yum install -y gnupg2; \
25-
if [ $PSMDB_VERSION != "latest" ]; then export PSMDB_REPO="$(echo "${PSMDB_VERSION}" | awk -F '.' '{print "psmdb-"$1$2}')" ; else export PSMDB_REPO=psmdb-60 ; fi ; \
25+
if [ $PSMDB_VERSION != "latest" ]; then export PSMDB_REPO="$(echo "${PSMDB_VERSION}" | awk -F '.' '{print "psmdb-"$1$2}')" ; else export PSMDB_REPO=psmdb-80 ; fi ; \
2626
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys 4D1BB29D63D98E422B2113B19334A25F8507EFA5 99DB70FAE1D7CE227FB6488205B555B38483C65D 94E279EB8D8F25B21810ADF121EA45AB2F86D6A1; \
2727
gpg --batch --export --armor 4D1BB29D63D98E422B2113B19334A25F8507EFA5 > ${GNUPGHOME}/PERCONA-PACKAGING-KEY; \
2828
gpg --batch --export --armor 99DB70FAE1D7CE227FB6488205B555B38483C65D > ${GNUPGHOME}/RPM-GPG-KEY-centosofficial; \
@@ -38,7 +38,7 @@ RUN set -ex; \
3838
percona-release enable pmm3-client ${PMM_REPO} && \
3939
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm && \
4040
yum update --refresh -y && \
41-
if [ $PSMDB_VERSION == "latest" ]; then \
41+
if [[ $PSMDB_VERSION == "latest" || "$PSMDB_VERSION" =~ ^[0-9]\.[0-9]$ ]] ; then \
4242
yum -y install percona-server-mongodb \
4343
percona-server-mongodb-tools \
4444
percona-server-mongodb-server \
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
mongodb_up
2+
mongodb_mongod_global_lock_client
3+
mongodb_mongod_global_lock_current_queue
4+
mongodb_mongod_instance_uptime_seconds
5+
mongodb_mongod_locks_time_acquiring_global_microseconds_total
6+
mongodb_mongod_metrics_cursor_open
7+
mongodb_mongod_metrics_cursor_timed_out_total
8+
mongodb_mongod_metrics_document_total
9+
mongodb_mongod_metrics_get_last_error_wtime_num_total
10+
mongodb_mongod_metrics_get_last_error_wtime_total_milliseconds
11+
mongodb_mongod_metrics_get_last_error_wtimeouts_total
12+
mongodb_mongod_metrics_operation_total
13+
mongodb_mongod_metrics_query_executor_total
14+
mongodb_mongod_metrics_ttl_deleted_documents_total
15+
mongodb_mongod_metrics_ttl_passes_total
16+
mongodb_mongod_op_counters_repl_total
17+
mongodb_mongod_op_latencies_latency_total
18+
mongodb_mongod_op_latencies_ops_total
19+
mongodb_mongod_storage_engine
20+
mongodb_mongod_wiredtiger_blockmanager_bytes_total
21+
mongodb_mongod_wiredtiger_cache_bytes
22+
mongodb_mongod_wiredtiger_cache_bytes_total
23+
mongodb_mongod_wiredtiger_cache_evicted_total
24+
mongodb_mongod_wiredtiger_cache_max_bytes
25+
mongodb_mongod_wiredtiger_cache_overhead_percent
26+
mongodb_mongod_wiredtiger_cache_pages
27+
mongodb_mongod_wiredtiger_cache_pages_total
28+
mongodb_mongod_wiredtiger_concurrent_transactions_available_tickets
29+
mongodb_mongod_wiredtiger_concurrent_transactions_out_tickets
30+
mongodb_mongod_wiredtiger_concurrent_transactions_total_tickets
31+
mongodb_mongod_wiredtiger_log_bytes_total
32+
mongodb_mongod_wiredtiger_log_operations_total
33+
mongodb_mongod_wiredtiger_log_records_scanned_total
34+
mongodb_mongod_wiredtiger_log_records_total
35+
mongodb_mongod_wiredtiger_session_open_sessions_total
36+
mongodb_mongod_wiredtiger_transactions_checkpoint_milliseconds
37+
mongodb_mongod_wiredtiger_transactions_checkpoint_milliseconds_total
38+
mongodb_mongod_wiredtiger_transactions_total

pmm_psmdb-pbm_setup/test/test.py

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323

2424

2525
def test_pmm_services():
26-
req = requests.post(f"https://{pmm_server_url}/v1/inventory/Services/List", json={},
26+
req = requests.get(f"https://{pmm_server_url}/v1/inventory/services", json={},
2727
headers={"authorization": "Basic YWRtaW46cGFzc3dvcmQ="}, verify=False)
2828
print('\nGetting all mongodb services:')
2929
mongodb = req.json()['mongodb']
3030
print(mongodb)
3131
assert mongodb
32-
assert "service_id" in mongodb[0]['service_id']
32+
assert "service_id" in mongodb[0]
3333
for service in mongodb:
3434
assert "rs" or "mongos" in service['service_name']
3535
if not "mongos" in service['service_name']:
@@ -49,11 +49,11 @@ def test_pmm_add_location():
4949
'bucket_name': 'bcp'
5050
}
5151
}
52-
req = requests.post(f"https://{pmm_server_url}/v1/management/backup/Locations/Add", json=data,
52+
req = requests.post(f"https://{pmm_server_url}/v1/backups/locations", json=data,
5353
headers={"authorization": "Basic YWRtaW46cGFzc3dvcmQ="}, verify=False)
5454
print('\nAdding new location:')
5555
print(req.json())
56-
assert "location_id" in req.json()['location_id']
56+
assert "location_id" in req.json()
5757
pytest.location_id = req.json()['location_id']
5858

5959

@@ -64,21 +64,23 @@ def test_pmm_logical_backup():
6464
'name': 'test',
6565
'description': 'test',
6666
'retries': 0,
67-
'data_model': 'LOGICAL'
67+
'data_model': 'DATA_MODEL_LOGICAL'
6868
}
69-
req = requests.post(f"https://{pmm_server_url}/v1/management/backup/Backups/Start", json=data,
69+
70+
print(data)
71+
req = requests.post(f"https://{pmm_server_url}/v1/backups:start", json=data,
7072
headers={"authorization": "Basic YWRtaW46cGFzc3dvcmQ="}, verify=False)
7173
print('\nCreating logical backup:')
7274
print(req.json())
73-
assert "artifact_id" in req.json()['artifact_id']
75+
assert "artifact_id" in req.json()
7476
pytest.artifact_id = req.json()['artifact_id']
7577

7678

7779
def test_pmm_artifact():
7880
backup_complete = False
7981
for i in range(600):
8082
done = False
81-
req = requests.post(f"https://{pmm_server_url}/v1/management/backup/Artifacts/List", json={},
83+
req = requests.get(f"https://{pmm_server_url}/v1/backups/artifacts", json={},
8284
headers={"authorization": "Basic YWRtaW46cGFzc3dvcmQ="}, verify=False)
8385
assert req.json()['artifacts']
8486
for artifact in req.json()['artifacts']:
@@ -118,11 +120,11 @@ def test_pmm_start_restore():
118120
'service_id': pytest.service_id,
119121
'artifact_id': pytest.artifact_id
120122
}
121-
req = requests.post(f"https://{pmm_server_url}/v1/management/backup/Backups/Restore", json=data,
123+
req = requests.post(f"https://{pmm_server_url}/v1/backups/restores:start", json=data,
122124
headers={"authorization": "Basic YWRtaW46cGFzc3dvcmQ="}, verify=False)
123125
print('\nRestoring logical backup:')
124126
print(req.json())
125-
assert "restore_id" in req.json()['restore_id']
127+
assert "restore_id" in req.json()
126128
pytest.restore_id = req.json()['restore_id']
127129

128130

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

168170
assert restore_complete
171+
172+
def test_metrics():
173+
pmm_admin_list = json.loads(docker_rs101.check_output('pmm-admin list --json', timeout=30))
174+
for agent in pmm_admin_list['agent']:
175+
if agent['agent_type'] == 'AGENT_TYPE_MONGODB_EXPORTER':
176+
agent_id = agent['agent_id']
177+
agent_port = agent['port']
178+
break
179+
try:
180+
command = f"curl -s http://pmm:{agent_id}@127.0.0.1:{agent_port}/metrics"
181+
metrics = docker_rs101.run(command, timeout=30)
182+
assert metrics.exit_status == 0, f"Curl command failed with exit status {metrics.exit_status}"
183+
except Exception as e:
184+
pytest.fail(f"Fail to get metrics from exporter")
185+
186+
try:
187+
with open("expected_metrics.txt", "r") as f:
188+
expected_metrics = {line.strip() for line in f if line.strip()}
189+
except FileNotFoundError:
190+
pytest.fail("Expected metrics file not found")
191+
192+
for metric in expected_metrics:
193+
if metric not in metrics.stdout:
194+
pytest.fail(f"Metric '{metric}' is missing from the exporter output")

pmm_psmdb_diffauth_setup/init/setup_psmdb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var db = connect("mongodb://dba:secret@localhost:27017/admin");
1+
var db = connect("mongodb://root:root@localhost:27017/admin");
22
db.getSiblingDB("admin").createRole({
33
"role": "pbmAnyAction",
44
"privileges": [{

pmm_psmdb_diffauth_setup/test-auth.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ docker compose -f docker-compose-pmm-psmdb.yml exec -T psmdb-server mgodatagen -
7575
tests=${TESTS:-yes}
7676
if [ $tests = "yes" ]; then
7777
echo "running tests"
78-
docker compose -f docker-compose-pmm-psmdb.yml run test pytest -s -x --verbose test.py
78+
output=$(docker compose -f docker-compose-pmm-psmdb.yml run test pytest -s --verbose test.py)
7979
else
8080
echo "skipping tests"
8181
fi
@@ -90,3 +90,8 @@ if [ $cleanup = "yes" ]; then
9090
else
9191
echo "skipping cleanup"
9292
fi
93+
94+
echo "$output"
95+
if echo "$output" | grep -q "\bFAILED\b"; then
96+
exit 1
97+
fi
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
mongodb_up
2+
mongodb_mongod_global_lock_client
3+
mongodb_mongod_global_lock_current_queue
4+
mongodb_mongod_instance_uptime_seconds
5+
mongodb_mongod_locks_time_acquiring_global_microseconds_total
6+
mongodb_mongod_metrics_cursor_open
7+
mongodb_mongod_metrics_cursor_timed_out_total
8+
mongodb_mongod_metrics_document_total
9+
mongodb_mongod_metrics_get_last_error_wtime_num_total
10+
mongodb_mongod_metrics_get_last_error_wtime_total_milliseconds
11+
mongodb_mongod_metrics_get_last_error_wtimeouts_total
12+
mongodb_mongod_metrics_operation_total
13+
mongodb_mongod_metrics_query_executor_total
14+
mongodb_mongod_metrics_ttl_deleted_documents_total
15+
mongodb_mongod_metrics_ttl_passes_total
16+
mongodb_mongod_op_counters_repl_total
17+
mongodb_mongod_op_latencies_latency_total
18+
mongodb_mongod_op_latencies_ops_total
19+
mongodb_mongod_storage_engine
20+
mongodb_mongod_wiredtiger_blockmanager_bytes_total
21+
mongodb_mongod_wiredtiger_cache_bytes
22+
mongodb_mongod_wiredtiger_cache_bytes_total
23+
mongodb_mongod_wiredtiger_cache_evicted_total
24+
mongodb_mongod_wiredtiger_cache_max_bytes
25+
mongodb_mongod_wiredtiger_cache_overhead_percent
26+
mongodb_mongod_wiredtiger_cache_pages
27+
mongodb_mongod_wiredtiger_cache_pages_total
28+
mongodb_mongod_wiredtiger_concurrent_transactions_available_tickets
29+
mongodb_mongod_wiredtiger_concurrent_transactions_out_tickets
30+
mongodb_mongod_wiredtiger_concurrent_transactions_total_tickets
31+
mongodb_mongod_wiredtiger_log_bytes_total
32+
mongodb_mongod_wiredtiger_log_operations_total
33+
mongodb_mongod_wiredtiger_log_records_scanned_total
34+
mongodb_mongod_wiredtiger_log_records_total
35+
mongodb_mongod_wiredtiger_session_open_sessions_total
36+
mongodb_mongod_wiredtiger_transactions_checkpoint_milliseconds
37+
mongodb_mongod_wiredtiger_transactions_checkpoint_milliseconds_total
38+
mongodb_mongod_wiredtiger_transactions_total

pmm_psmdb_diffauth_setup/test/test.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,26 @@ def run_test(add_db_command):
2525

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

33-
url = f'http://localhost:{agent_port}/metrics'
3439
try:
35-
response = docker_pmm_client.check_output(f"curl --request GET --url {url} --header 'Content-Type: "
36-
f"application/json' --user 'pmm:{agent_id}'")
37-
pattern = r'mongodb_up (\d+)'
38-
result = re.search(pattern, response)
39-
assert result is not None, "MongoDB related data isn't exported"
40-
except AssertionError:
41-
pytest.fail(f"Connection to {url} failed")
40+
with open("expected_metrics.txt", "r") as f:
41+
expected_metrics = {line.strip() for line in f if line.strip()}
42+
except FileNotFoundError:
43+
pytest.fail("Expected metrics file not found")
44+
45+
for metric in expected_metrics:
46+
if metric not in metrics.stdout:
47+
pytest.fail(f"Metric '{metric}' is missing from the exporter output")
4248

4349

4450
def test_simple_auth_wo_tls():

0 commit comments

Comments
 (0)