diff --git a/docs/docs/deployment-self-hosting/core-configuration/environment-variables.md b/docs/docs/deployment-self-hosting/core-configuration/environment-variables.md index b995f50b76a9..51c0e63d2e44 100644 --- a/docs/docs/deployment-self-hosting/core-configuration/environment-variables.md +++ b/docs/docs/deployment-self-hosting/core-configuration/environment-variables.md @@ -48,8 +48,8 @@ relevant section below for more details. - `INFLUXDB_TOKEN`: If you want to send API events to InfluxDB, specify this write token. - `INFLUXDB_URL`: The URL for your InfluxDB database. - `INFLUXDB_ORG`: The organisation string for your InfluxDB API call. -- `EXPERIMENTATION_ENABLED`: Set to `true` once the experimentation infra is deployed. Experiments and warehouse - connections stay unavailable until it is. Defaults to `false`. +- `EXPERIMENTATION_ENABLED`: Set to `true` to turn on experiments and warehouse connections. Defaults to `false`. See + [Self-Hosting and Open Source](/experimentation/self-hosting). - `WAREHOUSE_CREDENTIALS_SECRET`: Secret used to encrypt warehouse connection credentials. Warehouse delivery must use the same value. Changing it makes saved credentials unreadable. - `GA_TABLE_ID`: GA table ID (view) to query when looking for organisation usage. diff --git a/docs/docs/deployment-self-hosting/hosting-guides/kubernetes-openshift.md b/docs/docs/deployment-self-hosting/hosting-guides/kubernetes-openshift.md index d4547e169744..598ff7527aaf 100644 --- a/docs/docs/deployment-self-hosting/hosting-guides/kubernetes-openshift.md +++ b/docs/docs/deployment-self-hosting/hosting-guides/kubernetes-openshift.md @@ -394,7 +394,8 @@ The task processor itself is documented [here](/deployment-self-hosting/scaling- ### Experimentation The chart can run [experimentation](/experimentation). You bring your own Kafka and data warehouse, and each -environment's events are delivered to the warehouse connected to it. The chart then: +environment's events are delivered to the warehouse connected to it. To evaluate experimentation without deploying +this, see [Self-Hosting and Open Source](/experimentation/self-hosting). The chart then: - Runs the event ingestion service, which receives SDK events and writes them to a Kafka topic. - Runs warehouse delivery, which reads that topic and inserts each environment's events into its warehouse. diff --git a/docs/docs/experimentation/connect-a-warehouse.md b/docs/docs/experimentation/connect-a-warehouse.md index 56a92cc19319..4fb6e7b53cd6 100644 --- a/docs/docs/experimentation/connect-a-warehouse.md +++ b/docs/docs/experimentation/connect-a-warehouse.md @@ -2,8 +2,7 @@ title: Connect a Warehouse sidebar_label: Connect a Warehouse sidebar_position: 2 -description: - Choose where experiment events are stored, the managed Flagsmith warehouse or your own ClickHouse or Databricks. +description: Choose where experiment events are stored, from the managed Flagsmith warehouse to your own database. --- import CodeBlock from '@theme/CodeBlock'; import eventsSql from '../../../experimentation/clickhouse/events.sql?raw'; @@ -19,15 +18,14 @@ warehouse connection, and it must be in place before you can create experiments. :::note Self-hosted -The managed Flagsmith warehouse is only available on Flagsmith Cloud. When self-hosting, connect your own warehouse as -described below, and deploy event ingestion and warehouse delivery, for example with the -[Helm chart](/deployment-self-hosting/hosting-guides/kubernetes-openshift#experimentation). +The managed Flagsmith warehouse is only available on Flagsmith Cloud. When self-hosting, see +[Self-Hosting and Open Source](/experimentation/self-hosting). ::: :::note Plans -On Flagsmith Cloud, connecting your own ClickHouse or Databricks requires a +On Flagsmith Cloud, connecting your own ClickHouse, Databricks or PostgreSQL requires a [Scale-Up or Enterprise subscription](https://www.flagsmith.com/pricing). Self-hosted Flagsmith has no plan restriction. ::: @@ -36,7 +34,7 @@ On Flagsmith Cloud, connecting your own ClickHouse or Databricks requires a The **Flagsmith** warehouse is managed and hosted by Flagsmith. There is nothing to provision or configure. -1. Go to **Environment Settings > Warehouse**. +1. Go to **Environment Settings › Warehouse**. 2. Select **Flagsmith** and click **Enable**, then confirm. ![The Warehouse tab with the Flagsmith managed warehouse selected](/img/experimentation/warehouse-tab.png) @@ -56,17 +54,16 @@ Warehouse tab open. Once connected, the warehouse card shows the total number of events received and the number of unique event names, which is useful to verify that instrumentation data is arriving. - - ### Connection statuses -The current status is shown on the warehouse card in **Environment Settings > Warehouse**. +The current status is shown on the warehouse card in **Environment Settings › Warehouse**. - **Created**: the connection exists but no events have been received yet. - **Pending Connection**: waiting for the first event to arrive. - **Connected**: events have been received; you are ready to run experiments. -- **Errored**: the card shows the reason. For Databricks, see - [Troubleshooting](/experimentation/connect-databricks#troubleshooting); otherwise [contact support](/support/). +- **Errored**: the card shows the reason. See Troubleshooting for + [Databricks](/experimentation/connect-databricks#troubleshooting) or + [PostgreSQL](/experimentation/connect-postgresql#troubleshooting); otherwise [contact support](/support/). ## Bring your own ClickHouse @@ -75,15 +72,15 @@ be reachable from Flagsmith: on Flagsmith Cloud, over the internet; when self-ho warehouse delivery. 1. Configure your instance by running the following against it, using an administrative user (the statements require - `CREATE USER`, `GRANT`, `CREATE DATABASE` and `CREATE TABLE` privileges). Replace `` and `` - with your own values. This is a one-off setup step; the same SQL is available to copy from the Flagsmith dashboard. + `CREATE USER`, `GRANT`, `CREATE DATABASE` and `CREATE TABLE` privileges). Replace `` and `` with + your own values. This is a one-off setup step; the same SQL is available to copy from the Flagsmith dashboard. {eventsSql} ```sql -- Create a dedicated user for Flagsmith CREATE USER IF NOT EXISTS - IDENTIFIED WITH sha256_password BY ''; + IDENTIFIED WITH sha256_password BY ''; -- Allow it to write and read experiment events GRANT SELECT, INSERT ON flagsmith_exp.events TO ; @@ -92,12 +89,12 @@ warehouse delivery. GRANT SHOW TABLES, SHOW COLUMNS ON flagsmith_exp.* TO ; ``` -2. Go to **Environment Settings > Warehouse**, select **ClickHouse** and enter your connection details: host, HTTPS port +2. Go to **Environment Settings › Warehouse**, select **ClickHouse** and enter your connection details: host, HTTPS port (8443 by default), database (`flagsmith_exp` by default), and the username and password of the user you created in step 1. 3. Click **Test connection**. Once the test succeeds, save the connection. -4. Click **Send your first event** on the connection card to verify events are arriving in your warehouse; the button - disappears once the first event is received. +4. On Flagsmith Cloud, click **Send your first event** on the connection card to verify events are arriving in your + warehouse; the button disappears once the first event is received. Connections use the ClickHouse HTTP(S) interface, with TLS enabled by default. @@ -108,6 +105,11 @@ Experiment results and exposures are computed from your ClickHouse instance. You can also store experiment events in your own **Databricks** workspace, and Flagsmith computes results there. See [Connect Databricks](/experimentation/connect-databricks) for setup and troubleshooting. +## Bring your own PostgreSQL + +You can store experiment events in your own **PostgreSQL** database, or a PostgreSQL-compatible service, and Flagsmith +computes results there. See [Connect PostgreSQL](/experimentation/connect-postgresql) for setup and troubleshooting. + ## Coming soon Bring your own warehouse: connections for **Snowflake** and **BigQuery**. diff --git a/docs/docs/experimentation/connect-databricks.md b/docs/docs/experimentation/connect-databricks.md index d9c2dd185546..0bb59becc62c 100644 --- a/docs/docs/experimentation/connect-databricks.md +++ b/docs/docs/experimentation/connect-databricks.md @@ -107,8 +107,8 @@ storage works; you don't need an external location. If the test fails, you can save anyway and test again later, but events won't be delivered until it succeeds. -5. The connection shows **Connected** once the test succeeds. To verify events reach your table, click **Send your first - event** on the connection card; the button disappears once the first event arrives. +5. The connection shows **Connected** once the test succeeds. On Flagsmith Cloud, to verify events reach your table, + click **Send your first event** on the connection card; the button disappears once the first event arrives. ![A connected Databricks warehouse card showing the last event received, total events and unique event names](/img/experimentation/warehouse-databricks-connected.png) diff --git a/docs/docs/experimentation/connect-postgresql.md b/docs/docs/experimentation/connect-postgresql.md new file mode 100644 index 000000000000..78a34bc8e853 --- /dev/null +++ b/docs/docs/experimentation/connect-postgresql.md @@ -0,0 +1,129 @@ +--- +title: Connect PostgreSQL +sidebar_label: Connect PostgreSQL +sidebar_position: 2.7 +description: Store and query experiment events in your own PostgreSQL database. +--- + +:::info Beta + +Experimentation is in beta. + +::: + +Flagsmith writes experiment events to a table in your PostgreSQL database and computes experiment results by querying it +there. Each environment has one [warehouse connection](/experimentation/connect-a-warehouse). + +Results queries slow down as the events table grows. See [Performance and table growth](#performance-and-table-growth). + +## Before you start + +- On Flagsmith Cloud, a [Scale-Up or Enterprise subscription](https://www.flagsmith.com/pricing). +- A database reachable from Flagsmith: on Flagsmith Cloud, over the internet; when self-hosting, from your Flagsmith API + and warehouse delivery. On Flagsmith Cloud, servers restricted by IP allowlists aren't currently supported. +- A superuser, or a role with `CREATEROLE` and `CREATE` on the database, to run the setup SQL. +- When self-hosting, the event ingestion service, Kafka and warehouse delivery. See + [Self-Hosting and Open Source](/experimentation/self-hosting). + +PostgreSQL-compatible services such as Amazon RDS and Aurora, Cloud SQL, AlloyDB, Supabase and Neon also work. + +## 1. Create the events table and user + +Run this once against your database. Replace `` and `` with your own values. The same SQL is +available to copy from the Flagsmith dashboard. + +```sql +-- Create the schema and events table +CREATE SCHEMA IF NOT EXISTS flagsmith_exp; +CREATE TABLE IF NOT EXISTS flagsmith_exp.events ( + environment_key TEXT NOT NULL, + event TEXT NOT NULL, + feature_name TEXT, + timestamp TIMESTAMPTZ NOT NULL, + collected_at TIMESTAMPTZ, + identifier TEXT NOT NULL, + value TEXT, + traits TEXT, + metadata TEXT, + sdk_language TEXT, + sdk_version TEXT +); +CREATE INDEX IF NOT EXISTS events_env_event_feature_ts ON flagsmith_exp.events (environment_key, event, feature_name, timestamp); +CREATE INDEX IF NOT EXISTS events_env_event_identifier_ts ON flagsmith_exp.events (environment_key, event, identifier, timestamp); + +-- Create a dedicated user for Flagsmith +CREATE USER PASSWORD ''; + +-- Allow it to read and write experiment events +GRANT USAGE ON SCHEMA flagsmith_exp TO ; +GRANT SELECT, INSERT ON flagsmith_exp.events TO ; +``` + +To use a schema other than `flagsmith_exp`, use the same name in the script and in Flagsmith. Schema names may contain +only lowercase letters, numbers and underscores, and can't start with a number. + +Flagsmith doesn't create or alter the table, so keep exactly these columns and types. + +## 2. Connect in Flagsmith + +1. Go to **Environment Settings › Warehouse** and select **PostgreSQL**. +2. Fill in the connection details: + - **Host**: a hostname or IP address only, without a scheme, path or port. + - **Name this warehouse**: any name, e.g. `Production PostgreSQL`. + - **Port**: `5432` by default. + - **Database**: the database you ran the script in. + - **Schema**: `flagsmith_exp`, unless you changed it. + - **Username** and **Password**: the user you created in step 1. Usernames are lowercase unless you quoted the name + in `CREATE USER`. + - **Secure connection (TLS)**: on by default. It encrypts the connection but doesn't verify the server's certificate. + You can only turn it off when self-hosting. +3. Click **Test connection**. Once it succeeds, click **Save and continue**. The test checks that the user can use the + schema, and that the events table exists, has the expected columns and allows `SELECT` and `INSERT`. If the test + can't connect, you can save anyway and test again later, but events won't be delivered until it succeeds. If + Flagsmith rejects a field, such as the host or schema, fix it before saving. +4. On Flagsmith Cloud, to verify events reach your table, click **Send your first event** on the connection card; the + button disappears once the first event arrives. + +![The PostgreSQL connection form with host, name, port, database, schema, username, password and TLS fields](/img/experimentation/warehouse-postgres-form.png) + +![A connected PostgreSQL warehouse card showing the last event received, total events, unique event names and the database setup SQL](/img/experimentation/warehouse-postgres-connected.png) + +## Manage the connection + +### Change the password + +Change the user's password on your server first. Then edit the connection, enter the new password, click **Test +connection**, then click **Save changes**. Leaving the password blank keeps the current one. + +### Change server + +The host can't be changed. To use a different PostgreSQL database, disconnect and create a new connection. + +## Performance and table growth + +Results queries scan the events table, so they slow down as it grows. If results become too slow, use +[ClickHouse](/experimentation/connect-a-warehouse#bring-your-own-clickhouse) or +[Databricks](/experimentation/connect-databricks), which are built for this kind of query. + +Flagsmith doesn't delete old events or partition the table. Monitor its size and manage retention yourself. + +## Troubleshooting + +Errors show under a form field, below **Test connection**, or on the connection card with status **Errored** when event +delivery fails. + +| Message | Where | What to do | +| ---------------------------------------------------------------------------------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Enter a hostname or IP address, without a scheme or port. | Form | Remove any scheme (`postgresql://`), path, user or port from **Host**. | +| Port must be a number between 1 and 65535. | Form | Fix **Port**. | +| Use lowercase letters, numbers and underscores, not starting with a number. | Form | Fix **Schema**, and use the same name in the setup SQL. | +| Host must not target internal or private network addresses. | Test, card | On Flagsmith Cloud, use a host with a public address. | +| Authentication failed. | Test, card | Check **Username** and **Password**, and that your server's `pg_hba.conf` or firewall rules allow the connection. | +| Database does not exist. | Test, card | Check **Database**. | +| Events table not found in the configured database. Run the setup SQL to create it. | Test, card | Run the script in [step 1](#1-create-the-events-table-and-user) with the same schema as the connection. | +| Permission denied on the events table. The user needs SELECT and INSERT on it. | Test, card | Run the `GRANT` statements in step 1 again for the connection's user. | +| The events table's columns don't match the setup SQL. | Test, card | Make the table's columns and types match step 1 exactly. | +| The query timed out. | Test, card | Check the server's load. If the events table is large, see [Performance and table growth](#performance-and-table-growth). | +| Could not connect to the host. | Test, card | Check **Host** and **Port**, that the server accepts connections from Flagsmith, that the user has `CONNECT` on the database and, with **Secure connection (TLS)** on, that it supports SSL. | +| The PostgreSQL server rejected the request. | Test, card | Check the server's logs for the rejected connection or query. | +| Connection failed. | Test, card | [Contact support](/support/). | diff --git a/docs/docs/experimentation/run-an-experiment.mdx b/docs/docs/experimentation/run-an-experiment.mdx index cbf52aedb999..b30d5038470b 100644 --- a/docs/docs/experimentation/run-an-experiment.mdx +++ b/docs/docs/experimentation/run-an-experiment.mdx @@ -142,8 +142,8 @@ Enable events when you create the client, with the environment key you already u client-side key and server-side keys. When self-hosting, also point the SDK at your Flagsmith API and your event ingestion service, as in the commented lines -below. Otherwise the SDK sends events to Flagsmith Cloud. To deploy the event ingestion service, see -[Experimentation in the Helm chart](/deployment-self-hosting/hosting-guides/kubernetes-openshift#experimentation). +below. Otherwise the SDK sends events to Flagsmith Cloud. If you use the Flagsmith database, set the events URL to your +Flagsmith API URL ending in `/api/` instead. See [Self-Hosting and Open Source](/experimentation/self-hosting). The SDKs buffer events and send them in batches, by default every 10 seconds. Send what is left before your application exits, as shown in each tab. @@ -599,6 +599,8 @@ The SDKs skip events silently rather than throw. If the **Exposures** panel stay - The identity is inside the experiment's rollout. Identities outside it are not enrolled and record no exposure. - Buffered events were sent before your application exited. See [Initialise](#initialise). - Event names match your metrics exactly, including case. +- Event timestamps are within the accepted window. Events older than 10 days or more than 24 hours in the future are + rejected, and a batch over 2 MiB is rejected whole. To see why an event was skipped, turn on your SDK's debug logging. diff --git a/docs/docs/experimentation/self-hosting.md b/docs/docs/experimentation/self-hosting.md new file mode 100644 index 000000000000..4324536d3e8c --- /dev/null +++ b/docs/docs/experimentation/self-hosting.md @@ -0,0 +1,87 @@ +--- +title: Self-Hosting and Open Source +sidebar_label: Self-Hosting and Open Source +sidebar_position: 2.3 +description: Choose how self-hosted Flagsmith stores experiment events, and what to deploy for each option. +--- + +:::info Beta + +Experimentation is in beta. + +::: + +Experimentation works in both the Open Source version and the +[Enterprise Edition](/deployment-self-hosting/enterprise-edition), with no edition restriction. Self-hosted Flagsmith +can store experiment events in two ways: in the [Flagsmith database](#flagsmith-database) or in +[your own warehouse](#your-own-warehouse). + +## Turning it on + +Set `EXPERIMENTATION_ENABLED=true` on the Flagsmith API. The **Warehouse** tab doesn't appear without it. See +[environment variables](/deployment-self-hosting/core-configuration/environment-variables). + +## Flagsmith database + +:::warning + +For evaluating experimentation only. Events share the database that serves your flags, so they can slow Flagsmith down. +For production, [connect your own warehouse](#your-own-warehouse). + +::: + +Events are stored in the database Flagsmith already runs on, and the SDKs send them to your Flagsmith API. There is +nothing extra to run. This only works when that database is PostgreSQL. + +1. Go to **Environment Settings › Warehouse**. +2. Select **Flagsmith database** and click **Enable**, then confirm. + +![The Warehouse tab with the Flagsmith database card selected and the Enable button](/img/experimentation/warehouse-flagsmith-database.png) + +The connection shows **Connected** straight away. If Flagsmith can't read the events table, it shows **Errored** with +the reason; fix it and click **Test connection** on the card. + +Set each SDK's events URL to the URL shown on the card; see [SDK events URL](#sdk-events-url). To verify events arrive, +click **Send your first event**. + +![A connected Flagsmith database card showing the events URL, an SDK snippet and the Send your first event button](/img/experimentation/warehouse-flagsmith-database-connected.png) + +The connection has no settings to edit. To stop storing events, delete the connection; events already stored stay in the +table. + +## Your own warehouse + +Events are delivered to your own [ClickHouse](/experimentation/connect-a-warehouse#bring-your-own-clickhouse), +[Databricks](/experimentation/connect-databricks) or [PostgreSQL](/experimentation/connect-postgresql). + +- Also run the event ingestion service, Kafka and warehouse delivery. See [Deploying](#deploying). +- Suits higher event volumes. See + [Sizing experimentation](/deployment-self-hosting/scaling-and-performance/sizing-and-scaling#sizing-experimentation). + +## SDK events URL + +By default, the SDKs send events to Flagsmith Cloud. Set each SDK's events URL to: + +- **Flagsmith database**: your Flagsmith API URL ending in `/api/`, for example `https://flagsmith.example.com/api/`. +- **Your own warehouse**: your event ingestion service's public URL, for example + `https://events.flagsmith.example.com/`. + +The SDKs append `v1/events` themselves. See [Initialise](/experimentation/run-an-experiment#initialise) for each SDK. + +## Things to know + +- Events with a timestamp more than 10 days in the past or 24 hours in the future are rejected. +- A batch over 2 MiB is rejected whole. +- Flagsmith never deletes events. Monitor the size of your database or warehouse. + +## Deploying + +- [Docker](/deployment-self-hosting/hosting-guides/docker#experimentation): the + [`docker-compose.yml`](https://github.com/Flagsmith/flagsmith/blob/main/docker-compose.yml) runs every experimentation + service, with a local ClickHouse. +- [Kubernetes and OpenShift](/deployment-self-hosting/hosting-guides/kubernetes-openshift#experimentation): the + [Helm chart](https://github.com/Flagsmith/flagsmith-charts) runs the ingestion service and warehouse delivery, with + your own Kafka and warehouse. + +The source for the [event ingestion service](https://github.com/Flagsmith/ingestion-server) and +[warehouse delivery](https://github.com/Flagsmith/warehouse-delivery) is on GitHub. diff --git a/docs/static/img/experimentation/warehouse-flagsmith-database-connected.png b/docs/static/img/experimentation/warehouse-flagsmith-database-connected.png new file mode 100644 index 000000000000..ca189c3a3fec Binary files /dev/null and b/docs/static/img/experimentation/warehouse-flagsmith-database-connected.png differ diff --git a/docs/static/img/experimentation/warehouse-flagsmith-database.png b/docs/static/img/experimentation/warehouse-flagsmith-database.png new file mode 100644 index 000000000000..c8bfd6c336b7 Binary files /dev/null and b/docs/static/img/experimentation/warehouse-flagsmith-database.png differ diff --git a/docs/static/img/experimentation/warehouse-postgres-connected.png b/docs/static/img/experimentation/warehouse-postgres-connected.png new file mode 100644 index 000000000000..d5cf4d5981e4 Binary files /dev/null and b/docs/static/img/experimentation/warehouse-postgres-connected.png differ diff --git a/docs/static/img/experimentation/warehouse-postgres-form.png b/docs/static/img/experimentation/warehouse-postgres-form.png new file mode 100644 index 000000000000..b0a97872012b Binary files /dev/null and b/docs/static/img/experimentation/warehouse-postgres-form.png differ diff --git a/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/WarehouseSetup.tsx b/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/WarehouseSetup.tsx index 731688e3fcca..d2d2b4b46470 100644 --- a/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/WarehouseSetup.tsx +++ b/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/WarehouseSetup.tsx @@ -245,8 +245,8 @@ const WarehouseSetup: FC = ({ <>

Run this once against your ClickHouse instance using an - administrative user. Replace {''} and{' '} - {''} with your own values. + administrative user. Replace {''} and {''}{' '} + with your own values.

@@ -312,10 +312,11 @@ const WarehouseSetup: FC = ({ configure={ <>

- Run this once as a superuser or a role with CREATEROLE. Replace{' '} - {''} and {''} with your own values. - This also works with PostgreSQL-compatible services such as - Supabase, Neon, Amazon RDS and Aurora, AlloyDB and Cloud SQL. + Run this once as a superuser, or as a role with CREATEROLE and + CREATE on the database. Replace {''} and{' '} + {''} with your own values. This also works with + PostgreSQL-compatible services such as Supabase, Neon, Amazon + RDS and Aurora, AlloyDB and Cloud SQL.

diff --git a/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/__tests__/clickhouseSetupSql.test.ts b/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/__tests__/clickhouseSetupSql.test.ts index d2c7b32f439a..bdfc2bd7bba4 100644 --- a/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/__tests__/clickhouseSetupSql.test.ts +++ b/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/__tests__/clickhouseSetupSql.test.ts @@ -26,7 +26,7 @@ describe('getClickHouseOnboardingSql', () => { expect(sql).toContain('CREATE USER IF NOT EXISTS ') expect(sql).toContain( - "IDENTIFIED WITH sha256_password BY '';", + "IDENTIFIED WITH sha256_password BY '';", ) expect(sql).toContain( 'GRANT SELECT, INSERT ON flagsmith_exp.events TO ;', diff --git a/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/__tests__/postgresSetupSql.test.ts b/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/__tests__/postgresSetupSql.test.ts index 7a8c1ca6e0f7..f0e030694702 100644 --- a/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/__tests__/postgresSetupSql.test.ts +++ b/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/__tests__/postgresSetupSql.test.ts @@ -13,7 +13,7 @@ describe('getPostgresOnboardingSql', () => { const sql = getPostgresOnboardingSql() const positions = [ 'CREATE TABLE IF NOT EXISTS flagsmith_exp.events', - "CREATE USER PASSWORD '';", + "CREATE USER PASSWORD '';", 'GRANT USAGE ON SCHEMA flagsmith_exp TO ;', 'GRANT SELECT, INSERT ON flagsmith_exp.events TO ;', ].map((statement) => sql.indexOf(statement)) diff --git a/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/__tests__/postgresSetupSqlDocs.test.ts b/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/__tests__/postgresSetupSqlDocs.test.ts new file mode 100644 index 000000000000..d47bb40e484d --- /dev/null +++ b/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/__tests__/postgresSetupSqlDocs.test.ts @@ -0,0 +1,23 @@ +import fs from 'fs' +import path from 'path' +import { getPostgresOnboardingSql } from 'components/pages/environment-settings/tabs/warehouse-tab/postgresSetupSql' + +const normalise = (sql: string) => sql.replace(/\s+/g, ' ').trim() + +describe('getPostgresOnboardingSql', () => { + it('matches the copy of the script in the documentation', () => { + const doc = fs.readFileSync( + path.join( + __dirname, + '../../../../../../../../docs/docs/experimentation/connect-postgresql.md', + ), + 'utf8', + ) + const fencedSql = + doc.match( + /```sql\n(-- Create the schema and events table\n[\s\S]*?)```/, + )?.[1] ?? '' + + expect(normalise(fencedSql)).toEqual(normalise(getPostgresOnboardingSql())) + }) +}) diff --git a/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/clickhouseSetupSql.ts b/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/clickhouseSetupSql.ts index 80112013e60f..4c493550a2bb 100644 --- a/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/clickhouseSetupSql.ts +++ b/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/clickhouseSetupSql.ts @@ -35,7 +35,7 @@ ${getClickHouseSetupSql('flagsmith_exp')} -- Create a dedicated user for Flagsmith CREATE USER IF NOT EXISTS - IDENTIFIED WITH sha256_password BY ''; + IDENTIFIED WITH sha256_password BY ''; -- Allow it to write and read experiment events GRANT SELECT, INSERT ON flagsmith_exp.events TO ; diff --git a/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/postgresSetupSql.ts b/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/postgresSetupSql.ts index 6465fcbf9486..c8cf0cb4b36e 100644 --- a/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/postgresSetupSql.ts +++ b/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/postgresSetupSql.ts @@ -26,7 +26,7 @@ export const getPostgresOnboardingSql = (): string => { ${getPostgresSetupSql(schema)} -- Create a dedicated user for Flagsmith -CREATE USER PASSWORD ''; +CREATE USER PASSWORD ''; -- Allow it to read and write experiment events GRANT USAGE ON SCHEMA ${schema} TO ;