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

PMM-7 Update pg_query_go #2965

Open
wants to merge 21 commits into
base: v3
Choose a base branch
from
Open
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
24 changes: 14 additions & 10 deletions .github/workflows/agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -120,3 +123,4 @@ jobs:
echo "--- GO Environment ---"
go env | sort
git status
docker compose logs
39 changes: 33 additions & 6 deletions agent/agents/mongodb/internal/profiler/profiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]: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)
})
}
Expand Down Expand Up @@ -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)
Expand All @@ -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{})
Expand Down
52 changes: 27 additions & 25 deletions agent/agents/postgres/pgstatstatements/pgstatstatements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"math/rand"
"os"
"strconv"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -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",
Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand All @@ -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)
})
Expand Down
36 changes: 14 additions & 22 deletions agent/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -58,57 +58,49 @@ 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
- --sslMode=requireSSL
- --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:
Expand Down
2 changes: 0 additions & 2 deletions agent/packages.dot
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
38 changes: 23 additions & 15 deletions agent/runner/actions/mongodb_explain_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
use of fmt.Printf forbidden by pattern ^(fmt\.Print(|f|ln)|print|println)$ (forbidigo)


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{})
Expand Down Expand Up @@ -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",
Expand All @@ -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)
Expand Down
Loading
Loading