Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -13165,6 +13165,7 @@ spec:
enum:
- pgstatmonitor
- pgstatstatements
- none
type: string
resources:
properties:
Expand Down
1 change: 1 addition & 0 deletions config/crd/bases/pgv2.percona.com_perconapgclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13579,6 +13579,7 @@ spec:
enum:
- pgstatmonitor
- pgstatstatements
- none
type: string
resources:
properties:
Expand Down
1 change: 1 addition & 0 deletions deploy/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13780,6 +13780,7 @@ spec:
enum:
- pgstatmonitor
- pgstatstatements
- none
type: string
resources:
properties:
Expand Down
1 change: 1 addition & 0 deletions deploy/cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ spec:
# cpu: 300m
# customClusterName: "<string>"
# postgresParams: "<string>"
# # Query Analytics source: pgstatstatements (default), pgstatmonitor, or none to disable QAN.

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.

i think this comment is not needed

# querySource: pgstatmonitor
logcollector:
enabled: true
Expand Down
1 change: 1 addition & 0 deletions deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13780,6 +13780,7 @@ spec:
enum:
- pgstatmonitor
- pgstatstatements
- none
type: string
resources:
properties:
Expand Down
1 change: 1 addition & 0 deletions deploy/cw-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13780,6 +13780,7 @@ spec:
enum:
- pgstatmonitor
- pgstatstatements
- none
type: string
resources:
properties:
Expand Down
35 changes: 35 additions & 0 deletions e2e-tests/tests/monitoring/10-disable-qan-query-source.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |-
set -o errexit
set -o xtrace

source ../../functions

# K8SPG-1147: querySource "none" must turn Query Analytics off while
# leaving metrics collection in place.
kubectl -n ${NAMESPACE} patch perconapgcluster/monitoring --type=merge -p '{
"spec":{
"pmm":{"querySource":"none"}
}
}'

# Wait for PMM to re-register the service without a QAN agent.
sleep 80

primary=$(get_pod_by_role monitoring primary name)
kubectl -n ${NAMESPACE} exec ${primary} -c pmm-client -- pmm-admin list

# No QAN agent of either flavor may be registered.
if kubectl -n ${NAMESPACE} exec ${primary} -c pmm-client -- pmm-admin list | grep -E 'postgresql_pgstatements_agent|postgresql_pgstatmonitor_agent'; then
echo "a QAN agent is still running with querySource=none"
exit 1
fi

# Metrics collection must be unaffected.
if ! kubectl -n ${NAMESPACE} exec ${primary} -c pmm-client -- pmm-admin list | grep postgres_exporter; then
echo "postgres_exporter is not running"
exit 1
fi
timeout: 360
66 changes: 66 additions & 0 deletions percona/pmm/pmm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,69 @@ func TestSidecarContainer(t *testing.T) {
assert.Equal(t, "/pgconf/tls", container.VolumeMounts[0].MountPath)
assert.True(t, container.VolumeMounts[0].ReadOnly)
}

func TestQuerySource(t *testing.T) {
t.Parallel()

for name, tt := range map[string]struct {
crVersion string
source v2.PMMQuerySource
expected string
}{
"pg_stat_statements is mapped to the pmm-admin spelling": {
crVersion: "2.9.0",
source: v2.PgStatStatements,
expected: "pgstatements",
},
"pg_stat_monitor is passed through": {
crVersion: "2.9.0",
source: v2.PgStatMonitor,
expected: "pgstatmonitor",
},
"none is passed through to disable QAN": {
crVersion: "2.9.0",
source: v2.QuerySourceNone,
expected: "none",
},
"none is passed through on older CR versions too": {
crVersion: "2.8.0",
source: v2.QuerySourceNone,
expected: "none",
},
"pg_stat_statements is not remapped before 2.9.0": {
crVersion: "2.8.0",
source: v2.PgStatStatements,
expected: "pgstatstatements",
},
} {
t.Run(name, func(t *testing.T) {
t.Parallel()

pgc := &v2.PerconaPGCluster{
Spec: v2.PerconaPGClusterSpec{CRVersion: tt.crVersion},
}

assert.Equal(t, tt.expected, querySource(pgc, tt.source))
})
}
}

// TestAgentPrerunScriptQuerySourceNone guards the K8SPG-1147 contract: a cluster
// with querySource "none" must register the service with --query-source=none so
// pmm-admin skips the QAN agent instead of silently ignoring an unknown value.
func TestAgentPrerunScriptQuerySourceNone(t *testing.T) {
t.Parallel()

pgc := &v2.PerconaPGCluster{
ObjectMeta: metav1.ObjectMeta{Name: "test-cluster"},
Spec: v2.PerconaPGClusterSpec{
CRVersion: "2.9.0",
PMM: &v2.PMMSpec{Enabled: true, QuerySource: v2.QuerySourceNone},
},
}

script := agentPrerunScript(pgc)

assert.Contains(t, script, "--query-source=none")
assert.NotContains(t, script, "--query-source=pgstat")
}
7 changes: 6 additions & 1 deletion pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,9 @@ type PMMQuerySource string
const (
PgStatStatements PMMQuerySource = "pgstatstatements"
PgStatMonitor PMMQuerySource = "pgstatmonitor"
// QuerySourceNone disables Query Analytics for the cluster. Metrics are
// still collected; only the QAN agent is left unregistered.
QuerySourceNone PMMQuerySource = "none"
)

type PMMSpec struct {
Expand Down Expand Up @@ -1223,7 +1226,9 @@ type PMMSpec struct {
// +kubebuilder:validation:Required
Secret string `json:"secret,omitempty"`

// +kubebuilder:validation:Enum={pgstatmonitor,pgstatstatements}
// QuerySource selects the Query Analytics source for the cluster.
// Use "none" to disable Query Analytics while keeping metrics collection.
// +kubebuilder:validation:Enum={pgstatmonitor,pgstatstatements,none}
// +kubebuilder:default=pgstatstatements
// +kubebuilder:validation:Required
QuerySource PMMQuerySource `json:"querySource,omitempty"`
Expand Down
37 changes: 37 additions & 0 deletions pkg/apis/pgv2.percona.com/v2/perconapgcluster_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,43 @@ func TestPerconaPGCluster_ToCrunchy(t *testing.T) {
assert.False(t, actual.Spec.Extensions.PGStatStatements)
},
},
"handles PMM none query source": {
expectedPerconaPGCluster: &PerconaPGCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
Namespace: "test-namespace",
},
Spec: PerconaPGClusterSpec{
CRVersion: "2.9.0",
PostgresVersion: 15,
PMM: &PMMSpec{
Enabled: true,
QuerySource: QuerySourceNone,
},
InstanceSets: PGInstanceSets{
{
Name: "instance1",
Replicas: &[]int32{1}[0],
DataVolumeClaimSpec: corev1.PersistentVolumeClaimSpec{
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
},
},
},
Backups: Backups{
PGBackRest: PGBackRestArchive{
Repos: []crunchyv1beta1.PGBackRestRepo{
{Name: "repo1"},
},
},
},
},
},
assertClusterFunc: func(t *testing.T, actual *crunchyv1beta1.PostgresCluster, _ *PerconaPGCluster) {
// Neither query-source extension is installed when QAN is off.
assert.False(t, actual.Spec.Extensions.PGStatMonitor)
assert.False(t, actual.Spec.Extensions.PGStatStatements)
},
},
"handles AutoCreateUserSchema annotation": {
expectedPerconaPGCluster: &PerconaPGCluster{
ObjectMeta: metav1.ObjectMeta{
Expand Down
Loading