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-9288 Extended profiler. #3662

Merged
merged 42 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
dc20c1d
PMM-9288 Extended system profile capture.
JiriCtvrtka Feb 18, 2025
1347a3b
Merge branch 'v3' into PMM-9288-extended-profiler
JiriCtvrtka Feb 18, 2025
e8dd2bd
PMM-9288 Tidy.
JiriCtvrtka Feb 18, 2025
39b5c20
Merge remote-tracking branch 'origin/PMM-9288-extended-profiler' into…
JiriCtvrtka Feb 18, 2025
dfdf7de
PMM-9288 Another fields/metrics.
JiriCtvrtka Feb 18, 2025
5022989
PMM-9288 Changes.
JiriCtvrtka Feb 19, 2025
aba0e85
PMM-9288 New fields in clickhouse.
JiriCtvrtka Feb 19, 2025
d36174f
PMM-9288 Refactor.
JiriCtvrtka Feb 19, 2025
a272fe4
PMM-9288 Changes.
JiriCtvrtka Feb 19, 2025
7925382
PMM-9288 Changes.
JiriCtvrtka Feb 19, 2025
c9c6785
PMM-9288 Better debug.
JiriCtvrtka Feb 19, 2025
2b24c9f
PMM-9288 Profiler test adjust.
JiriCtvrtka Feb 19, 2025
672738e
PMM-9288 Changes.
JiriCtvrtka Feb 19, 2025
6a8bec3
PMM-9288 Profiler test.
JiriCtvrtka Feb 19, 2025
f6dbd44
PMM-9288 Changes.
JiriCtvrtka Feb 20, 2025
5e59c08
PMM-9288 Mod tidy.
JiriCtvrtka Feb 20, 2025
1d32d73
PMM-9288 Small refactor in naming.
JiriCtvrtka Feb 20, 2025
752be78
Merge branch 'mainv3' into PMM-9288-extended-profiler
JiriCtvrtka Feb 20, 2025
fa28b21
PMM-9288 Format, lint.
JiriCtvrtka Feb 20, 2025
b9f7c20
PMM-9288 Changes after discussion.
JiriCtvrtka Feb 20, 2025
4fb81ad
PMM-9288 Format.
JiriCtvrtka Feb 20, 2025
0c8e198
Merge branch 'v3' into PMM-9288-extended-profiler
JiriCtvrtka Feb 20, 2025
62151ea
PMM-9288 Mention of new PMM ticket.
JiriCtvrtka Feb 20, 2025
efb51f4
Merge remote-tracking branch 'origin/PMM-9288-extended-profiler' into…
JiriCtvrtka Feb 20, 2025
ac40bc2
PMM-9288 Related tickets.
JiriCtvrtka Feb 20, 2025
569418d
Merge branch 'v3' into PMM-9288-extended-profiler
JiriCtvrtka Feb 20, 2025
06e3595
Merge branch 'v3' into PMM-9288-extended-profiler
JiriCtvrtka Feb 21, 2025
7043877
PMM-9288 Changes for FE. Mod.
JiriCtvrtka Feb 21, 2025
d500aa2
Merge branch 'v3' into PMM-9288-extended-profiler
JiriCtvrtka Feb 24, 2025
efa14ab
Merge branch 'v3' into PMM-9288-extended-profiler
JiriCtvrtka Feb 25, 2025
f32d830
Merge branch 'v3' into PMM-9288-extended-profiler
JiriCtvrtka Feb 26, 2025
af5ec05
Merge branch 'v3' into PMM-9288-extended-profiler
JiriCtvrtka Feb 26, 2025
0f6dcbf
Merge branch 'v3' into PMM-9288-extended-profiler
JiriCtvrtka Feb 26, 2025
71322b0
Merge branch 'v3' into PMM-9288-extended-profiler
JiriCtvrtka Feb 26, 2025
34d6b00
Merge branch 'v3' into PMM-9288-extended-profiler
JiriCtvrtka Feb 27, 2025
1bab9c5
Merge branch 'v3' into PMM-9288-extended-profiler
JiriCtvrtka Mar 4, 2025
81c6275
Merge branch 'v3' into PMM-9288-extended-profiler
JiriCtvrtka Mar 6, 2025
96b0508
Merge branch 'v3' into PMM-9288-extended-profiler
JiriCtvrtka Mar 6, 2025
a7e8379
PMM-9288 Percona Toolkit merged commit hash.
JiriCtvrtka Mar 7, 2025
2618531
Merge branch 'v3' into PMM-9288-extended-profiler
JiriCtvrtka Mar 7, 2025
27db2cf
PMM-9288 Tidy.
JiriCtvrtka Mar 7, 2025
23f5aab
Merge remote-tracking branch 'origin/PMM-9288-extended-profiler' into…
JiriCtvrtka Mar 7, 2025
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
82 changes: 64 additions & 18 deletions agent/agents/mongodb/internal/profiler/aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ import (

var DefaultInterval = time.Duration(time.Minute)

const reportChanBuffer = 1000
const (
reportChanBuffer = 1000
millisecondsToSeconds = 1000
microsecondsToSeconds = 1000000
)

// New returns configured *Aggregator
func New(timeStart time.Time, agentID string, logger *logrus.Entry, maxQueryLength int32) *Aggregator {
Expand Down Expand Up @@ -258,12 +262,12 @@ func (a *Aggregator) createResult(_ context.Context) *report.Result {
query, truncated := truncate.Query(v.Query, a.maxQueryLength, truncate.GetMongoDBDefaultMaxQueryLength())
bucket := &agentv1.MetricsBucket{
Common: &agentv1.MetricsBucket_Common{
Queryid: v.ID,
Queryid: v.ID, // PMM-13466
Fingerprint: fingerprint,
Database: db,
Tables: []string{collection},
Username: "",
ClientHost: "",
Username: v.User,
ClientHost: v.Client,
AgentId: a.agentID,
AgentType: inventoryv1.AgentType_AGENT_TYPE_QAN_MONGODB_PROFILER_AGENT,
PeriodStartUnixSecs: uint32(a.timeStart.Truncate(1 * time.Minute).Unix()),
Expand All @@ -272,38 +276,80 @@ func (a *Aggregator) createResult(_ context.Context) *report.Result {
ExampleType: agentv1.ExampleType_EXAMPLE_TYPE_RANDOM,
NumQueries: float32(v.Count),
IsTruncated: truncated,
Comments: nil, // PMM-11866
},
Mongodb: &agentv1.MetricsBucket_MongoDB{},
}

bucket.Common.MQueryTimeCnt = float32(v.Count) // TODO: Check is it right value
bucket.Common.MQueryTimeMax = float32(v.QueryTime.Max) / 1000
bucket.Common.MQueryTimeMin = float32(v.QueryTime.Min) / 1000
bucket.Common.MQueryTimeP99 = float32(v.QueryTime.Pct99) / 1000
bucket.Common.MQueryTimeSum = float32(v.QueryTime.Total) / 1000
bucket.Common.MQueryTimeCnt = float32(v.Count) // PMM-13788
bucket.Common.MQueryTimeMax = float32(v.QueryTime.Max) / millisecondsToSeconds
bucket.Common.MQueryTimeMin = float32(v.QueryTime.Min) / millisecondsToSeconds
bucket.Common.MQueryTimeP99 = float32(v.QueryTime.Pct99) / millisecondsToSeconds
bucket.Common.MQueryTimeSum = float32(v.QueryTime.Total) / millisecondsToSeconds

bucket.Mongodb.MDocsReturnedCnt = float32(v.Count) // TODO: Check is it right value
bucket.Mongodb.MDocsReturnedCnt = float32(v.Count) // PMM-13788
bucket.Mongodb.MDocsReturnedMax = float32(v.Returned.Max)
bucket.Mongodb.MDocsReturnedMin = float32(v.Returned.Min)
bucket.Mongodb.MDocsReturnedP99 = float32(v.Returned.Pct99)
bucket.Mongodb.MDocsReturnedSum = float32(v.Returned.Total)

bucket.Mongodb.MDocsScannedCnt = float32(v.Count) // TODO: Check is it right value
bucket.Mongodb.MDocsScannedMax = float32(v.Scanned.Max)
bucket.Mongodb.MDocsScannedMin = float32(v.Scanned.Min)
bucket.Mongodb.MDocsScannedP99 = float32(v.Scanned.Pct99)
bucket.Mongodb.MDocsScannedSum = float32(v.Scanned.Total)
Comment on lines -291 to -295
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deprecated


bucket.Mongodb.MResponseLengthCnt = float32(v.Count) // TODO: Check is it right value
bucket.Mongodb.MResponseLengthCnt = float32(v.ResponseLengthCount)
bucket.Mongodb.MResponseLengthMax = float32(v.ResponseLength.Max)
bucket.Mongodb.MResponseLengthMin = float32(v.ResponseLength.Min)
bucket.Mongodb.MResponseLengthP99 = float32(v.ResponseLength.Pct99)
bucket.Mongodb.MResponseLengthSum = float32(v.ResponseLength.Total)

bucket.Mongodb.MFullScanCnt = float32(v.CollScanCount)
bucket.Mongodb.MFullScanSum = float32(v.CollScanSum) / 1000
bucket.Mongodb.MFullScanSum = float32(v.CollScanCount) // Sum is same like count in this case
Comment on lines -304 to +303
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@igroene please check if in case of Full Scan (CollScan in Mongo) are Sum and Count values same.

Copy link
Member

Choose a reason for hiding this comment

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

what if we count the distinct number of collscans and use sum for the total number? would it be too complicated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if I understood you correctly, but:

  1. Currently, it is the total sum of the number of collection scans. Is this what you meant?
  2. If you're asking about the total number of all stages, then yes, it would be complicated at this point. To achieve that, we would need to change the way data is collected, which could be done in a separate ticket.

Or did you mean something entirely different?

Copy link
Member

Choose a reason for hiding this comment

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

what I mean is, keep the SUM as the total number of recorded COLSCANS for that particular query shape. Use COUNT for the number of recorded COLSCANS of the particular query shape that have different values for the variables. Assuming we captured the following 4 queries:

db.testcol.find({a:101})
db.testcol.find({a:101})
db.testcol.find({a:200})
db.testcol.find({a:140})

assuming all the above are collscans, SUM would be 4 and COUNT would be 3. Makes sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. Yes, this should be possible. Let me adjust the code to make it work. Thanks for the explanation.

Copy link
Member

Choose a reason for hiding this comment

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

@JiriCtvrtka current implementation should make it, no adjustment required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for verifying.

bucket.Mongodb.PlanSummary = v.PlanSummary

bucket.Mongodb.ApplicationName = v.AppName

bucket.Mongodb.MDocsExaminedCnt = float32(v.DocsExaminedCount)
bucket.Mongodb.MDocsExaminedMax = float32(v.DocsExamined.Max)
bucket.Mongodb.MDocsExaminedMin = float32(v.DocsExamined.Min)
bucket.Mongodb.MDocsExaminedP99 = float32(v.DocsExamined.Pct99)
bucket.Mongodb.MDocsExaminedSum = float32(v.DocsExamined.Total)

bucket.Mongodb.MKeysExaminedCnt = float32(v.KeysExaminedCount)
bucket.Mongodb.MKeysExaminedMax = float32(v.KeysExamined.Max)
bucket.Mongodb.MKeysExaminedMin = float32(v.KeysExamined.Min)
bucket.Mongodb.MKeysExaminedP99 = float32(v.KeysExamined.Pct99)
bucket.Mongodb.MKeysExaminedSum = float32(v.KeysExamined.Total)

bucket.Mongodb.MLocksGlobalAcquireCountReadSharedCnt = float32(v.LocksGlobalAcquireCountReadSharedCount)
bucket.Mongodb.MLocksGlobalAcquireCountReadSharedSum = float32(v.LocksGlobalAcquireCountReadShared)

bucket.Mongodb.MLocksGlobalAcquireCountWriteSharedCnt = float32(v.LocksGlobalAcquireCountWriteSharedCount)
bucket.Mongodb.MLocksGlobalAcquireCountWriteSharedSum = float32(v.LocksGlobalAcquireCountWriteShared)

bucket.Mongodb.MLocksDatabaseAcquireCountReadSharedCnt = float32(v.LocksDatabaseAcquireCountReadSharedCount)
bucket.Mongodb.MLocksDatabaseAcquireCountReadSharedSum = float32(v.LocksDatabaseAcquireCountReadShared)

bucket.Mongodb.MLocksDatabaseAcquireWaitCountReadSharedCnt = float32(v.LocksDatabaseAcquireWaitCountReadSharedCount)
bucket.Mongodb.MLocksDatabaseAcquireWaitCountReadSharedSum = float32(v.LocksDatabaseAcquireWaitCountReadShared)

bucket.Mongodb.MLocksDatabaseTimeAcquiringMicrosReadSharedCnt = float32(v.LocksDatabaseTimeAcquiringMicrosReadSharedCount)
bucket.Mongodb.MLocksDatabaseTimeAcquiringMicrosReadSharedMax = float32(v.LocksDatabaseTimeAcquiringMicrosReadShared.Max) / microsecondsToSeconds
bucket.Mongodb.MLocksDatabaseTimeAcquiringMicrosReadSharedMin = float32(v.LocksDatabaseTimeAcquiringMicrosReadShared.Min) / microsecondsToSeconds
bucket.Mongodb.MLocksDatabaseTimeAcquiringMicrosReadSharedP99 = float32(v.LocksDatabaseTimeAcquiringMicrosReadShared.Pct99) / microsecondsToSeconds
bucket.Mongodb.MLocksDatabaseTimeAcquiringMicrosReadSharedSum = float32(v.LocksDatabaseTimeAcquiringMicrosReadShared.Total) / microsecondsToSeconds

bucket.Mongodb.MLocksCollectionAcquireCountReadSharedCnt = float32(v.LocksCollectionAcquireCountReadSharedCount)
bucket.Mongodb.MLocksCollectionAcquireCountReadSharedSum = float32(v.LocksCollectionAcquireCountReadShared)

bucket.Mongodb.MStorageBytesReadCnt = float32(v.StorageBytesReadCount)
bucket.Mongodb.MStorageBytesReadMax = float32(v.StorageBytesRead.Max)
bucket.Mongodb.MStorageBytesReadMin = float32(v.StorageBytesRead.Min)
bucket.Mongodb.MStorageBytesReadP99 = float32(v.StorageBytesRead.Pct99)
bucket.Mongodb.MStorageBytesReadSum = float32(v.StorageBytesRead.Total)

bucket.Mongodb.MStorageTimeReadingMicrosCnt = float32(v.StorageTimeReadingMicrosCount)
bucket.Mongodb.MStorageTimeReadingMicrosMax = float32(v.StorageTimeReadingMicros.Max) / microsecondsToSeconds
bucket.Mongodb.MStorageTimeReadingMicrosMin = float32(v.StorageTimeReadingMicros.Min) / microsecondsToSeconds
bucket.Mongodb.MStorageTimeReadingMicrosP99 = float32(v.StorageTimeReadingMicros.Pct99) / microsecondsToSeconds
bucket.Mongodb.MStorageTimeReadingMicrosSum = float32(v.StorageTimeReadingMicros.Total) / microsecondsToSeconds

buckets = append(buckets, bucket)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ func TestAggregator(t *testing.T) {
defer aggregator.Stop()
ctx := context.TODO()
err := aggregator.Add(ctx, proto.SystemProfile{
NscannedObjects: 2,
Nreturned: 3,
Ns: "collection.people",
Op: "insert",
Nreturned: 3,
Ns: "collection.people",
Op: "insert",
DocsExamined: 2,
KeysExamined: 3,
})
require.NoError(t, err)

Expand Down Expand Up @@ -85,11 +86,16 @@ func TestAggregator(t *testing.T) {
MDocsReturnedMax: 3,
MDocsReturnedP99: 3,
MResponseLengthCnt: 1,
MDocsScannedCnt: 1,
MDocsScannedSum: 2,
MDocsScannedMin: 2,
MDocsScannedMax: 2,
MDocsScannedP99: 2,
MDocsExaminedCnt: 1,
MDocsExaminedSum: 2,
MDocsExaminedMin: 2,
MDocsExaminedMax: 2,
MDocsExaminedP99: 2,
MKeysExaminedCnt: 1,
MKeysExaminedSum: 3,
MKeysExaminedMin: 3,
MKeysExaminedMax: 3,
MKeysExaminedP99: 3,
},
},
},
Expand All @@ -104,10 +110,9 @@ func TestAggregator(t *testing.T) {
defer aggregator.Stop()
ctx := context.TODO()
err := aggregator.Add(ctx, proto.SystemProfile{
NscannedObjects: 2,
Nreturned: 3,
Ns: "collection.people",
Op: "query",
Nreturned: 3,
Ns: "collection.people",
Op: "query",
Command: bson.D{
primitive.E{Key: "find", Value: "people"},
primitive.E{
Expand All @@ -117,6 +122,8 @@ func TestAggregator(t *testing.T) {
},
},
},
DocsExamined: 2,
KeysExamined: 3,
})
require.NoError(t, err)

Expand Down Expand Up @@ -148,11 +155,16 @@ func TestAggregator(t *testing.T) {
MDocsReturnedMax: 3,
MDocsReturnedP99: 3,
MResponseLengthCnt: 1,
MDocsScannedCnt: 1,
MDocsScannedSum: 2,
MDocsScannedMin: 2,
MDocsScannedMax: 2,
MDocsScannedP99: 2,
MDocsExaminedCnt: 1,
MDocsExaminedSum: 2,
MDocsExaminedMin: 2,
MDocsExaminedMax: 2,
MDocsExaminedP99: 2,
MKeysExaminedCnt: 1,
MKeysExaminedSum: 3,
MKeysExaminedMin: 3,
MKeysExaminedMax: 3,
MKeysExaminedP99: 3,
},
},
},
Expand Down
17 changes: 8 additions & 9 deletions agent/agents/mongodb/internal/profiler/profiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func testProfiler(t *testing.T, url string) {
b.Mongodb.MDocsReturnedCnt += bucket.Mongodb.MDocsReturnedCnt
b.Mongodb.MResponseLengthCnt += bucket.Mongodb.MResponseLengthCnt
b.Mongodb.MResponseLengthSum += bucket.Mongodb.MResponseLengthSum
b.Mongodb.MDocsScannedCnt += bucket.Mongodb.MDocsScannedCnt
b.Mongodb.MDocsExaminedCnt += bucket.Mongodb.MDocsExaminedCnt
} else {
bucketsMap[key] = bucket
}
Expand Down Expand Up @@ -184,16 +184,15 @@ func testProfiler(t *testing.T, url string) {
MResponseLengthMin: responseLength,
MResponseLengthMax: responseLength,
MResponseLengthP99: responseLength,
MDocsScannedCnt: docsCount,
}
// TODO: fix protobuf equality https://jira.percona.com/browse/PMM-6743
assert.Equalf(t, expected.MDocsReturnedCnt, bucket.Mongodb.MDocsReturnedCnt, "wrong metrics for db %s", bucket.Common.Database)
assert.Equalf(t, expected.MResponseLengthCnt, bucket.Mongodb.MResponseLengthCnt, "wrong metrics for db %s", bucket.Common.Database)
assert.Equalf(t, expected.MResponseLengthSum, bucket.Mongodb.MResponseLengthSum, "wrong metrics for db %s", bucket.Common.Database)
assert.Equalf(t, expected.MResponseLengthMin, bucket.Mongodb.MResponseLengthMin, "wrong metrics for db %s", bucket.Common.Database)
assert.Equalf(t, expected.MResponseLengthMax, bucket.Mongodb.MResponseLengthMax, "wrong metrics for db %s", bucket.Common.Database)
assert.Equalf(t, expected.MResponseLengthP99, bucket.Mongodb.MResponseLengthP99, "wrong metrics for db %s", bucket.Common.Database)
assert.Equalf(t, expected.MDocsScannedCnt, bucket.Mongodb.MDocsScannedCnt, "wrong metrics for db %s", bucket.Common.Database)
assert.Equalf(t, expected.MDocsReturnedCnt, bucket.Mongodb.MDocsReturnedCnt, "wrong metrics MDocsReturnedCnt for db %s", bucket.Common.Database)
assert.Equalf(t, expected.MResponseLengthCnt, bucket.Mongodb.MResponseLengthCnt, "wrong metrics MResponseLengthCnt for db %s", bucket.Common.Database)
assert.Equalf(t, expected.MResponseLengthSum, bucket.Mongodb.MResponseLengthSum, "wrong metrics MResponseLengthSum for db %s", bucket.Common.Database)
assert.Equalf(t, expected.MResponseLengthMin, bucket.Mongodb.MResponseLengthMin, "wrong metrics MResponseLengthMin for db %s", bucket.Common.Database)
assert.Equalf(t, expected.MResponseLengthMax, bucket.Mongodb.MResponseLengthMax, "wrong metrics MResponseLengthMax for db %s", bucket.Common.Database)
assert.Equalf(t, expected.MResponseLengthP99, bucket.Mongodb.MResponseLengthP99, "wrong metrics MResponseLengthP99 for db %s", bucket.Common.Database)
assert.Equalf(t, expected.MDocsExaminedCnt, bucket.Mongodb.MDocsExaminedCnt, "wrong metrics MDocsExaminedCnt for db %s", bucket.Common.Database)
}
require.NotNil(t, findBucket)
assert.Equal(t, `db.people.find({"name_00\ufffd":"?"})`, findBucket.Common.Fingerprint)
Expand Down
Loading
Loading