Skip to content

K8SPSMDB-1546 add PMM querySource#2380

Merged
hors merged 12 commits into
mainfrom
K8SPSMDB-1546
Jun 12, 2026
Merged

K8SPSMDB-1546 add PMM querySource#2380
hors merged 12 commits into
mainfrom
K8SPSMDB-1546

Conversation

@nmarukovich

@nmarukovich nmarukovich commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

CHANGE DESCRIPTION

Problem:
Add a new pmm.querySource field to the CR that lets users choose how PMM collects Query Analytics (QAN) data:

profiler (default)
mongolog — from mongod log files (requires PMM >= 3.3.0 and logcollector enabled so logs are written at /data/db/logs/)
When set, the value is passed to pmm-admin via --query-source.

Tests:

Add mongolog QAN check to the monitoring-pmm3 e2e test.
Update compare files.

Cause:
Short explanation of the root cause of the issue if applicable.

Solution:
Short explanation of the solution we are providing with this PR.

CHECKLIST

Jira

  • Is the Jira ticket created and referenced properly?
  • Does the Jira ticket have the proper statuses for documentation (Needs Doc) and QA (Needs QA)?
  • Does the Jira ticket link to the proper milestone (Fix Version field)?

Tests

  • Is an E2E test/test case added for the new feature/change?
  • Are unit tests added where appropriate?
  • Are OpenShift compare files changed for E2E tests (compare/*-oc.yml)?

Config/Logging/Testability

  • Are all needed new/changed options added to default YAML files?
  • Are all needed new/changed options added to the Helm Chart?
  • Did we add proper logging messages for operator actions?
  • Did we ensure compatibility with the previous version or cluster upgrade process?
  • Does the change support oldest and newest supported MongoDB version?
  • Does the change support oldest and newest supported Kubernetes version?

Copilot AI review requested due to automatic review settings June 4, 2026 08:05
@pull-request-size pull-request-size Bot added the size/L 100-499 lines label Jun 4, 2026
@github-actions github-actions Bot added the tests label Jun 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for selecting the MongoDB Query Analytics (QAN) collection source for PMM by introducing a spec.pmm.querySource field (enum: profiler/mongolog) and wiring it into the PMM sidecar’s pmm-admin add invocation, along with accompanying CRD, unit test, and E2E test updates.

Changes:

  • Add PMMSpec.QuerySource to the API/CRD and pass it to PMM via --query-source=... when set.
  • Extend unit tests to verify the --query-source flag is added/omitted correctly.
  • Update PMM3 E2E scenario to enable logcollector and validate QAN collection after switching to mongolog.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/psmdb/pmm/pmm.go Append --query-source to the PMM pmm-admin add command when configured.
pkg/psmdb/pmm/pmm_test.go Add assertions/tests for querySource flag presence/absence.
pkg/apis/psmdb/v1/psmdb_types.go Introduce PMMSpec.QuerySource with kubebuilder enum validation and docs.
config/crd/bases/psmdb.percona.com_perconaservermongodbs.yaml CRD schema update to include pmm.querySource.
deploy/crd.yaml Bundle CRD schema update for pmm.querySource.
deploy/bundle.yaml Bundle CRD schema update for pmm.querySource.
deploy/cw-bundle.yaml Bundle CRD schema update for pmm.querySource.
e2e-tests/version-service/conf/crd.yaml Test CRD schema update for pmm.querySource.
deploy/cr.yaml Document the new pmm.querySource option in the example CR.
e2e-tests/monitoring-pmm3/conf/monitoring-pmm3-rs0.yml Enable logcollector in the PMM3 monitoring E2E config.
e2e-tests/monitoring-pmm3/run Patch cluster during E2E to switch QAN source to mongolog and validate QAN.
e2e-tests/monitoring-pmm3/compare/statefulset_monitoring-pmm3-rs0.yml Update expected manifests to include logcollector env/sidecars.
e2e-tests/monitoring-pmm3/compare/statefulset_monitoring-pmm3-rs0-oc.yml Same as above for OpenShift compare output.
e2e-tests/monitoring-pmm3/compare/statefulset_monitoring-pmm3-rs0-no-pmm.yml Same as above for “no pmm-client container yet” compare output.
e2e-tests/monitoring-pmm3/compare/statefulset_monitoring-pmm3-rs0-no-pmm-oc.yml Same as above for OpenShift “no pmm-client container yet”.
e2e-tests/monitoring-pmm3/compare/statefulset_monitoring-pmm3-cfg.yml Update expected manifests for configsvr with logcollector.
e2e-tests/monitoring-pmm3/compare/statefulset_monitoring-pmm3-cfg-oc.yml Same as above for OpenShift compare output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/psmdb/pmm/pmm.go
Comment on lines +283 to +285
if cr.Spec.PMM.QuerySource != "" {
pmmServerArgs += " --query-source=" + cr.Spec.PMM.QuerySource
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it can't really happen in practice. querySource only exists in the CRD from 1.23, so you need the 1.23 operator to set it. With sequential upgrades, you get to 1.23 from 1.22 — and 1.22 already mounts /data/db (PMM3 gate is >= 1.22.0). So during a normal 1.22 → 1.23 upgrade the mount is always there and mongolog works.

The only way to break it is to manually pin crVersion below 1.22 on a 1.23 operator, which isn't a supported upgrade path.

Comment thread deploy/cr.yaml Outdated
Comment on lines +82 to +85
# customClusterName: mongo-cluster
# mongodParams: --environment=ENVIRONMENT
# mongosParams: --environment=ENVIRONMENT
# querySource: mongolog
Copilot AI review requested due to automatic review settings June 8, 2026 08:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.

Comment thread pkg/psmdb/pmm/pmm.go
Comment on lines +283 to +285
if cr.Spec.PMM.QuerySource != "" {
pmmServerArgs += " --query-source=" + cr.Spec.PMM.QuerySource
}
Comment thread pkg/psmdb/pmm/pmm_test.go
Comment on lines +92 to +96
"pmm enabled - query-source=mongolog is set": {
secret: tokenSecret,
setup: func(cr *api.PerconaServerMongoDB) {
cr.Spec.PMM.QuerySource = "mongolog"
},
Comment on lines +451 to +454
// QuerySource defines the source for Query Analytics (QAN) data collection.
// Use "profiler" to collect queries via the MongoDB profiler (default),
// or "mongolog" to collect queries from mongod log files (requires PMM >= 3.3.0
// and mongod configured to write logs to /data/db/logs/).
Comment on lines 350 to +353
yq eval '(.spec | select(.image == null)).image = "'"$IMAGE_MONGOD"'"' "$test_dir/conf/$cluster-rs0.yml" \
| yq eval '(.spec | select(has("pmm"))).pmm.image = "'"$IMAGE_PMM3_CLIENT"'"' - \
| yq eval '(.spec | select(has("pmm"))).pmm.customClusterName = "'"$custom_cluster_name"'"' - \
| yq eval '(.spec | select(has("logcollector"))).logcollector.image = "'"$IMAGE_LOGCOLLECTOR"'"' - \
@hors hors added this to the v1.23.0 milestone Jun 8, 2026
Comment on lines +451 to +453
// QuerySource defines the source for Query Analytics (QAN) data collection.
// Use "profiler" to collect queries via the MongoDB profiler (default),
// or "mongolog" to collect queries from mongod log files (requires PMM >= 3.3.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Noticed that we have maxDescLen=0 while generating CRD, so all these comments (which do a great job explaining how the field should be used) don't end up anywhere.
It's not directly related to this PR, I'm just curious why so. Are there any limits we hit so we need to exclude the descriptions?

@egegunes egegunes changed the title K8SPSMDB-1546 add mongolog K8SPSMDB-1546 add PMM querySource Jun 9, 2026
// or "mongolog" to collect queries from mongod log files (requires PMM >= 3.3.0
// and mongod configured to write logs to /data/db/logs/).
// +kubebuilder:validation:Enum=profiler;mongolog
QuerySource string `json:"querySource,omitempty"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we configure the default here?

Comment thread deploy/cr.yaml Outdated
# customClusterName: mongo-cluster
# mongodParams: --environment=ENVIRONMENT
# mongosParams: --environment=ENVIRONMENT
# querySource: mongolog

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if profiler is the default, should we have that here?

gkech
gkech previously approved these changes Jun 9, 2026

@hors hors left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@nmarukovich please check PMM3 test

Copilot AI review requested due to automatic review settings June 10, 2026 15:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.

Comment thread pkg/psmdb/pmm/pmm.go
Comment on lines +283 to +285
if cr.Spec.PMM.QuerySource != "" {
pmmServerArgs += " --query-source=" + cr.Spec.PMM.QuerySource
}
Comment thread pkg/psmdb/pmm/pmm_test.go
Comment on lines +92 to 110
"pmm enabled - query-source=mongolog is set": {
secret: tokenSecret,
setup: func(cr *api.PerconaServerMongoDB) {
cr.Spec.PMM.QuerySource = "mongolog"
},
assert: assertQuerySource("mongolog"),
},
"pmm enabled - query-source=profiler is set": {
secret: tokenSecret,
setup: func(cr *api.PerconaServerMongoDB) {
cr.Spec.PMM.QuerySource = "profiler"
},
assert: assertQuerySource("profiler"),
},
"pmm enabled - query-source not set omits flag": {
secret: tokenSecret,
assert: assertNoQuerySource(),
},
}
@nmarukovich nmarukovich dismissed stale reviews from oksana-grishchenko and gkech via a46d8e0 June 10, 2026 16:54
Copilot AI review requested due to automatic review settings June 10, 2026 17:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated no new comments.

egegunes
egegunes previously approved these changes Jun 11, 2026
@nmarukovich nmarukovich requested a review from hors June 11, 2026 07:57
Copilot AI review requested due to automatic review settings June 12, 2026 08:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 26 out of 26 changed files in this pull request and generated 1 comment.

Comment on lines +463 to +466
// QuerySource defines the source for Query Analytics (QAN) data collection.
// Use "profiler" to collect queries via the MongoDB profiler (default),
// or "mongolog" to collect queries from mongod log files (requires PMM >= 3.3.0
// and mongod configured to write logs to /data/db/logs/).
@JNKPercona

Copy link
Copy Markdown
Collaborator
Test Name Result Time
arbiter passed 00:00:00
balancer passed 00:00:00
cert-management-policy passed 00:00:00
cross-site-sharded passed 00:00:00
custom-replset-name passed 00:00:00
custom-tls passed 00:00:00
custom-users-roles passed 00:00:00
custom-users-roles-sharded passed 00:00:00
data-at-rest-encryption passed 00:00:00
data-sharded passed 00:00:00
demand-backup passed 00:00:00
demand-backup-eks-credentials-irsa passed 00:00:00
demand-backup-fs passed 00:00:00
demand-backup-if-unhealthy passed 00:00:00
demand-backup-incremental-aws passed 00:00:00
demand-backup-incremental-azure passed 00:00:00
demand-backup-incremental-gcp-native passed 00:00:00
demand-backup-incremental-gcp-s3 passed 00:00:00
demand-backup-incremental-minio passed 00:00:00
demand-backup-incremental-sharded-aws passed 00:00:00
demand-backup-incremental-sharded-azure passed 00:00:00
demand-backup-incremental-sharded-gcp-native passed 00:00:00
demand-backup-incremental-sharded-gcp-s3 passed 00:00:00
demand-backup-incremental-sharded-minio passed 00:00:00
demand-backup-logical-minio-native-tls passed 00:00:00
demand-backup-physical-parallel passed 00:00:00
demand-backup-physical-aws passed 00:00:00
demand-backup-physical-azure passed 00:00:00
demand-backup-physical-gcp-s3 passed 00:00:00
demand-backup-physical-gcp-native passed 00:00:00
demand-backup-physical-minio passed 00:00:00
demand-backup-physical-minio-native passed 00:00:00
demand-backup-physical-minio-native-tls passed 00:00:00
demand-backup-physical-sharded-parallel passed 00:00:00
demand-backup-physical-sharded-aws passed 00:00:00
demand-backup-physical-sharded-azure passed 00:00:00
demand-backup-physical-sharded-gcp-native passed 00:00:00
demand-backup-physical-sharded-minio passed 00:00:00
demand-backup-physical-sharded-minio-native passed 00:00:00
demand-backup-sharded passed 00:00:00
demand-backup-snapshot passed 00:00:00
demand-backup-snapshot-vault passed 00:00:00
disabled-auth passed 00:00:00
expose-sharded passed 00:00:00
finalizer passed 00:00:00
ignore-labels-annotations passed 00:00:00
init-deploy passed 00:00:00
ldap passed 00:00:00
ldap-tls passed 00:00:00
limits passed 00:00:00
liveness passed 00:00:00
mongod-major-upgrade passed 00:00:00
mongod-major-upgrade-sharded passed 00:00:00
monitoring-2-0 passed 00:00:00
monitoring-pmm3 passed 00:00:00
multi-cluster-service passed 00:00:00
multi-storage passed 00:00:00
non-voting-and-hidden passed 00:00:00
one-pod passed 00:00:00
operator-self-healing-chaos passed 00:00:00
pitr passed 00:00:00
pitr-physical passed 00:00:00
pitr-sharded passed 00:00:00
pitr-to-new-cluster passed 00:00:00
pitr-physical-backup-source passed 00:00:00
preinit-updates passed 00:00:00
pvc-auto-resize passed 00:00:00
pvc-resize passed 00:00:00
recover-no-primary passed 00:00:00
replset-overrides passed 00:00:00
replset-remapping passed 00:00:00
replset-remapping-sharded passed 00:00:00
rs-shard-migration passed 00:00:00
scaling passed 00:00:00
scheduled-backup passed 00:00:00
security-context passed 00:00:00
self-healing-chaos passed 00:00:00
service-per-pod passed 00:00:00
serviceless-external-nodes passed 00:00:00
smart-update passed 00:00:00
split-horizon passed 00:00:00
split-horizon-manual-tls passed 00:00:00
stable-resource-version passed 00:00:00
storage passed 00:00:00
tls-issue-cert-manager passed 00:00:00
unsafe-psa passed 00:00:00
upgrade passed 00:00:00
upgrade-consistency passed 00:00:00
upgrade-consistency-sharded-tls passed 00:00:00
upgrade-sharded passed 00:00:00
upgrade-partial-backup passed 00:00:00
users passed 00:00:00
users-vault passed 00:00:00
version-service passed 00:00:00
Summary Value
Tests Run 94/94
Job Duration 00:11:51
Total Test Time N/A

commit: 5896eaf
image: perconalab/percona-server-mongodb-operator:PR-2380-5896eaf9a

@hors hors merged commit cbe1222 into main Jun 12, 2026
16 checks passed
@hors hors deleted the K8SPSMDB-1546 branch June 12, 2026 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L 100-499 lines tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants