Skip to content

Commit

Permalink
Sync docs from Discourse (#414)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] authored Oct 7, 2024
1 parent 425b197 commit 6a4a868
Show file tree
Hide file tree
Showing 6 changed files with 297 additions and 64 deletions.
59 changes: 59 additions & 0 deletions docs/explanation/e-events-hooks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Events and hooks

Detailed information about the charm's internal behaviour can be found in the charm's [GitHub wiki](https://github.com/canonical/pgbouncer-k8s-operator/wiki).

It includes flowcharts of events in the charm's lifecycle, examples of the expected interface resulting from relations (databag contents), and hook flowcharts:

* **Main file:** [**`charm.py`**][charm.py]
* [Event flowcharts]
* [Charm startup]
* [Config updates]
* [Leader updates]
* [Hook handler flowcharts]
* [`start`]
* [`pgbouncer-pebble-ready`]
* [`config-changed`]
* [`update-status`]
* **Relations**
* [**`backend_database`**][backend_database relation]
* [Example databag contents][backend_database example]
* [Hook handler flowcharts][backend_database hooks]
* [**`database`**][database relation]
* [Example databag contents][database example]
* [Hook handler flowcharts][database hooks]
* [**`db` and `db-admin`**][db and db-admin relations]
* [Example databag contents][db example]
* [Hook handler flowcharts][db hooks]
* [**`pgb-peers`**][pgb-peers relation]
* [Example databag contents][pgb-peers example]
* [Hook handler flowcharts][pgb-peers hooks]

<!-- LINKS -->
[charm.py]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/charm.py

[backend_database relation]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/backend_database-relation
[backend_database example]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/backend_database-relation#expected-interface
[backend_database hooks]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/backend_database-relation#hook-handler-flowcharts

[database relation]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/database-relation
[database example]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/database-relation#expected-interface
[database hooks]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/database-relation#hook-handler-flowcharts

[db and db-admin relations]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/db-and-db%E2%80%90admin-relations
[db example]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/db-and-db%E2%80%90admin-relations#expected-interface
[db hooks]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/db-and-db%E2%80%90admin-relations#hook-handler-flowcharts

[pgb-peers relation]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/pgb%E2%80%90peers-relation
[pgb-peers example]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/pgb%E2%80%90peers-relation#expected-interface
[pgb-peers hooks]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/pgb%E2%80%90peers-relation#hook-handler-flowcharts

[Event flowcharts]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/charm.py#event-flow
[Charm startup]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/charm.py#charm-startup
[Config updates]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/charm.py#config-updates
[Leader updates]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/charm.py#leader-updates

[Hook handler flowcharts]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/charm.py#hook-handler-flowcharts
[`start`]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/charm.py#start-hook
[`pgbouncer-pebble-ready`]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/charm.py#pgbouncer-pebble-ready-hook
[`config-changed`]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/charm.py#config-changed-hook
[`update-status`]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/charm.py#update-status-hook
83 changes: 41 additions & 42 deletions docs/how-to/h-enable-tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ This guide contains the steps to enable tracing with [Grafana Tempo](https://gra

To summarize:
* [Deploy the Tempo charm in a COS K8s environment](#heading--deploy)
* [Integrate it with the COS charms](#heading--integrate)
* [Offer interfaces for cross-model integrations](#heading--offer)
* [Consume and integrate cross-model integrations](#heading--consume)
* [View PgBouncer K8s traces on Grafana](#heading--view)


Expand All @@ -33,35 +33,17 @@ Enabling tracing with Tempo requires that you:
<a href="#heading--deploy"><h2 id="heading--deploy"> Deploy Tempo </h2></a>

First, switch to the Kubernetes controller where the COS model is deployed:

```shell
juju switch <k8s_controller_name>:<cos_model_name>
```
Then, deploy the [`tempo-k8s`](https://charmhub.io/tempo-k8s) charm:
```shell
juju deploy -n 1 tempo-k8s --channel latest/edge
```

<a href="#heading--integrate"><h2 id="heading--integrate"> Integrate with the COS charms </h2></a>

Integrate `tempo-k8s` with the COS charms as follows:
Then, deploy the dependencies of Tempo by following [this tutorial](https://discourse.charmhub.io/t/tutorial-deploy-tempo-ha-on-top-of-cos-lite/15489). In particular, we would want to:
- Deploy the minio charm
- Deploy the s3 integrator charm
- Add a bucket in minio using a python script
- Configure s3 integrator with the minio credentials

```shell
juju integrate tempo-k8s:grafana-dashboard grafana:grafana-dashboard
juju integrate tempo-k8s:grafana-source grafana:grafana-source
juju integrate tempo-k8s:ingress traefik:traefik-route
juju integrate tempo-k8s:metrics-endpoint prometheus:metrics-endpoint
juju integrate tempo-k8s:logging loki:logging
```
If you would like to instrument traces from the COS charms as well, create the following integrations:
```shell
juju integrate tempo-k8s:tracing alertmanager:tracing
juju integrate tempo-k8s:tracing catalogue:tracing
juju integrate tempo-k8s:tracing grafana:tracing
juju integrate tempo-k8s:tracing loki:tracing
juju integrate tempo-k8s:tracing prometheus:tracing
juju integrate tempo-k8s:tracing traefik:tracing
```
Finally, deploy and integrate with Tempo HA in [a monolithic setup](https://discourse.charmhub.io/t/tutorial-deploy-tempo-ha-on-top-of-cos-lite/15489#heading--deploy-monolithic-setup).

<a href="#heading--offer"><h2 id="heading--offer"> Offer interfaces </h2></a>

Expand All @@ -70,7 +52,7 @@ Next, offer interfaces for cross-model integrations from the model where Charmed
To offer the Tempo integration, run

```shell
juju offer tempo-k8s:tracing
juju offer <tempo_coordinator_k8s_application_name>:tracing
```

Then, switch to the Charmed PgBouncer K8s model, find the offers, and integrate (relate) with them:
Expand All @@ -86,50 +68,67 @@ Below is a sample output where `k8s` is the K8s controller name and `cos` is the

```shell
Store URL Access Interfaces
k8s admin/cos.tempo-k8s admin tracing:tracing
k8s admin/cos.tempo admin tracing:tracing
```

Next, consume this offer so that it is reachable from the current model:

```shell
juju consume k8s:admin/cos.tempo-k8s
juju consume k8s:admin/cos.tempo
```

<a href="#heading--consume"><h2 id="heading--consume"> Consume interfaces </h2></a>

Relate Charmed PgBouncer K8s with the above consumed interface:

First, dpeloy [Grafana Agent K8s](https://charmhub.io/grafana-agent-k8s) from the `latest/edge` channel:
```shell
juju deploy grafana-agent-k8s --channel latest/edge
```

Then, integrate Grafana Agent K8s with the consumed interface from the previous section:
```shell
juju integrate grafana-agent-k8s:tracing tempo:tracing
```

Finally, integrate Charmed PgBouncer K8s with Grafana Agent K8s:
```shell
juju integrate pgbouncer-k8s:tracing tempo-k8s:tracing
juju integrate pgbouncer-k8s:tracing grafana-agent-k8s:tracing-provider
```

Wait until the model settles. The following is an example of the `juju status --relations` on the Charmed PgBouncer K8s model:

```shell
Model Controller Cloud/Region Version SLA Timestamp
database uk8s microk8s/localhost 3.4.3 unsupported 19:00:48Z
database k8s microk8s/localhost 3.5.4 unsupported 18:12:15Z

SAAS Status Store URL
tempo-k8s active uk8s admin/cos.tempo-k8s
SAAS Status Store URL
tempo active k8s admin/cos.tempo

App Version Status Scale Charm Channel Rev Address Exposed Message
pgbouncer-k8s 1.21.0 active 1 pgbouncer-k8s 1/edge 196 10.152.183.140 no
postgresql-k8s 14.12 active 1 postgresql-k8s 14/edge 315 10.152.183.28 no
postgresql-test-app active 1 postgresql-test-app latest/edge 176 10.152.183.204 no received database credentials of the first database
App Version Status Scale Charm Channel Rev Address Exposed Message
grafana-agent-k8s 0.40.4 active 1 grafana-agent-k8s latest/edge 93 10.152.183.52 no grafana-dashboards-provider: off, logging-consumer: off, send-remote-write: off
pgbouncer-k8s 1.21.0 active 1 pgbouncer-k8s 0 10.152.183.202 no
postgresql-k8s 14.13 active 1 postgresql-k8s 14/edge 410 10.152.183.168 no
postgresql-test-app active 1 postgresql-test-app latest/stable 211 10.152.183.174 no received database credentials of the first database

Unit Workload Agent Address Ports Message
pgbouncer-k8s/0* active idle 10.1.241.198
postgresql-k8s/0* active idle 10.1.241.220 Primary
postgresql-test-app/0* active idle 10.1.241.200 received database credentials of the first database
grafana-agent-k8s/0* active idle 10.1.241.205 grafana-dashboards-provider: off, logging-consumer: off, send-remote-write: off
pgbouncer-k8s/0* active idle 10.1.241.202
postgresql-k8s/0* active idle 10.1.241.204 Primary
postgresql-test-app/0* active idle 10.1.241.203 received database credentials of the first database

Integration provider Requirer Interface Type Message
pgbouncer-k8s:database postgresql-test-app:first-database postgresql_client regular
grafana-agent-k8s:peers grafana-agent-k8s:peers grafana_agent_replica peer
grafana-agent-k8s:tracing-provider pgbouncer-k8s:tracing tracing regular
pgbouncer-k8s:database postgresql-test-app:database postgresql_client regular
pgbouncer-k8s:pgb-peers pgbouncer-k8s:pgb-peers pgb_peers peer
pgbouncer-k8s:upgrade pgbouncer-k8s:upgrade upgrade peer
postgresql-k8s:database pgbouncer-k8s:backend-database postgresql_client regular
postgresql-k8s:database-peers postgresql-k8s:database-peers postgresql_peers peer
postgresql-k8s:restart postgresql-k8s:restart rolling_op peer
postgresql-k8s:upgrade postgresql-k8s:upgrade upgrade peer
postgresql-test-app:postgresql-test-peers postgresql-test-app:postgresql-test-peers postgresql-test-peers peer
tempo-k8s:tracing pgbouncer-k8s:tracing tracing regular
tempo:tracing grafana-agent-k8s:tracing tracing regular

```

Expand All @@ -145,4 +144,4 @@ Below is a screenshot demonstrating a Charmed PgBouncer K8s trace:

![Example PgBouncer K8s trace with Grafana Tempo|690x381](upload://2g5ynYhu1uPX7E8Xi33qkT3p2s9.png)

Feel free to read through the [Tempo documentation](https://discourse.charmhub.io/t/tempo-k8s-docs-index/14005) at your leisure to explore its deployment and its integrations.
Feel free to read through the [Tempo HA documentation](https://discourse.charmhub.io/t/charmed-tempo-ha/15531) at your leisure to explore its deployment and its integrations.
91 changes: 91 additions & 0 deletions docs/how-to/h-external-k8s-connection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# External K8s connection

To make the Charmed PostgreSQL K8s database reachable from outside the Kubernetes cluster, this charm PgBouncer K8s should be deployed. It creates and manages several K8s services including the NodePort one:

```shell
kubectl get services -n <model>
```

```
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
...
pgbouncer-k8s ClusterIP 10.152.183.48 <none> 65535/TCP 20m
pgbouncer-k8s-endpoints ClusterIP None <none> <none> 20m
pgbouncer-k8s-nodeport NodePort 10.152.183.116 <none> 6432:30288/TCP 20m
...
```

The `pgbouncer-k8s-nodeport` NodePort service exposes a port to access both R/W and R/O PostgreSQL servers from outside of K8s. The charm opens NodePort if requested in relation as `external-node-connectivity: true`. Example (relate pgbouncer-k8s with data-integrator):
```shell
> juju run data-integrator/0 get-credentials
...
postgresql:
data: '{"database": "test123", "external-node-connectivity": "true", "requested-secrets":
"[\"username\", \"password\", \"tls\", \"tls-ca\", \"uris\"]"}'
database: test123
endpoints: 10.76.203.225:30288
password: lJPIjF04GCPYptiR2k1f4NUt
read-only-endpoints: 10.76.203.225:30288
uris: postgresql://relation_id_22:[email protected]:30288/test123
username: relation_id_22
version: "14.13"
```
> **Note**: the relation flag `external-node-connectivity` is experimental and will be replaced in the future. Follow https://warthogs.atlassian.net/browse/DPE-5636 for more details.
> **Note**: The `pgbouncer-k8s` and `pgbouncer-k8s-endpoints` ClusterIP services seen above are created for every Juju application by default as part of the StatefulSet they are associated with. These services are not relevant to users and can be safely ignored.
## Client connections using the bootstrap service

A client can be configured to connect to the `pgbouncer-k8s-nodeport` service using a Kubernetes NodeIP, and desired NodePort.

To get NodeIPs:

```shell
kubectl get nodes -o wide -n model | awk -v OFS='\t\t' '{print $1, $6}'
```

```
NAME INTERNAL-IP
node-0 10.155.67.110
node-1 10.155.67.120
node-2 10.155.67.130
```

NodeIPs are different for each deployment as they are randomly allocated.
For the example from the previous section, the created NodePorts was:

```shell
6432:30288/TCP
```

Users can use this NodePort to access read-write / Primary server from outside of K8s:
```shell
> psql postgresql://relation_id_22:[email protected]:30288/test123
...

test123=> create table A (id int);
CREATE TABLE

test123=> \d
List of relations
Schema | Name | Type | Owner
--------+------+-------+----------------
public | a | table | relation_id_22
(1 row)
...
```
Read-only servers can be accessed using the `_readonly` suffix to the desired DB name:
```shell
> psql postgresql://relation_id_22:[email protected]:30288/test123_readonly
...

test123_readonly=> create table B (id int);
ERROR: cannot execute CREATE TABLE in a read-only transaction

test123_readonly=> \d
List of relations
Schema | Name | Type | Owner
--------+------+-------+----------------
public | a | table | relation_id_22
(1 row)
```
10 changes: 5 additions & 5 deletions docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ This PgBouncer K8s charm is an official distribution of PgBouncer. It’s an ope
| 2 | t-managing-units | [4. Manage units](/t/12254) |
| 2 | t-enable-security | [5. Enable security](/t/12255) |
| 2 | t-cleanup-environment | [6. Clean up environment](/t/12256) |
| 1 | how-to | [How To]() |
| 1 | how-to | [How to]() |
| 2 | h-setup | [Setup]() |
| 3 | h-deploy-microk8s | [Deploy on MicroK8s](/t/12257) |
| 3 | h-manage-units | [Manage units](/t/12258) |
| 3 | h-enable-encryption | [Enable encryption](/t/12259) |
| 3 | h-manage-app | [Manage applications](/t/12260) |
| 3 | h-external-k8s-connection | [External k8s connection](/t/15694) |
| 2 | h-upgrade | [Upgrade]() |
| 3 | h-upgrade-intro | [Intro](/t/12267) |
| 3 | h-upgrade-major | [Major upgrade](/t/12268) |
Expand All @@ -53,22 +54,21 @@ This PgBouncer K8s charm is an official distribution of PgBouncer. It’s an ope
| 3 | h-enable-monitoring | [Monitor (COS)](/t/12279) |
| 3 | h-enable-tracing | [Tracing (COS)](/t/14789) |
| 1 | reference | [Reference]() |
| 2 | r-releases-group | [Release Notes]() |
| 3 | r-releases | [All releases](/t/12261) |
| 2 | r-releases | [Release Notes](/t/12261) |
| 3 | r-revision-268-269 | [Revision 268/269](/t/15443) |
| 3 | r-revision-228-229 | [Revision 228/229](/t/15090) |
| 3 | r-revision-144 | [Revision 144/145](/t/14070) |
| 3 | r-revision-103 | [Revision 103](/t/13297) |
| 3 | r-revision-81 | [Revision 81](/t/12751) |
| 3 | r-revision-76 | [Revision 76](/t/12262) |
| 2 | r-requirements | [Requirements](/t/12263) |
| 2 | r-contributing | [Contributing](https://github.com/canonical/pgbouncer-k8s-operator/blob/main/CONTRIBUTING.md) |
| 2 | r-testing | [Testing](/t/12272) |
| 2 | r-contacts | [Contacts](/t/12264) |
| 1 | explanation | [Explanation]() |
| 2 | e-juju-details | [Juju](/t/12274) |
| 2 | e-interfaces | [Interfaces/endpoints](/t/12265) |
| 2 | e-statuses | [Statuses](/t/12266) |
| 2 | e-juju-details | [Juju](/t/12274) |
| 2 | e-events-hooks | [Events and hooks](/t/15662) |

[/details]

Expand Down
Loading

0 comments on commit 6a4a868

Please sign in to comment.