Skip to content

Commit df492f1

Browse files
chobostarcbandy
authored andcommitted
Turn off JIT for only monitoring user's context
It prevents issues related to monitoring queries: - slow query executing due to unnecessary inlining, optimization and emission - memory leak due to re-creating struct types during inlining related issues (CrunchyData/crunchy-containers#1381) (CrunchyData/pgmonitor#182) On the other hand database is open to enabling JIT for other users Issue: [sc-15755] Signed-off-by: Kirill Petrov <[email protected]>
1 parent 39a8e1f commit df492f1

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

internal/controller/postgrescluster/pgmonitor_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ func TestReconcilePGMonitorExporterStatus(t *testing.T) {
437437
podExecCalled: false,
438438
// Status was generated manually for this test case
439439
// TODO jmckulk: add code to generate status
440-
status: v1beta1.MonitoringStatus{ExporterConfiguration: "8b589fd65"},
440+
status: v1beta1.MonitoringStatus{ExporterConfiguration: "5f599686cf"},
441441
statusChangedAfterReconcile: false,
442442
}} {
443443
t.Run(test.name, func(t *testing.T) {
@@ -504,9 +504,9 @@ func TestReconcilePGMonitorExporterStatus(t *testing.T) {
504504

505505
assert.NilError(t, reconciler.reconcilePGMonitorExporter(ctx,
506506
cluster, observed, secret))
507-
assert.Equal(t, called, test.podExecCalled)
508507
assert.Assert(t, test.statusChangedAfterReconcile == (cluster.Status.Monitoring.ExporterConfiguration != test.status.ExporterConfiguration),
509508
"got %v", cluster.Status.Monitoring.ExporterConfiguration)
509+
assert.Equal(t, called, test.podExecCalled)
510510
})
511511
}
512512
}

internal/pgmonitor/postgres.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func DisableExporterInPostgreSQL(ctx context.Context, exec postgres.Executor) er
8888
// EnableExporterInPostgreSQL runs SQL setup commands in `database` to enable
8989
// the exporter to retrieve metrics. pgMonitor objects are created and expected
9090
// extensions are installed. We also ensure that the monitoring user has the
91-
// current password and can login.
91+
// current password, optimal config and can login.
9292
func EnableExporterInPostgreSQL(ctx context.Context, exec postgres.Executor,
9393
monitoringSecret *corev1.Secret, database, setup string) error {
9494
log := logging.FromContext(ctx)
@@ -134,6 +134,12 @@ func EnableExporterInPostgreSQL(ctx context.Context, exec postgres.Executor,
134134
// password; update the password and ensure that the ROLE
135135
// can login to the database
136136
`ALTER ROLE :"username" LOGIN PASSWORD :'verifier';`,
137+
138+
// disable JIT for only ccp_monitoring user's context to prevent:
139+
// - slow executing due unnecessary inlining, optimization and emission
140+
// - memory leak due to re-creating struct types during inlining
141+
// and allow to enable JIT for other database users transparently
142+
`ALTER ROLE :"username" SET jit = off;`,
137143
}, "\n"),
138144
map[string]string{
139145
"database": database,

testing/kuttl/e2e/exporter/01--check-exporter.yaml

+21-14
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,27 @@
22
apiVersion: kuttl.dev/v1beta1
33
kind: TestStep
44
commands:
5-
# Ensure that the metrics endpoint is available from inside the exporter container
65
- script: |
7-
name=$(kubectl -n ${NAMESPACE} get pods --no-headers -o custom-columns="name:{metadata.name}" \
8-
--selector='postgres-operator.crunchydata.com/cluster=exporter,postgres-operator.crunchydata.com/instance-set=instance1')
9-
kubectl -n ${NAMESPACE} exec $name -it -c exporter -- curl http://localhost:9187/metrics
10-
# Ensure that the ccp_monitoring user exists in the database
11-
- script: |
12-
name=$(kubectl -n ${NAMESPACE} get pods --no-headers -o custom-columns="name:{metadata.name}" \
13-
--selector='postgres-operator.crunchydata.com/cluster=exporter,postgres-operator.crunchydata.com/instance-set=instance1')
14-
kubectl -n ${NAMESPACE} exec $name -it -c database -- \
15-
psql -c "DO \$\$
6+
set -e
7+
PRIMARY=$(
8+
kubectl get pod --namespace "${NAMESPACE}" \
9+
--output name --selector '
10+
postgres-operator.crunchydata.com/cluster=exporter,
11+
postgres-operator.crunchydata.com/role=master'
12+
)
13+
14+
# Ensure that the metrics endpoint is available from inside the exporter container
15+
kubectl exec --namespace "${NAMESPACE}" "${PRIMARY}" -c exporter -- curl http://localhost:9187/metrics
16+
17+
# Ensure that the monitoring user exists and is configured.
18+
kubectl exec --stdin --namespace "${NAMESPACE}" "${PRIMARY}" \
19+
-- psql -qb --set ON_ERROR_STOP=1 --file=- <<'SQL'
20+
DO $$
1621
DECLARE
17-
result boolean;
22+
result record;
1823
BEGIN
19-
SELECT 1 from pg_roles where rolname='ccp_monitoring' INTO result;
20-
ASSERT result = 't', 'ccp_monitor not found';
21-
END \$\$;"
24+
SELECT * INTO result FROM pg_catalog.pg_roles WHERE rolname = 'ccp_monitoring';
25+
ASSERT FOUND, 'user not found';
26+
ASSERT result.rolconfig @> '{jit=off}', format('got config: %L', result.rolconfig);
27+
END $$
28+
SQL

0 commit comments

Comments
 (0)