Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSMDB. Fix script exit code and change the way to get PMM metrics #71

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -68,7 +68,7 @@ done
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 -x --verbose test.py)
else
echo "skipping tests"
fi
Expand All @@ -83,3 +83,8 @@ if [ $cleanup = "yes" ]; then
else
echo "skipping cleanup"
fi

echo "$output"
if echo "$output" | grep -q "\bFAILED\b"; then
exit 1
fi
17 changes: 9 additions & 8 deletions pmm_psmdb_diffauth_setup/test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ def run_test(add_db_command):
agent_port = agent['port']
break

url = f'http://psmdb-server:{agent_port}/metrics'
agent_id_parts = agent_id.split('/')
agent_pass = f"%2F{agent_id_parts[1]}%2F{agent_id_parts[2]}"

try:
response = requests.get(url, auth=('pmm', agent_id), timeout=5)
assert response.status_code == 200, f"Request for metrics failed with status code {response.status_code}"
pattern = r'mongodb_up (\d+)'
result = re.search(pattern, response.text)
assert result is not None, "MongoDB related data isn't exported"
except requests.exceptions.ConnectionError:
pytest.fail(f"Connection to {url} failed")
command = f"curl http://pmm:{agent_pass}@127.0.0.1:{agent_port}/metrics"
metrics = docker_pmm_client.run(command, timeout=30)
except Exception as e:
pytest.fail(f"Fail to get metrics from exporter")
if "mongodb_up" not in metrics.stdout:
pytest.fail("MongoDB related data isn't exported")

def test_simple_auth_wo_tls():
run_test('pmm-admin add mongodb psmdb-server --username=pmm_mongodb --password="5M](Q%q/U+YQ<^m" '\
Expand Down
Loading