diff --git a/.github/workflows/agent.yml b/.github/workflows/agent.yml index 957d19720e..50c509a0e4 100644 --- a/.github/workflows/agent.yml +++ b/.github/workflows/agent.yml @@ -28,15 +28,18 @@ jobs: strategy: matrix: images: - - { mysql: 'mysql:5.6', mongo: 'mongo:4.4', postgres: 'postgres:10', pmm_server: 'perconalab/pmm-server:3-dev-latest' } - - { mysql: 'mysql:5.7', mongo: 'mongo:4.4', postgres: 'postgres:11', pmm_server: 'perconalab/pmm-server:3-dev-latest' } - - { mysql: 'mysql:8.0', mongo: 'mongo:4.4', postgres: 'postgres:12', pmm_server: 'perconalab/pmm-server:3-dev-latest' } - - { mysql: 'mysql:8.0', mongo: 'mongo:4.4', postgres: 'postgres:13', pmm_server: 'perconalab/pmm-server:3-dev-latest' } + - { mysql: 'mysql:5.6', mongo: 'mongo:4.4', postgres: 'postgres:13', pmm_server: 'perconalab/pmm-server:3-dev-latest' } + - { mysql: 'mysql:5.7', mongo: 'mongo:5.0', postgres: 'postgres:14', pmm_server: 'perconalab/pmm-server:3-dev-latest' } + - { mysql: 'mysql:8.0', mongo: 'mongo:6.0', postgres: 'postgres:15', pmm_server: 'perconalab/pmm-server:3-dev-latest' } + - { mysql: 'mysql:lts', mongo: 'mongo:7.0', postgres: 'postgres:16', pmm_server: 'perconalab/pmm-server:3-dev-latest' } + - { mysql: 'mysql:latest', mongo: 'mongo:latest', postgres: 'postgres:latest', pmm_server: 'perconalab/pmm-server:3-dev-latest' } # Percona + latest PMM Server release - - { mysql: 'percona:5.6', mongo: 'percona/percona-server-mongodb:4.4', postgres: 'perconalab/percona-distribution-postgresql:11', pg_libs: 'pg_stat_statements,pg_stat_monitor', pmm_server: 'perconalab/pmm-server:3-dev-latest' } - - { mysql: 'percona:5.7', mongo: 'percona/percona-server-mongodb:4.4', postgres: 'perconalab/percona-distribution-postgresql:12.8-pg_stat', pg_libs: 'pg_stat_statements,pg_stat_monitor', pmm_server: 'perconalab/pmm-server:3-dev-latest' } - - { mysql: 'percona:8.0', mongo: 'percona/percona-server-mongodb:4.4', postgres: 'perconalab/percona-distribution-postgresql:13.5-pg_stat', pg_libs: 'pg_stat_statements,pg_stat_monitor', pmm_server: 'perconalab/pmm-server:3-dev-latest' } + - { mysql: 'percona:5.6', mongo: 'percona/percona-server-mongodb:4.4', postgres: 'perconalab/percona-distribution-postgresql:14', pg_libs: 'pg_stat_statements,pg_stat_monitor', pmm_server: 'perconalab/pmm-server:3-dev-latest' } + - { mysql: 'percona:5.7', mongo: 'percona/percona-server-mongodb:5.0', postgres: 'perconalab/percona-distribution-postgresql:15', pg_libs: 'pg_stat_statements,pg_stat_monitor', pmm_server: 'perconalab/pmm-server:3-dev-latest' } + - { mysql: 'percona:8.0', mongo: 'percona/percona-server-mongodb:6.0', postgres: 'perconalab/percona-distribution-postgresql:16', pg_libs: 'pg_stat_statements,pg_stat_monitor', pmm_server: 'perconalab/pmm-server:3-dev-latest' } + - { mysql: 'percona:8', mongo: 'percona/percona-server-mongodb:7.0', postgres: 'perconalab/percona-distribution-postgresql:17', pg_libs: 'pg_stat_statements,pg_stat_monitor', pmm_server: 'perconalab/pmm-server:3-dev-latest' } + - { mysql: 'percona:latest', mongo: 'percona/percona-server-mongodb:latest', postgres: 'perconalab/percona-distribution-postgresql:latest', pg_libs: 'pg_stat_statements,pg_stat_monitor', pmm_server: 'perconalab/pmm-server:3-dev-latest' } # MariaDB (only 3 latest GA versions) # + older supported MongoDB versions @@ -46,9 +49,9 @@ jobs: # - MYSQL_IMAGE=mariadb:10.0 # - MYSQL_IMAGE=mariadb:10.1 - - { mysql: 'mariadb:10.2', mongo: 'mongo:4.4', postgres: 'postgres:9.4', pmm_server: 'perconalab/pmm-server:3-dev-latest' } - - { mysql: 'mariadb:10.3', mongo: 'percona/percona-server-mongodb:4.4', postgres: 'postgres:9.5', pmm_server: 'perconalab/pmm-server:3-dev-latest' } - - { mysql: 'mariadb:10.4', postgres: 'postgres:9.6', pmm_server: 'perconalab/pmm-server:3-dev-latest' } + - { mysql: 'mariadb:11.2', mongo: 'mongo:4.4', postgres: 'postgres:10', pmm_server: 'perconalab/pmm-server:3-dev-latest' } + - { mysql: 'mariadb:11.4', mongo: 'percona/percona-server-mongodb:4.4', postgres: 'postgres:11', pmm_server: 'perconalab/pmm-server:3-dev-latest' } + - { mysql: 'mariadb:11.5', postgres: 'postgres:12', pmm_server: 'perconalab/pmm-server:3-dev-latest' } continue-on-error: true @@ -120,3 +123,4 @@ jobs: echo "--- GO Environment ---" go env | sort git status + docker compose logs diff --git a/agent/agents/mongodb/internal/profiler/profiler_test.go b/agent/agents/mongodb/internal/profiler/profiler_test.go index b6e044ee02..891abf4667 100644 --- a/agent/agents/mongodb/internal/profiler/profiler_test.go +++ b/agent/agents/mongodb/internal/profiler/profiler_test.go @@ -69,11 +69,11 @@ func TestProfiler(t *testing.T) { tempDir := t.TempDir() sslDSN, err := templates.RenderDSN(sslDSNTemplate, files, tempDir) require.NoError(t, err) - for _, url := range []string{ - "mongodb://root:root-password@127.0.0.1:27017/admin", - sslDSN, + for name, url := range map[string]string{ + "normal": tests.GetTestMongoDBDSN(t), + "ssl": sslDSN, } { - t.Run(url, func(t *testing.T) { + t.Run(name, func(t *testing.T) { testProfiler(t, url) }) } @@ -221,6 +221,7 @@ func testProfiler(t *testing.T, url string) { Dsn: tests.GetTestMongoDBDSN(t), Query: findBucket.Common.Example, } + client := tests.OpenTestMongoDB(t, params.Dsn) ex, err := actions.NewMongoDBExplainAction(id, 5*time.Second, params, os.TempDir()) require.NoError(t, err) @@ -238,8 +239,34 @@ func testProfiler(t *testing.T, url string) { "$eq": "value_00\ufffd", }, }, - "plannerVersion": map[string]interface{}{"$numberInt": "1"}, - "rejectedPlans": []interface{}{}, + "rejectedPlans": []interface{}{}, + } + mongoDBVersion := tests.MongoDBVersion(t, client) + + switch mongoDBVersion { + case "4.4": + want["plannerVersion"] = map[string]interface{}{"$numberInt": "1"} + case "5.0": + want["maxIndexedAndSolutionsReached"] = false + want["maxIndexedOrSolutionsReached"] = false + want["maxScansToExplodeReached"] = false + case "6.0": + want["maxIndexedAndSolutionsReached"] = false + want["maxIndexedOrSolutionsReached"] = false + want["maxScansToExplodeReached"] = false + case "7.0": + want["maxIndexedAndSolutionsReached"] = false + want["maxIndexedOrSolutionsReached"] = false + want["maxScansToExplodeReached"] = false + } + + switch mongoDBVersion { + case "6.0": + want["planCacheKey"] = "4FA12547" + want["queryHash"] = "4FA12547" + case "7.0": + want["planCacheKey"] = "0F06B42F" + want["queryHash"] = "0F06B42F" } explainM := make(map[string]interface{}) diff --git a/agent/agents/postgres/pgstatstatements/pgstatstatements_test.go b/agent/agents/postgres/pgstatstatements/pgstatstatements_test.go index c666cffec3..3c1c1c8360 100644 --- a/agent/agents/postgres/pgstatstatements/pgstatstatements_test.go +++ b/agent/agents/postgres/pgstatstatements/pgstatstatements_test.go @@ -19,6 +19,7 @@ import ( "fmt" "math/rand" "os" + "strconv" "strings" "sync" "testing" @@ -128,16 +129,6 @@ func TestPGStatStatementsQAN(t *testing.T) { engineVersion := tests.PostgreSQLVersion(t, sqlDB) var digests map[string]string // digest_text/fingerprint to digest/query_id switch engineVersion { - case "9.4": - digests = map[string]string{ - selectAllCities: "3239586867", - selectAllCitiesLong: "2745128652", - } - case "9.5", "9.6": - digests = map[string]string{ - selectAllCities: "3994135135", - selectAllCitiesLong: "2677760328", - } case "10": digests = map[string]string{ selectAllCities: "2229807896", @@ -163,6 +154,16 @@ func TestPGStatStatementsQAN(t *testing.T) { selectAllCities: "5991662752016701281", selectAllCitiesLong: "-3564720362103294944", } + case "15": + digests = map[string]string{ + selectAllCities: "5991662752016701281", + selectAllCitiesLong: "-3564720362103294944", + } + case "16": + digests = map[string]string{ + selectAllCities: "9094455616937907056", + selectAllCitiesLong: "-8264367755446145090", + } default: t.Log("Unhandled version, assuming dummy digests.") digests = map[string]string{ @@ -282,9 +283,16 @@ func TestPGStatStatementsQAN(t *testing.T) { t.Logf("Actual:\n%s", tests.FormatBuckets(buckets)) require.Len(t, buckets, 1) + expectedSharedBlksHitSum := float32(1007) + engineVersionInt, err := strconv.Atoi(engineVersion) + assert.NoError(t, err) + if engineVersionInt >= 14 { + expectedSharedBlksHitSum = 32 + } + actual := buckets[0] assert.InDelta(t, 0, actual.Common.MQueryTimeSum, 0.09) - assert.InDelta(t, 1010, actual.Postgresql.MSharedBlksHitSum+actual.Postgresql.MSharedBlksReadSum, 3) + assert.InDelta(t, expectedSharedBlksHitSum+3, actual.Postgresql.MSharedBlksHitSum+actual.Postgresql.MSharedBlksReadSum, 3) assert.InDelta(t, 1.5, actual.Postgresql.MSharedBlksHitCnt+actual.Postgresql.MSharedBlksReadCnt, 0.5) expected := &agentv1.MetricsBucket{ Common: &agentv1.MetricsBucket_Common{ @@ -329,7 +337,7 @@ func TestPGStatStatementsQAN(t *testing.T) { actual = buckets[0] assert.InDelta(t, 0, actual.Common.MQueryTimeSum, 0.09) assert.InDelta(t, 0, actual.Postgresql.MBlkReadTimeCnt, 1) - assert.InDelta(t, 1007, actual.Postgresql.MSharedBlksHitSum, 2) + assert.InDelta(t, expectedSharedBlksHitSum, actual.Postgresql.MSharedBlksHitSum, 2) expected = &agentv1.MetricsBucket{ Common: &agentv1.MetricsBucket_Common{ Fingerprint: selectAllCitiesLong, @@ -349,7 +357,7 @@ func TestPGStatStatementsQAN(t *testing.T) { Postgresql: &agentv1.MetricsBucket_PostgreSQL{ MBlkReadTimeCnt: actual.Postgresql.MBlkReadTimeCnt, MBlkReadTimeSum: actual.Postgresql.MBlkReadTimeSum, - MSharedBlksHitCnt: 1, + MSharedBlksHitCnt: actual.Postgresql.MSharedBlksHitCnt, MSharedBlksHitSum: actual.Postgresql.MSharedBlksHitSum, MRowsCnt: 1, MRowsSum: 499, @@ -397,24 +405,15 @@ func TestPGStatStatementsQAN(t *testing.T) { t.Logf("Actual:\n%s", tests.FormatBuckets(buckets)) require.Len(t, buckets, 1) - var fingerprint string - tables := []string{tableName} + fingerprint := fmt.Sprintf(`INSERT /* CheckMBlkReadTime controller='test' */ INTO %s (customer_id, first_name, last_name, active) VALUES ($1, $2, $3, $4)`, tableName) - switch engineVersion { - case "9.4", "9.5", "9.6": - fingerprint = fmt.Sprintf(`INSERT /* CheckMBlkReadTime controller='test' */ INTO %s (customer_id, first_name, last_name, active) VALUES (?, ?, ?, ?)`, tableName) - tables = []string{} - default: - fingerprint = fmt.Sprintf(`INSERT /* CheckMBlkReadTime controller='test' */ INTO %s (customer_id, first_name, last_name, active) VALUES ($1, $2, $3, $4)`, tableName) - } actual := buckets[0] - assert.NotZero(t, actual.Postgresql.MBlkReadTimeSum) expected := &agentv1.MetricsBucket{ Common: &agentv1.MetricsBucket_Common{ Queryid: actual.Common.Queryid, Fingerprint: fingerprint, Database: "pmm-agent", - Tables: tables, + Tables: []string{tableName}, Comments: map[string]string{"controller": "test"}, Username: "pmm-agent", AgentId: "agent_id", @@ -426,8 +425,10 @@ func TestPGStatStatementsQAN(t *testing.T) { MQueryTimeSum: actual.Common.MQueryTimeSum, }, Postgresql: &agentv1.MetricsBucket_PostgreSQL{ - MBlkReadTimeCnt: float32(n), + MBlkReadTimeCnt: actual.Postgresql.MBlkReadTimeCnt, MBlkReadTimeSum: actual.Postgresql.MBlkReadTimeSum, + MBlkWriteTimeCnt: actual.Postgresql.MBlkWriteTimeCnt, + MBlkWriteTimeSum: actual.Postgresql.MBlkWriteTimeSum, MSharedBlksReadCnt: actual.Postgresql.MSharedBlksReadCnt, MSharedBlksReadSum: actual.Postgresql.MSharedBlksReadSum, MSharedBlksWrittenCnt: actual.Postgresql.MSharedBlksWrittenCnt, @@ -440,6 +441,7 @@ func TestPGStatStatementsQAN(t *testing.T) { MRowsSum: float32(n), }, } + assert.InDelta(t, n, actual.Postgresql.MBlkWriteTimeCnt+actual.Postgresql.MBlkReadTimeCnt, 1) tests.AssertBucketsEqual(t, expected, actual) assert.LessOrEqual(t, actual.Postgresql.MBlkReadTimeSum, actual.Common.MQueryTimeSum) }) diff --git a/agent/docker-compose.yml b/agent/docker-compose.yml index a8f7aecb78..43934865dd 100644 --- a/agent/docker-compose.yml +++ b/agent/docker-compose.yml @@ -48,7 +48,7 @@ services: - ./testdata/mysql:/mysql mongo: - image: ${MONGO_IMAGE:-percona/percona-server-mongodb:4.2} + image: ${MONGO_IMAGE:-percona/percona-server-mongodb:5.0} container_name: pmm-agent_mongo command: --profile 2 ports: @@ -58,7 +58,7 @@ services: - MONGO_INITDB_ROOT_PASSWORD=root-password mongo_with_ssl: - image: ${MONGO_IMAGE:-percona/percona-server-mongodb:4.2} + image: ${MONGO_IMAGE:-percona/percona-server-mongodb:5.0} container_name: pmm-agent_mongo_with_ssl command: - --profile=2 @@ -66,49 +66,41 @@ services: - --sslPEMKeyFile=/etc/ssl/certificates/server.pem - --sslCAFile=/etc/ssl/certificates/ca.crt - --sslWeakCertificateValidation - - --bind_ip=0.0.0.0 ports: - "127.0.0.1:27018:27017" volumes: - ${PWD}/utils/tests/testdata/mongodb:/etc/ssl/certificates mongonoauth: - image: ${MONGO_IMAGE:-percona/percona-server-mongodb:4.2} + image: ${MONGO_IMAGE:-percona/percona-server-mongodb:5.0} container_name: pmm-agent_mongonoauth command: --profile 2 ports: - "127.0.0.1:27019:27017" mongo_repl: - image: ${MONGO_IMAGE:-percona/percona-server-mongodb:4.2} + image: ${MONGO_IMAGE:-percona/percona-server-mongodb:5.0} container_name: pmm-agent_mongorepl - command: > - bash -c " - mkdir /tmp/mongodb1 /tmp/mongodb2 - mongod --fork --logpath=/dev/null --profile=2 --replSet=rs0 --noauth --bind_ip=0.0.0.0 --dbpath=/tmp/mongodb1 --port=27020 - mongod --fork --logpath=/dev/null --profile=2 --replSet=rs0 --noauth --bind_ip=0.0.0.0 --dbpath=/tmp/mongodb2 --port=27021 - mongo --port 27020 --eval \"rs.initiate( { _id : 'rs0', members: [{ _id: 0, host: 'localhost:27020' }, { _id: 1, host: 'localhost:27021', priority: 0 }]})\" - tail -f /dev/null - " + environment: + - MONGO_IMAGE=${MONGO_IMAGE:-percona/percona-server-mongodb:5.0} + volumes: + - ./testscripts/:/scripts + command: /scripts/mongo_repl.sh ports: - "127.0.0.1:27020:27020" - "127.0.0.1:27021:27021" mongo_repl_with_ssl: - image: ${MONGO_IMAGE:-percona/percona-server-mongodb:4.2} + image: ${MONGO_IMAGE:-percona/percona-server-mongodb:5.0} container_name: pmm-agent_mongorepl_with_ssl - command: > - bash -c " - mkdir /tmp/mongodb1 /tmp/mongodb2 - mongod --fork --logpath=/dev/null --profile=2 --replSet=rs0 --sslMode=requireSSL --sslPEMKeyFile=/etc/ssl/certificates/server.pem --sslCAFile=/etc/ssl/certificates/ca.crt --sslClusterFile=/etc/ssl/certificates/client.pem --bind_ip=0.0.0.0 --dbpath=/tmp/mongodb1 --port=27022 - mongod --fork --logpath=/dev/null --profile=2 --replSet=rs0 --sslMode=requireSSL --sslPEMKeyFile=/etc/ssl/certificates/server.pem --sslCAFile=/etc/ssl/certificates/ca.crt --sslClusterFile=/etc/ssl/certificates/client.pem --bind_ip=0.0.0.0 --dbpath=/tmp/mongodb2 --port=27023 - mongo --port 27022 --ssl --sslCAFile=/etc/ssl/certificates/ca.crt --sslPEMKeyFile=/etc/ssl/certificates/client.pem --sslAllowInvalidHostnames --eval \"rs.initiate( { _id : 'rs0', members: [{ _id: 0, host: 'localhost:27022' }, { _id: 1, host: 'localhost:27023', priority: 0 }]})\" - tail -f /dev/null - " + command: /scripts/mongo_repl_with_ssl.sh + environment: + - MONGO_IMAGE=${MONGO_IMAGE:-percona/percona-server-mongodb:5.0} ports: - "127.0.0.1:27022:27022" - "127.0.0.1:27023:27023" volumes: + - ./testscripts/:/scripts - ${PWD}/utils/tests/testdata/mongodb:/etc/ssl/certificates postgres: diff --git a/agent/packages.dot b/agent/packages.dot index bb9f70bf21..74d45da9a1 100644 --- a/agent/packages.dot +++ b/agent/packages.dot @@ -40,11 +40,9 @@ digraph packages { "/agents/supervisor" -> "/config"; "/agents/supervisor" -> "/tailog"; "/agents/supervisor.test" -> "/agents/supervisor"; - "/client" -> "/client/cache"; "/client" -> "/client/channel"; "/client" -> "/config"; "/client" -> "/connectionuptime"; - "/client" -> "/models"; "/client" -> "/runner"; "/client" -> "/runner/actions"; "/client" -> "/runner/jobs"; diff --git a/agent/runner/actions/mongodb_explain_action_test.go b/agent/runner/actions/mongodb_explain_action_test.go index f8218d9a8d..4e78e4df0f 100644 --- a/agent/runner/actions/mongodb_explain_action_test.go +++ b/agent/runner/actions/mongodb_explain_action_test.go @@ -282,9 +282,28 @@ func TestMongoDBExplain(t *testing.T) { "parsedQuery": map[string]interface{}{ "k": map[string]interface{}{"$lte": map[string]interface{}{"$numberInt": "1"}}, }, - "plannerVersion": map[string]interface{}{"$numberInt": "1"}, - "rejectedPlans": []interface{}{}, - "winningPlan": map[string]interface{}{"stage": "EOF"}, + "rejectedPlans": []interface{}{}, + "winningPlan": map[string]interface{}{"stage": "EOF"}, + } + mongoDBVersion := tests.MongoDBVersion(t, client) + fmt.Printf("MongoDB version: %s\n", mongoDBVersion) + + switch mongoDBVersion { + case "4.4", "4.2": + want["plannerVersion"] = map[string]interface{}{"$numberInt": "1"} + case "5.0", "6.0", "7.0": + want["maxIndexedAndSolutionsReached"] = false + want["maxIndexedOrSolutionsReached"] = false + want["maxScansToExplodeReached"] = false + } + + switch mongoDBVersion { + case "6.0": + want["planCacheKey"] = "88A125C6" + want["queryHash"] = "88A125C6" + case "7.0": + want["planCacheKey"] = "0F06B42F" + want["queryHash"] = "0F06B42F" } explainM := make(map[string]interface{}) @@ -321,8 +340,7 @@ func TestNewMongoDBExplain(t *testing.T) { in: "distinct.json", }, { - in: "aggregate.json", - minVersion: "3.4.0", + in: "aggregate.json", }, { in: "count.json", @@ -331,17 +349,7 @@ func TestNewMongoDBExplain(t *testing.T) { in: "find_and_modify.json", }, } - mongoDBVersion := tests.MongoDBVersion(t, client) for _, tf := range testFiles { - // Not all MongoDB versions allow explaining all commands - if tf.minVersion != "" { - c, err := lessThan(tf.minVersion, mongoDBVersion) - require.NoError(t, err) - if c { - continue - } - } - t.Run(tf.in, func(t *testing.T) { query, err := os.ReadFile(filepath.Join("testdata/", filepath.Clean(tf.in))) assert.NoError(t, err) diff --git a/agent/runner/actions/mongodb_query_admincommand_action_test.go b/agent/runner/actions/mongodb_query_admincommand_action_test.go index 08c6a1eacd..38d9afd4f6 100644 --- a/agent/runner/actions/mongodb_query_admincommand_action_test.go +++ b/agent/runner/actions/mongodb_query_admincommand_action_test.go @@ -196,7 +196,6 @@ func convertToObjxMap(t *testing.T, b []byte) objx.Map { func getParameterAssertions(t *testing.T, b []byte) { //nolint:thelper assert.LessOrEqual(t, 5000, len(b)) - assert.LessOrEqual(t, len(b), 17000) objxM := convertToObjxMap(t, b) assert.Equal(t, 1.0, objxM.Get("ok").Data()) assert.Contains(t, objxM.Get("authenticationMechanisms").Data(), "SCRAM-SHA-1") @@ -204,7 +203,6 @@ func getParameterAssertions(t *testing.T, b []byte) { //nolint:thelper func buildInfoAssertions(t *testing.T, b []byte) { //nolint:thelper assert.LessOrEqual(t, 1000, len(b)) - assert.LessOrEqual(t, len(b), 2200) objxM := convertToObjxMap(t, b) assert.Equal(t, 1.0, objxM.Get("ok").Data()) assert.Equal(t, "mozjs", objxM.Get("javascriptEngine").Data()) @@ -213,7 +211,6 @@ func buildInfoAssertions(t *testing.T, b []byte) { //nolint:thelper func getDiagnosticDataAssertions(t *testing.T, b []byte) { //nolint:thelper assert.LessOrEqual(t, 25000, len(b)) - assert.LessOrEqual(t, len(b), 110000) objxM := convertToObjxMap(t, b) assert.Equal(t, 1.0, objxM.Get("ok").Data()) assert.Equal(t, 1.0, objxM.Get("data.serverStatus.ok").Data()) @@ -222,7 +219,6 @@ func getDiagnosticDataAssertions(t *testing.T, b []byte) { //nolint:thelper func replSetGetStatusAssertionsReplicated(t *testing.T, b []byte) { //nolint:thelper assert.LessOrEqual(t, 1000, len(b)) - assert.LessOrEqual(t, len(b), 4000) objxM := convertToObjxMap(t, b) assert.Equal(t, 1.0, objxM.Get("ok").Data()) assert.Len(t, objxM.Get("members").Data(), 2) diff --git a/agent/runner/actions/postgresql_query_show_action_test.go b/agent/runner/actions/postgresql_query_show_action_test.go index 037c32a1bf..1b5ce7ba24 100644 --- a/agent/runner/actions/postgresql_query_show_action_test.go +++ b/agent/runner/actions/postgresql_query_show_action_test.go @@ -48,14 +48,12 @@ func TestPostgreSQLQueryShow(t *testing.T) { b, err := a.Run(ctx) require.NoError(t, err) - assert.LessOrEqual(t, 22000, len(b)) - assert.LessOrEqual(t, len(b), 33668) + assert.GreaterOrEqual(t, len(b), 22000) data, err := agentv1.UnmarshalActionQueryResult(b) require.NoError(t, err) t.Log(spew.Sdump(data)) - assert.LessOrEqual(t, 200, len(data)) - assert.LessOrEqual(t, len(data), 358) + assert.GreaterOrEqual(t, len(data), 200) var found int for _, m := range data { diff --git a/agent/testscripts/mongo_repl.sh b/agent/testscripts/mongo_repl.sh new file mode 100755 index 0000000000..24f441640e --- /dev/null +++ b/agent/testscripts/mongo_repl.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +MONGODB_CLIENT="mongosh" +PARSED=(${MONGO_IMAGE//:/ }) +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 + +mkdir /tmp/mongodb1 /tmp/mongodb2 +mongod --fork --logpath=/dev/null --profile=2 --replSet=rs0 --noauth --bind_ip=0.0.0.0 --dbpath=/tmp/mongodb1 --port=27020 +mongod --fork --logpath=/dev/null --profile=2 --replSet=rs0 --noauth --bind_ip=0.0.0.0 --dbpath=/tmp/mongodb2 --port=27021 +$MONGODB_CLIENT --port 27020 --eval "rs.initiate( { _id : 'rs0', members: [{ _id: 0, host: 'localhost:27020' }, { _id: 1, host: 'localhost:27021', priority: 0 }]})" +tail -f /dev/null \ No newline at end of file diff --git a/agent/testscripts/mongo_repl_with_ssl.sh b/agent/testscripts/mongo_repl_with_ssl.sh new file mode 100755 index 0000000000..21e47075f0 --- /dev/null +++ b/agent/testscripts/mongo_repl_with_ssl.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +MONGODB_CLIENT="mongosh" +PARSED=(${MONGO_IMAGE//:/ }) +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 + +mkdir /tmp/mongodb1 /tmp/mongodb2 +mongod --fork --logpath=/dev/null --profile=2 --replSet=rs0 --sslMode=requireSSL --sslPEMKeyFile=/etc/ssl/certificates/server.pem --sslCAFile=/etc/ssl/certificates/ca.crt --sslClusterFile=/etc/ssl/certificates/client.pem --bind_ip=0.0.0.0 --dbpath=/tmp/mongodb1 --port=27022 +mongod --fork --logpath=/dev/null --profile=2 --replSet=rs0 --sslMode=requireSSL --sslPEMKeyFile=/etc/ssl/certificates/server.pem --sslCAFile=/etc/ssl/certificates/ca.crt --sslClusterFile=/etc/ssl/certificates/client.pem --bind_ip=0.0.0.0 --dbpath=/tmp/mongodb2 --port=27023 +$MONGODB_CLIENT --port 27022 --ssl --sslCAFile=/etc/ssl/certificates/ca.crt --sslPEMKeyFile=/etc/ssl/certificates/client.pem --sslAllowInvalidHostnames --eval "rs.initiate( { _id : 'rs0', members: [{ _id: 0, host: 'localhost:27022' }, { _id: 1, host: 'localhost:27023', priority: 0 }]})" +tail -f /dev/null \ No newline at end of file diff --git a/agent/utils/tests/mongodb.go b/agent/utils/tests/mongodb.go index 537fc20411..7c7d9741c4 100644 --- a/agent/utils/tests/mongodb.go +++ b/agent/utils/tests/mongodb.go @@ -16,6 +16,8 @@ package tests import ( "context" + "fmt" + "github.com/percona/pmm/version" "os" "path/filepath" "testing" @@ -131,5 +133,9 @@ func MongoDBVersion(tb testing.TB, client *mongo.Client) string { if err := res.Decode(&bi); err != nil { tb.Fatalf("Cannot decode buildInfo response: %s", err) } - return bi.Version + parsed, err := version.Parse(bi.Version) + if err != nil { + tb.Fatalf("Cannot parse version: %s", err) + } + return fmt.Sprintf("%d.%d", parsed.Major, parsed.Minor) }