-
Notifications
You must be signed in to change notification settings - Fork 637
Fix for PGO-2380: #4163
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
Merged
dsessler7
merged 2 commits into
CrunchyData:main
from
dsessler7:fix-otel-without-backups-bug
Apr 25, 2025
Merged
Fix for PGO-2380: #4163
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestStep | ||
| apply: | ||
| - files/05--annotate-cluster.yaml | ||
| assert: | ||
| - files/05-backup-completed.yaml |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
6 changes: 6 additions & 0 deletions
6
testing/kuttl/e2e/otel-logging-and-metrics/07--add-instrumentation-to-pgadmin.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestStep | ||
| apply: | ||
| - files/07--add-instrumentation.yaml | ||
| assert: | ||
| - files/07-instrumentation-added.yaml |
6 changes: 0 additions & 6 deletions
6
testing/kuttl/e2e/otel-logging-and-metrics/08--add-custom-queries.yaml
This file was deleted.
Oops, something went wrong.
File renamed without changes.
6 changes: 6 additions & 0 deletions
6
testing/kuttl/e2e/otel-logging-and-metrics/09--add-custom-queries.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestStep | ||
| apply: | ||
| - files/09--add-custom-queries.yaml | ||
| assert: | ||
| - files/09-custom-queries-added.yaml |
6 changes: 0 additions & 6 deletions
6
testing/kuttl/e2e/otel-logging-and-metrics/10--add-logs-exporter.yaml
This file was deleted.
Oops, something went wrong.
File renamed without changes.
6 changes: 6 additions & 0 deletions
6
testing/kuttl/e2e/otel-logging-and-metrics/11--add-logs-exporter.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestStep | ||
| apply: | ||
| - files/11--add-logs-exporter.yaml | ||
| assert: | ||
| - files/11-logs-exporter-added.yaml |
File renamed without changes.
6 changes: 6 additions & 0 deletions
6
testing/kuttl/e2e/otel-logging-and-metrics/13--cluster-no-backups.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestStep | ||
| apply: | ||
| - files/13--create-cluster.yaml | ||
| assert: | ||
| - files/13-cluster-created.yaml |
55 changes: 55 additions & 0 deletions
55
testing/kuttl/e2e/otel-logging-and-metrics/14-assert-instance.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestAssert | ||
| commands: | ||
| # First, check that all containers in the instance pod are ready. | ||
| # Then, grab the collector metrics output and check that a postgres | ||
| # metric is present, as well as a patroni metric. | ||
| # Then, check the collector logs for patroni, and postgres logs. | ||
| # Finally, ensure the monitoring user exists and is configured. | ||
| - script: | | ||
| retry() { bash -ceu 'printf "$1\nSleeping...\n" && sleep 5' - "$@"; } | ||
| check_containers_ready() { bash -ceu 'echo "$1" | jq -e ".[] | select(.type==\"ContainersReady\") | .status==\"True\""' - "$@"; } | ||
| contains() { bash -ceu '[[ "$1" == *"$2"* ]]' - "$@"; } | ||
|
|
||
| pod=$(kubectl get pods -o name -n "${NAMESPACE}" \ | ||
| -l postgres-operator.crunchydata.com/cluster=otel-cluster-no-backups,postgres-operator.crunchydata.com/data=postgres) | ||
| [ "$pod" = "" ] && retry "Pod not found" && exit 1 | ||
|
|
||
| condition_json=$(kubectl get "${pod}" -n "${NAMESPACE}" -o jsonpath="{.status.conditions}") | ||
| [ "$condition_json" = "" ] && retry "conditions not found" && exit 1 | ||
| { check_containers_ready "$condition_json"; } || { | ||
| retry "containers not ready" | ||
| exit 1 | ||
| } | ||
|
|
||
| scrape_metrics=$(kubectl exec "${pod}" -c collector -n "${NAMESPACE}" -- \ | ||
| curl --insecure --silent http://localhost:9187/metrics) | ||
| { contains "${scrape_metrics}" 'ccp_connection_stats_active'; } || { | ||
| retry "5 second metric not found" | ||
| exit 1 | ||
| } | ||
| { contains "${scrape_metrics}" 'patroni_postgres_running'; } || { | ||
| retry "patroni metric not found" | ||
| exit 1 | ||
| } | ||
|
|
||
| logs=$(kubectl logs "${pod}" --namespace "${NAMESPACE}" -c collector | grep InstrumentationScope) | ||
| { contains "${logs}" 'InstrumentationScope patroni'; } || { | ||
| retry "patroni logs not found" | ||
| exit 1 | ||
| } | ||
| { contains "${logs}" 'InstrumentationScope postgres'; } || { | ||
| retry "postgres logs not found" | ||
| exit 1 | ||
| } | ||
|
|
||
| kubectl exec --stdin "${pod}" --namespace "${NAMESPACE}" -c database \ | ||
| -- psql -qb --set ON_ERROR_STOP=1 --file=- <<'SQL' | ||
| DO $$ | ||
| DECLARE | ||
| result record; | ||
| BEGIN | ||
| SELECT * INTO result FROM pg_catalog.pg_roles WHERE rolname = 'ccp_monitoring'; | ||
| ASSERT FOUND, 'user not found'; | ||
| END $$ | ||
| SQL |
6 changes: 6 additions & 0 deletions
6
testing/kuttl/e2e/otel-logging-and-metrics/15--cluster-add-backups.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestStep | ||
| apply: | ||
| - files/15--add-backups.yaml | ||
| assert: | ||
| - files/15-backups-added.yaml |
6 changes: 6 additions & 0 deletions
6
testing/kuttl/e2e/otel-logging-and-metrics/16--remove-backups.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestStep | ||
| commands: | ||
| - command: |- | ||
| kubectl patch postgrescluster otel-cluster-no-backups --type 'merge' -p '{"spec":{"backups": null}}' | ||
| namespaced: true |
7 changes: 7 additions & 0 deletions
7
testing/kuttl/e2e/otel-logging-and-metrics/17--annotate-cluster.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestStep | ||
| commands: | ||
| - command: kubectl annotate postgrescluster otel-cluster-no-backups postgres-operator.crunchydata.com/authorizeBackupRemoval="true" | ||
| namespaced: true | ||
| assert: | ||
| - files/17-backups-removed.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions
26
testing/kuttl/e2e/otel-logging-and-metrics/files/07--add-instrumentation.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| --- | ||
| apiVersion: postgres-operator.crunchydata.com/v1beta1 | ||
| kind: PGAdmin | ||
| metadata: | ||
| name: otel-pgadmin | ||
| spec: | ||
| users: | ||
| - username: otel@example.com | ||
| role: Administrator | ||
| passwordRef: | ||
| name: pgadmin-password-secret | ||
| key: otel-password | ||
| dataVolumeClaimSpec: | ||
| accessModes: | ||
| - "ReadWriteOnce" | ||
| resources: | ||
| requests: | ||
| storage: 1Gi | ||
| serverGroups: | ||
| - name: supply | ||
| # An empty selector selects all postgresclusters in the Namespace | ||
| postgresClusterSelector: {} | ||
| config: | ||
| settings: | ||
| AUTHENTICATION_SOURCES: ['internal'] | ||
| instrumentation: {} |
120 changes: 120 additions & 0 deletions
120
testing/kuttl/e2e/otel-logging-and-metrics/files/07-instrumentation-added.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| apiVersion: postgres-operator.crunchydata.com/v1beta1 | ||
| kind: PostgresCluster | ||
| metadata: | ||
| name: otel-cluster | ||
| status: | ||
| instances: | ||
| - name: instance1 | ||
| readyReplicas: 1 | ||
| replicas: 1 | ||
| updatedReplicas: 1 | ||
| proxy: | ||
| pgBouncer: | ||
| readyReplicas: 1 | ||
| replicas: 1 | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| labels: | ||
| postgres-operator.crunchydata.com/data: postgres | ||
| postgres-operator.crunchydata.com/role: master | ||
| postgres-operator.crunchydata.com/cluster: otel-cluster | ||
| postgres-operator.crunchydata.com/crunchy-otel-collector: "true" | ||
| status: | ||
| containerStatuses: | ||
| - name: collector | ||
| ready: true | ||
| started: true | ||
| - name: database | ||
| ready: true | ||
| started: true | ||
| - name: pgbackrest | ||
| ready: true | ||
| started: true | ||
| - name: pgbackrest-config | ||
| ready: true | ||
| started: true | ||
| - name: replication-cert-copy | ||
| ready: true | ||
| started: true | ||
| phase: Running | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| labels: | ||
| postgres-operator.crunchydata.com/data: pgbackrest | ||
| postgres-operator.crunchydata.com/cluster: otel-cluster | ||
| postgres-operator.crunchydata.com/crunchy-otel-collector: "true" | ||
| status: | ||
| containerStatuses: | ||
| - name: collector | ||
| ready: true | ||
| started: true | ||
| - name: pgbackrest | ||
| ready: true | ||
| started: true | ||
| - name: pgbackrest-config | ||
| ready: true | ||
| started: true | ||
| phase: Running | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| labels: | ||
| postgres-operator.crunchydata.com/role: pgbouncer | ||
| postgres-operator.crunchydata.com/cluster: otel-cluster | ||
| postgres-operator.crunchydata.com/crunchy-otel-collector: "true" | ||
| status: | ||
| containerStatuses: | ||
| - name: collector | ||
| ready: true | ||
| started: true | ||
| - name: pgbouncer | ||
| ready: true | ||
| started: true | ||
| - name: pgbouncer-config | ||
| ready: true | ||
| started: true | ||
| phase: Running | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: otel-cluster-primary | ||
| --- | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| labels: | ||
| postgres-operator.crunchydata.com/role: pgadmin | ||
| postgres-operator.crunchydata.com/pgadmin: otel-pgadmin | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| labels: | ||
| postgres-operator.crunchydata.com/data: pgadmin | ||
| postgres-operator.crunchydata.com/role: pgadmin | ||
| postgres-operator.crunchydata.com/pgadmin: otel-pgadmin | ||
| postgres-operator.crunchydata.com/crunchy-otel-collector: "true" | ||
| status: | ||
| containerStatuses: | ||
| - name: collector | ||
| ready: true | ||
| started: true | ||
| - name: pgadmin | ||
| ready: true | ||
| started: true | ||
| phase: Running | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Secret | ||
| metadata: | ||
| labels: | ||
| postgres-operator.crunchydata.com/role: pgadmin | ||
| postgres-operator.crunchydata.com/pgadmin: otel-pgadmin | ||
| type: Opaque | ||
| --- |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
testing/kuttl/e2e/otel-logging-and-metrics/files/13--create-cluster.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| --- | ||
| apiVersion: postgres-operator.crunchydata.com/v1beta1 | ||
| kind: PostgresCluster | ||
| metadata: | ||
| name: otel-cluster-no-backups | ||
| spec: | ||
| postgresVersion: ${KUTTL_PG_VERSION} | ||
| instances: | ||
| - name: instance1 | ||
| dataVolumeClaimSpec: | ||
| accessModes: | ||
| - "ReadWriteOnce" | ||
| resources: | ||
| requests: | ||
| storage: 1Gi | ||
| instrumentation: {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am curious -- if you skip steps 3 and 4, will 5 fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow... If you don't remove the backups spec and annotate the cluster, pgbackrest will just continue to run (in the instance pod and repo-host)...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right -- I'm wondering if step 5 tests what we want it to test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, first we create a brand new cluster that does not have backups enabled. And we make sure that the collector runs in that scenario. Then we add backups and ensure that everything works properly with that transition. Then we remove backups and ensure that everything works properly with that transition... What scenario do you think we aren't testing? Or what is it about the test that is insufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's been a while since I did a KUTTL test, but I remember running into issues where I asserted that X existed, but it actually ignored what wasn't X. So here, we assert there's a few containers, but not the collector container -- but will it fail if that collector container does exist? Or will it just skip that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, I think I understand now... In the assert step we tell it to check the instance pod for specific containers and it will fail if the list is not exactly correct (if we ask about 3 containers, but there are actually 5 containers that include the 3 we ask about, it will fail).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, it checks if the list (of containers, etc.) is complete still? I think we (and others) were pushing to get it to check only for the presence of the items in the list.