Skip to content

Commit 75cddb4

Browse files
Merge pull request #920 from percona/PMM-12468-plan-summary-and-coll-scan
PMM-12468 Plan summary, COLLSCAN.
2 parents d82723f + 5972093 commit 75cddb4

File tree

6 files changed

+43
-10
lines changed

6 files changed

+43
-10
lines changed

src/go/mongolib/fingerprinter/fingerprinter_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import (
1010
"strings"
1111
"testing"
1212

13-
"github.com/percona/percona-toolkit/src/go/lib/tutil"
14-
"github.com/percona/percona-toolkit/src/go/mongolib/proto"
1513
"github.com/stretchr/testify/assert"
1614
"github.com/stretchr/testify/require"
1715
"go.mongodb.org/mongo-driver/bson"
16+
17+
"github.com/percona/percona-toolkit/src/go/lib/tutil"
18+
"github.com/percona/percona-toolkit/src/go/mongolib/proto"
1819
)
1920

2021
const (
@@ -33,7 +34,8 @@ func TestMain(m *testing.M) {
3334
log.Printf("cannot get root path: %s", err.Error())
3435
os.Exit(1)
3536
}
36-
os.Exit(m.Run())
37+
code := m.Run()
38+
os.Exit(code)
3739
}
3840

3941
func TestSingleFingerprint(t *testing.T) {

src/go/mongolib/profiler/profiler_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import (
77
"testing"
88
"time"
99

10+
"github.com/stretchr/testify/assert"
11+
"github.com/stretchr/testify/require"
12+
"go.mongodb.org/mongo-driver/bson/primitive"
13+
1014
tu "github.com/percona/percona-toolkit/src/go/internal/testutils"
1115
"github.com/percona/percona-toolkit/src/go/lib/tutil"
1216
"github.com/percona/percona-toolkit/src/go/mongolib/fingerprinter"
1317
"github.com/percona/percona-toolkit/src/go/mongolib/stats"
1418
"github.com/percona/percona-toolkit/src/go/pt-mongodb-query-digest/filter"
15-
"github.com/stretchr/testify/assert"
16-
"github.com/stretchr/testify/require"
17-
"go.mongodb.org/mongo-driver/bson/primitive"
1819
)
1920

2021
const (
@@ -38,7 +39,8 @@ func TestMain(m *testing.M) {
3839
log.Printf("cannot get root path: %s", err.Error())
3940
os.Exit(1)
4041
}
41-
os.Exit(m.Run())
42+
code := m.Run()
43+
os.Exit(code)
4244
}
4345

4446
func TestRegularIterator(t *testing.T) {

src/go/mongolib/proto/system.profile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ type SystemProfile struct {
7878
Ns string `bson:"ns"`
7979
NumYield int `bson:"numYield"`
8080
Op string `bson:"op"`
81+
PlanSummary string `bson:"planSummary"`
8182
Protocol string `bson:"protocol"`
8283
Query bson.D `bson:"query"`
8384
UpdateObj bson.D `bson:"updateobj"`

src/go/mongolib/stats/stats.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"crypto/md5"
55
"fmt"
66
"sort"
7+
"strings"
78
"sync"
89
"time"
910

@@ -13,6 +14,11 @@ import (
1314
"github.com/percona/percona-toolkit/src/go/mongolib/proto"
1415
)
1516

17+
const (
18+
planSummaryCollScan = "COLLSCAN"
19+
planSummaryIXScan = "IXSCAN"
20+
)
21+
1622
type StatsError struct {
1723
error
1824
}
@@ -86,13 +92,22 @@ func (s *Stats) Add(doc proto.SystemProfile) error {
8692
Namespace: fp.Namespace,
8793
TableScan: false,
8894
Query: string(queryBson),
95+
PlanSummary: doc.PlanSummary,
8996
}
9097
s.setQueryInfoAndCounters(key, qiac)
9198
}
9299
qiac.Count++
93100
// docsExamined is renamed from nscannedObjects in 3.2.0.
94101
// https://docs.mongodb.com/manual/reference/database-profiler/#system.profile.docsExamined
95102
s.Lock()
103+
qiac.PlanSummary = doc.PlanSummary
104+
if qiac.PlanSummary == planSummaryCollScan {
105+
qiac.CollScanCount++
106+
qiac.CollScanSum += int64(doc.Millis)
107+
}
108+
if strings.HasPrefix(qiac.PlanSummary, planSummaryIXScan) {
109+
qiac.PlanSummary = planSummaryIXScan
110+
}
96111
if doc.NscannedObjects > 0 {
97112
qiac.NScanned = append(qiac.NScanned, float64(doc.NscannedObjects))
98113
} else {
@@ -188,6 +203,10 @@ type QueryInfoAndCounters struct {
188203
NScanned []float64
189204
QueryTime []float64 // in milliseconds
190205
ResponseLength []float64
206+
207+
PlanSummary string
208+
CollScanCount int
209+
CollScanSum int64 // in milliseconds
191210
}
192211

193212
// times is an array of time.Time that implements the Sorter interface
@@ -238,6 +257,10 @@ type QueryStats struct {
238257
ResponseLength Statistics
239258
Returned Statistics
240259
Scanned Statistics
260+
261+
PlanSummary string
262+
CollScanCount int
263+
CollScanSum int64 // in milliseconds
241264
}
242265

243266
type Statistics struct {
@@ -267,6 +290,9 @@ func countersToStats(query QueryInfoAndCounters, uptime int64, tc totalCounters)
267290
LastSeen: query.LastSeen,
268291
Namespace: query.Namespace,
269292
QPS: float64(query.Count) / float64(uptime),
293+
PlanSummary: query.PlanSummary,
294+
CollScanCount: query.CollScanCount,
295+
CollScanSum: query.CollScanSum,
270296
}
271297
if tc.Scanned > 0 {
272298
queryStats.Scanned.Pct = queryStats.Scanned.Total * 100 / tc.Scanned

src/go/mongolib/stats/stats_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"time"
1515

1616
"github.com/golang/mock/gomock"
17+
1718
"github.com/percona/percona-toolkit/src/go/lib/tutil"
1819
"github.com/percona/percona-toolkit/src/go/mongolib/fingerprinter"
1920
"github.com/percona/percona-toolkit/src/go/mongolib/proto"
@@ -40,8 +41,8 @@ func TestMain(m *testing.M) {
4041
log.Printf("cannot get root path: %s", err.Error())
4142
os.Exit(1)
4243
}
43-
// TODO: Review with the new sandbox
44-
// os.Exit(m.Run())
44+
code := m.Run()
45+
os.Exit(code)
4546
}
4647

4748
func TestTimesLen(t *testing.T) {

src/go/pt-pg-summary/main_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ var logger = logrus.New()
3232

3333
func TestMain(m *testing.M) {
3434
logger.SetLevel(logrus.WarnLevel)
35-
os.Exit(m.Run())
35+
code := m.Run()
36+
os.Exit(code)
3637
}
3738

3839
func TestConnection(t *testing.T) {

0 commit comments

Comments
 (0)