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-12468 Plan summary, COLLSCAN. #920

Draft
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions src/go/mongolib/proto/system.profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type SystemProfile struct {
Ns string `bson:"ns"`
NumYield int `bson:"numYield"`
Op string `bson:"op"`
PlanSummary string `bson:"planSummary"`
Protocol string `bson:"protocol"`
Query bson.D `bson:"query"`
UpdateObj bson.D `bson:"updateobj"`
Expand Down
26 changes: 26 additions & 0 deletions src/go/mongolib/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/md5"
"fmt"
"sort"
"strings"
"sync"
"time"

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

const (
planSummaryCollScan = "COLLSCAN"
planSummaryIXScan = "IXSCAN"
)

type StatsError struct {
error
}
Expand Down Expand Up @@ -86,13 +92,22 @@ func (s *Stats) Add(doc proto.SystemProfile) error {
Namespace: fp.Namespace,
TableScan: false,
Query: string(queryBson),
PlanSummary: doc.PlanSummary,
}
s.setQueryInfoAndCounters(key, qiac)
}
qiac.Count++
// docsExamined is renamed from nscannedObjects in 3.2.0.
// https://docs.mongodb.com/manual/reference/database-profiler/#system.profile.docsExamined
s.Lock()
qiac.PlanSummary = doc.PlanSummary
if qiac.PlanSummary == planSummaryCollScan {
qiac.CollScanCount++
qiac.CollScanSum += int64(doc.Millis)
}
if strings.HasPrefix(qiac.PlanSummary, planSummaryIXScan) {
qiac.PlanSummary = planSummaryIXScan
}
if doc.NscannedObjects > 0 {
qiac.NScanned = append(qiac.NScanned, float64(doc.NscannedObjects))
} else {
Expand Down Expand Up @@ -188,6 +203,10 @@ type QueryInfoAndCounters struct {
NScanned []float64
QueryTime []float64 // in milliseconds
ResponseLength []float64

PlanSummary string
CollScanCount int
CollScanSum int64 // in milliseconds
}

// times is an array of time.Time that implements the Sorter interface
Expand Down Expand Up @@ -238,6 +257,10 @@ type QueryStats struct {
ResponseLength Statistics
Returned Statistics
Scanned Statistics

PlanSummary string
CollScanCount int
CollScanSum int64 // in milliseconds
}

type Statistics struct {
Expand Down Expand Up @@ -267,6 +290,9 @@ func countersToStats(query QueryInfoAndCounters, uptime int64, tc totalCounters)
LastSeen: query.LastSeen,
Namespace: query.Namespace,
QPS: float64(query.Count) / float64(uptime),
PlanSummary: query.PlanSummary,
CollScanCount: query.CollScanCount,
CollScanSum: query.CollScanSum,
}
if tc.Scanned > 0 {
queryStats.Scanned.Pct = queryStats.Scanned.Total * 100 / tc.Scanned
Expand Down
Loading