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 15 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
22 changes: 12 additions & 10 deletions .github/workflows/agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ 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.2', 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:4.4', 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:4.4', postgres: 'perconalab/percona-distribution-postgresql:16', 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 +48,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
22 changes: 20 additions & 2 deletions agent/agents/mongodb/internal/profiler/profiler_test.go
Original file line number Diff line number Diff line change
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,25 @@ 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
}

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
28 changes: 25 additions & 3 deletions agent/runner/actions/mongodb_explain_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,31 @@
"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)

Check failure on line 289 in agent/runner/actions/mongodb_explain_action_test.go

View workflow job for this annotation

GitHub Actions / Checks

use of `fmt.Printf` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)

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":
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
want["planCacheKey"] = "88A125C6"
want["queryHash"] = "88A125C6"
case "7.0":
want["maxIndexedAndSolutionsReached"] = false
want["maxIndexedOrSolutionsReached"] = false
want["maxScansToExplodeReached"] = false
want["planCacheKey"] = "0F06B42F"
want["queryHash"] = "0F06B42F"
}

explainM := make(map[string]interface{})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 2 additions & 4 deletions agent/runner/actions/postgresql_query_show_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading