Merge branch '3.0' into PMM-1.3

This commit is contained in:
Kamil Dziedzic
2017-10-10 12:06:09 +02:00
27 changed files with 1056 additions and 378 deletions
+4 -2
View File
@@ -86,6 +86,7 @@ func TestRegularIterator(t *testing.T) {
},
}
prof.Start()
defer prof.Stop()
select {
case queries := <-prof.QueriesChan():
if !reflect.DeepEqual(queries, want) {
@@ -144,6 +145,7 @@ func TestIteratorTimeout(t *testing.T) {
}
prof.Start()
defer prof.Stop()
gotTimeout := false
// Get a timeout
@@ -168,8 +170,6 @@ func TestIteratorTimeout(t *testing.T) {
case <-time.After(2 * time.Second):
t.Error("Didn't get any query after 2 seconds")
}
prof.Stop()
}
func TestTailIterator(t *testing.T) {
@@ -239,6 +239,7 @@ func TestTailIterator(t *testing.T) {
},
}
prof.Start()
defer prof.Stop()
index := 0
// Since the mocked iterator has a Sleep(1500 ms) between Next methods calls,
// we are going to have two ticker ticks and on every tick it will return one document.
@@ -339,6 +340,7 @@ func TestCalcTotalStats(t *testing.T) {
prof := NewProfiler(iter, filters, nil, s)
prof.Start()
defer prof.Stop()
select {
case queries := <-prof.QueriesChan():
s := queries.CalcTotalQueriesStats(1)
+2
View File
@@ -7,11 +7,13 @@ import (
"gopkg.in/mgo.v2/bson"
)
// docsExamined is renamed from nscannedObjects in 3.2.0
type SystemProfile struct {
AllUsers []interface{} `bson:"allUsers"`
Client string `bson:"client"`
CursorExhausted bool `bson:"cursorExhausted"`
DocsExamined int `bson:"docsExamined"`
NscannedObjects int `bson:"nscannedObjects"`
ExecStats struct {
Advanced int `bson:"advanced"`
ExecutionTimeMillisEstimate int `bson:"executionTimeMillisEstimate"`
+8 -2
View File
@@ -90,7 +90,12 @@ func (s *Stats) Add(doc proto.SystemProfile) error {
s.setQueryInfoAndCounters(key, qiac)
}
qiac.Count++
qiac.NScanned = append(qiac.NScanned, float64(doc.DocsExamined))
// docsExamined is renamed from nscannedObjects in 3.2.0.
if doc.NscannedObjects > 0 {
qiac.NScanned = append(qiac.NScanned, float64(doc.NscannedObjects))
} else {
qiac.NScanned = append(qiac.NScanned, float64(doc.DocsExamined))
}
qiac.NReturned = append(qiac.NReturned, float64(doc.Nreturned))
qiac.QueryTime = append(qiac.QueryTime, float64(doc.Millis))
qiac.ResponseLength = append(qiac.ResponseLength, float64(doc.ResponseLength))
@@ -269,7 +274,7 @@ func countersToStats(query QueryInfoAndCounters, uptime int64, tc totalCounters)
queryStats.QueryTime.Pct = queryStats.QueryTime.Total * 100 / tc.QueryTime
}
if tc.Bytes > 0 {
queryStats.ResponseLength.Pct = queryStats.ResponseLength.Total / tc.Bytes
queryStats.ResponseLength.Pct = queryStats.ResponseLength.Total * 100 / tc.Bytes
}
if queryStats.Returned.Total > 0 {
queryStats.Ratio = queryStats.Scanned.Total / queryStats.Returned.Total
@@ -281,6 +286,7 @@ func countersToStats(query QueryInfoAndCounters, uptime int64, tc totalCounters)
func aggregateCounters(queries []QueryInfoAndCounters) QueryInfoAndCounters {
qt := QueryInfoAndCounters{}
for _, query := range queries {
qt.Count += query.Count
qt.NScanned = append(qt.NScanned, query.NScanned...)
qt.NReturned = append(qt.NReturned, query.NReturned...)
qt.QueryTime = append(qt.QueryTime, query.QueryTime...)
+4 -7
View File
@@ -165,7 +165,8 @@ func main() {
if opts.Limit > 0 && len(sortedQueryStats) > opts.Limit {
sortedQueryStats = sortedQueryStats[:opts.Limit]
}
for _, qs := range sortedQueryStats {
for i, qs := range sortedQueryStats {
qs.Rank = i + 1
t.Execute(os.Stdout, qs)
}
@@ -426,15 +427,11 @@ func sortQueries(queries []stats.QueryStats, orderby []string) []stats.QueryStat
case "ratio":
f = func(c1, c2 *stats.QueryStats) bool {
ratio1 := c1.Scanned.Max / c1.Returned.Max
ratio2 := c2.Scanned.Max / c2.Returned.Max
return ratio1 < ratio2
return c1.Ratio < c2.Ratio
}
case "-ratio":
f = func(c1, c2 *stats.QueryStats) bool {
ratio1 := c1.Scanned.Max / c1.Returned.Max
ratio2 := c2.Scanned.Max / c2.Returned.Max
return ratio1 > ratio2
return c1.Ratio > c2.Ratio
}
//
+3 -3
View File
@@ -22,7 +22,7 @@
"Median": 0
},
"ResponseLength": {
"Pct": 0.9995949739087844,
"Pct": 99.95949739087844,
"Total": 1061230,
"Min": 1061230,
"Max": 1061230,
@@ -75,7 +75,7 @@
"Median": 7
},
"ResponseLength": {
"Pct": 0.00020251304560782172,
"Pct": 0.020251304560782172,
"Total": 215,
"Min": 215,
"Max": 215,
@@ -128,7 +128,7 @@
"Median": 0
},
"ResponseLength": {
"Pct": 0.00020251304560782172,
"Pct": 0.020251304560782172,
"Total": 215,
"Min": 215,
"Max": 215,
@@ -6,8 +6,8 @@
"Fingerprint": "",
"FirstSeen": "0001-01-01T00:00:00Z",
"LastSeen": "0001-01-01T00:00:00Z",
"Count": 0,
"QPS": 0,
"Count": 3,
"QPS": 3,
"Rank": 0,
"Ratio": 134.33333333333334,
"QueryTime": {
@@ -21,7 +21,7 @@
"Median": 0
},
"ResponseLength": {
"Pct": 1,
"Pct": 100,
"Total": 1061660,
"Min": 215,
"Max": 1061230,