The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Setup analytics for self-hosted; Updated documentation
Filipe Cabaco642527b4e955
diff --git a/apps/docs/docs/ref/self-hosting-analytics/introduction.mdx b/apps/docs/docs/ref/self-hosting-analytics/introduction.mdxindex a1cb8d81c9a..954ea7212be 100644--- a/apps/docs/docs/ref/self-hosting-analytics/introduction.mdx+++ b/apps/docs/docs/ref/self-hosting-analytics/introduction.mdx@@ -28,6 +28,27 @@ However, it's important to note that certain [differences](#differences) may ari### Pre-requisites+Currently the Analytics service supports two backends for ingestion:++- Postgres ingestion+- Big Query ingestion++### Postgres Ingestion Requirements++- Requires you to use supabase/logflare:1.3.26 or above+- Requires the following environment variables set:+ - Required - POSTGRES_BACKEND_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}+ - Optional - POSTGRES_BACKEND_SCHEMA: ${SCHEMA_NAME}++### Big Query Ingestion Requirements++- Google Cloud Account with billing enabled+- Big Query enabled++The remainder of the instructions are specified in the [Setup Big Query ingestion](#setup-big-query-ingestion) section.++#### Setup Big Query ingestion+Logflare currently requires BigQuery usage. You will need to create a Google Cloud project with billing enabled.The requirements are as follows after creating the project:@@ -36,7 +57,7 @@ The requirements are as follows after creating the project:- Project number- A service account key-#### Setting up BigQuery Service Account+##### Setting up BigQuery Service AccountTo ensure that you have sufficient permissions to insert into your Google Cloud BigQuery, ensure that you have created a service account with either:@@ -60,31 +81,50 @@ You can create the service account via the web console or `gcloud`, as per the [We recommend setting the BigQuery Admin role, as it simplifies permissions setup.-#### Downloading the Service Account key+##### Downloading the Service Account keyAfter the service account is created, you will need to create a key for the service account. This key will sign the JWTs for API requests that the Analytics server makes with BigQuery.### Docker Compose+For analytics to work we're adding two services: Logflare and Vector.++Logflare is the analytics server that will ingest your logs into your prefered backend while Vector is the log router that will route all the docker logs using syslog unto Logflare.++#### Using the Postgres Backend++You can simply startup using the following command++```bash+# assuming you clone the supabase/supabase repo.+cd docker+docker compose -f docker-compose.yml up+```++> ⚠️ WARNING: Please be aware of the heavy consumption of analytics. For heavy usage you might want to consider the usage of a different database for analytics only by updating the `POSTGRES_BACKEND_URL` in the `analytics` service on the `docker-compose.yml` file.++#### Using the Big Query Backend+Using the example [self-hosting stack based on docker-compose](https://github.com/supabase/supabase/tree/master/docker), you include the logging related services using the following command-You will first need to update the `.env.example` file with the necessary environment variables.+1. Update the `.env.example` file with the necessary environment variables.- `GOOGLE_PROJECT_ID`- `GOOGLE_PROJECT_NUMBER`-You will need to place your Service Account key in your present working directory with the filename `gcloud.json`.+2. Place your Service Account key in your present working directory with the filename `gcloud.json`.-Thereafter, you can run the docker-compose commands and include the logging-specific compose file.+3. On `docker-compose.yml`, uncomment the block section below the commentary `# Uncomment to use Big Query backend for analytics`+4. On `docker-compose.yml`, comment the block section below the commentary `# Comment variables to use Big Query backend for analytics`++Thereafter, you can simply startup using the following command```bash# assuming you clone the supabase/supabase repo.cd docker-docker compose -f docker-compose.yml -f docker-compose-logging.yml up+docker compose -f docker-compose.yml```-This would include two additional docker services to your compose stack: Logflare and Vector.-<Admonition type="info" label="Self-hosting">Read more about [self-hosting Logflare](https://docs.logflare.app/self-hosting) as your analyticsserver.@@ -98,9 +138,7 @@ If you need to customize the logging pipeline for your own needs, you must ensur### Standalone Docker Container-If desired, you can utilize the standalone docker-container. Please refer to the [docker-compose file](https://github.com/supabase/supabase/tree/master/docker/docker-compose-logging.yml) for required docker configuration.--Additional supplementary technical documentation on self-hosting and using the `supabase/logflare` image for a full Logflare experience is available at the [official Logflare documentation](https://docs.logflare.app/self-hosting/).+Supplementary technical documentation on self-hosting and using the `supabase/logflare` image for a full Logflare experience is available at the [official Logflare documentation](https://docs.logflare.app/self-hosting/).## Differences@@ -109,6 +147,16 @@ API logs rely on Kong instead of the Supabase Cloud API Gateway. Logs from KongWithin the self-hosted setup, all logs are routed to Logflare via Vector. As Kong routes API requests to PostgREST, self-hosted or local deployments will result in Kong request logs instead.This would result in differences in the log event metadata between self-hosted API requests and Supabase Platform requests.+## Postgres++Log event data is stored and queried from a Postgres database.++Make sure to set the `POSTGRES_BACKEND_URL` environment variable.++### Storage++All data will be stored on the Postgres Database configured by setting `POSTGRES_BACKEND_URL`+## BigQueryAll log event data is stored in and queried from BigQuery. To use the Analytics server with Supabase you'll need a Google Cloud Platform account for access to BigQuery.@@ -141,6 +189,10 @@ Logflare requires a Postgres database to function. However, if there is an issueThe self-hosted example is only used as a minimal example on running the entire stack, however it is not recommended to use the same database server for both production and observability.+### Use Big Query as the Logflare Backend++The current Postgres Ingestion backend isn't optimized for production usage. We recommend using Big Query for more heavy use cases.+</RefSubLayout.Details><RefSubLayout.Examples>diff --git a/docker/docker-compose-logging.yml b/docker/docker-compose-logging.ymldeleted file mode 100644index fe3ec5c8d7c..00000000000--- a/docker/docker-compose-logging.yml+++ /dev/null@@ -1,163 +0,0 @@-# Usage-# Start: docker compose -f docker-compose.yml -f docker-compose-logging.yml up-# With helpers: docker compose -f docker-compose.yml -f ./dev/docker-compose.dev.yml -f docker-compose-logging.yml up-# Stop: docker compose down-# Destroy: docker compose -f docker-compose.yml -f ./dev/docker-compose.dev.yml -f docker-compose-logging.yml down -v --remove-orphans-# Please refer to https://supabase.com/docs/reference/self-hosting-analytics/introduction-version: "3.8"--services:- studio:- logging:- driver: syslog- options:- syslog-address: "tcp://localhost:${VECTOR_PORT}"- tag: studio- depends_on:- analytics:- condition: service_healthy- environment:- LOGFLARE_API_KEY: ${LOGFLARE_API_KEY}- LOGFLARE_URL: http://analytics:4000- NEXT_PUBLIC_ENABLE_LOGS: true-- kong:- logging:- driver: syslog- options:- syslog-address: "tcp://localhost:${VECTOR_PORT}"- tag: kong- depends_on:- analytics:- condition: service_healthy-- auth:- depends_on:- analytics:- condition: service_healthy- logging:- driver: syslog- options:- syslog-address: "tcp://localhost:${VECTOR_PORT}"- tag: auth-- rest:- depends_on:- analytics:- condition: service_healthy- logging:- driver: syslog- options:- syslog-address: "tcp://localhost:${VECTOR_PORT}"- tag: rest-- realtime:- depends_on:- analytics:- condition: service_healthy- logging:- driver: syslog- options:- syslog-address: "tcp://localhost:${VECTOR_PORT}"- tag: realtime-- storage:- depends_on:- analytics:- condition: service_healthy- logging:- driver: syslog- options:- syslog-address: "tcp://localhost:${VECTOR_PORT}"- tag: storage-- meta:- depends_on:- analytics:- condition: service_healthy- logging:- driver: syslog- options:- syslog-address: "tcp://localhost:${VECTOR_PORT}"- tag: meta-- functions:- depends_on:- analytics:- condition: service_healthy- logging:- driver: syslog- options:- syslog-address: "tcp://localhost:${VECTOR_PORT}"- tag: functions-- analytics:- container_name: supabase-analytics- image: supabase/logflare:1.3.17- healthcheck:- test: [ "CMD", "curl", "http://localhost:4000/health" ]- timeout: 5s- interval: 5s- retries: 10- restart: unless-stopped- depends_on:- db:- # Disable this if you are using an external Postgres database- condition: service_healthy- ports:- - ${LOGFLARE_HTTP_PORT}:4000/tcp- volumes:- - type: bind- source: ${PWD}/gcloud.json- target: /opt/app/rel/logflare/bin/gcloud.json- read_only: true- environment:- MY_POD_IP: 127.0.0.1- DB_USERNAME: supabase_admin- DB_DATABASE: ${POSTGRES_DB}- DB_HOSTNAME: ${POSTGRES_HOST}- DB_PORT: ${POSTGRES_PORT}- DB_PASSWORD: ${POSTGRES_PASSWORD}- DB_SCHEMA: _analytics- LOGFLARE_API_KEY: ${LOGFLARE_API_KEY}- GOOGLE_PROJECT_ID: ${GOOGLE_PROJECT_ID}- GOOGLE_PROJECT_NUMBER: ${GOOGLE_PROJECT_NUMBER}- LOGFLARE_SINGLE_TENANT: true- LOGFLARE_SUPABASE_MODE: true- LOGFLARE_MIN_CLUSTER_SIZE: 1- vector:- container_name: supabase-vector- image: timberio/vector:0.28.1-alpine- healthcheck:- test:- [-- "CMD",- "wget",- "--no-verbose",- "--tries=1",- "--spider",- "http://localhost:${VECTOR_API_PORT}/health"- ]- timeout: 5s- interval: 5s- retries: 3- ports:- - ${VECTOR_PORT}:${VECTOR_PORT}- - ${VECTOR_API_PORT}:${VECTOR_API_PORT}- volumes:- - ./volumes/logs/vector.yml:/etc/vector/vector.yml:ro- command: [ "--config", "etc/vector/vector.yml" ]- # Comment out everything below this point if you are using an external Postgres database- db:- logging:- driver: syslog- options:- syslog-address: "tcp://localhost:${VECTOR_PORT}"- tag: db- depends_on:- vector:- # Disable this if you are using an external Postgres database- condition: service_healthy- volumes:- - ./volumes/db/logs.sql:/docker-entrypoint-initdb.d/migrations/99-logs.sql:Zdiff --git a/docker/docker-compose.yml b/docker/docker-compose.ymlindex a4bc0ce9866..b4d69bbca7c 100644--- a/docker/docker-compose.yml+++ b/docker/docker-compose.yml@@ -23,6 +23,14 @@ services:timeout: 5sinterval: 5sretries: 3+ logging:+ driver: syslog+ options:+ syslog-address: "tcp://localhost:${VECTOR_PORT}"+ tag: studio+ depends_on:+ analytics:+ condition: service_healthyenvironment:STUDIO_PG_META_URL: http://meta:8080POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}@@ -35,6 +43,10 @@ services:SUPABASE_ANON_KEY: ${ANON_KEY}SUPABASE_SERVICE_KEY: ${SERVICE_ROLE_KEY}+ LOGFLARE_API_KEY: ${LOGFLARE_API_KEY}+ LOGFLARE_URL: http://analytics:4000+ NEXT_PUBLIC_ENABLE_LOGS: true+kong:container_name: supabase-kongimage: kong:2.8.1@@ -44,6 +56,14 @@ services:ports:- ${KONG_HTTP_PORT}:8000/tcp- ${KONG_HTTPS_PORT}:8443/tcp+ logging:+ driver: syslog+ options:+ syslog-address: "tcp://localhost:${VECTOR_PORT}"+ tag: kong+ depends_on:+ analytics:+ condition: service_healthyenvironment:KONG_DATABASE: "off"KONG_DECLARATIVE_CONFIG: /home/kong/kong.yml@@ -65,6 +85,8 @@ services:db:# Disable this if you are using an external Postgres databasecondition: service_healthy+ analytics:+ condition: service_healthyhealthcheck:test:[@@ -79,6 +101,11 @@ services:interval: 5sretries: 3restart: unless-stopped+ logging:+ driver: syslog+ options:+ syslog-address: "tcp://localhost:${VECTOR_PORT}"+ tag: authenvironment:GOTRUE_API_HOST: 0.0.0.0GOTRUE_API_PORT: 9999@@ -123,7 +150,14 @@ services:db:# Disable this if you are using an external Postgres databasecondition: service_healthy+ analytics:+ condition: service_healthyrestart: unless-stopped+ logging:+ driver: syslog+ options:+ syslog-address: "tcp://localhost:${VECTOR_PORT}"+ tag: restenvironment:PGRST_DB_URI: postgres://authenticator:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}PGRST_DB_SCHEMAS: ${PGRST_DB_SCHEMAS}@@ -138,6 +172,8 @@ services:db:# Disable this if you are using an external Postgres databasecondition: service_healthy+ analytics:+ condition: service_healthyhealthcheck:test:[@@ -150,6 +186,11 @@ services:interval: 5sretries: 3restart: unless-stopped+ logging:+ driver: syslog+ options:+ syslog-address: "tcp://localhost:${VECTOR_PORT}"+ tag: realtimeenvironment:PORT: 4000DB_HOST: ${POSTGRES_HOST}@@ -235,7 +276,14 @@ services:db:# Disable this if you are using an external Postgres databasecondition: service_healthy+ analytics:+ condition: service_healthyrestart: unless-stopped+ logging:+ driver: syslog+ options:+ syslog-address: "tcp://localhost:${VECTOR_PORT}"+ tag: metaenvironment:PG_META_PORT: 8080PG_META_DB_HOST: ${POSTGRES_HOST}@@ -248,6 +296,14 @@ services:container_name: supabase-edge-functionsimage: supabase/edge-runtime:v1.6.6restart: unless-stopped+ depends_on:+ analytics:+ condition: service_healthy+ logging:+ driver: syslog+ options:+ syslog-address: "tcp://localhost:${VECTOR_PORT}"+ tag: functionsenvironment:JWT_SECRET: ${JWT_SECRET}SUPABASE_URL: http://kong:8000@@ -263,6 +319,56 @@ services:- --main-service- /home/deno/functions/main+ analytics:+ container_name: supabase-analytics+ image: supabase/logflare:1.3.26+ healthcheck:+ test: [ "CMD", "curl", "http://localhost:4000/health" ]+ timeout: 5s+ interval: 5s+ retries: 10+ restart: unless-stopped+ depends_on:+ db:+ # Disable this if you are using an external Postgres database+ condition: service_healthy+ ports:+ - ${LOGFLARE_HTTP_PORT}:4000/tcp+ # Uncomment to use Big Query backend for analytics+ # volumes:+ # - type: bind+ # source: ${PWD}/gcloud.json+ # target: /opt/app/rel/logflare/bin/gcloud.json+ # read_only: true+ environment:+ LOGFLARE_NODE_HOST: 127.0.0.1+ DB_USERNAME: supabase_admin+ DB_DATABASE: ${POSTGRES_DB}+ DB_HOSTNAME: ${POSTGRES_HOST}+ DB_PORT: ${POSTGRES_PORT}+ DB_PASSWORD: ${POSTGRES_PASSWORD}+ DB_SCHEMA: _analytics+ LOGFLARE_API_KEY: ${LOGFLARE_API_KEY}+ LOGFLARE_SINGLE_TENANT: true+ LOGFLARE_SUPABASE_MODE: true+ LOGFLARE_MIN_CLUSTER_SIZE: 1+ RELEASE_COOKIE: cookie++ # Comment variables to use Big Query backend for analytics+ POSTGRES_BACKEND_URL: postgresql://supabase_admin:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}+ POSTGRES_BACKEND_SCHEMA: _analytics+ LOGFLARE_FEATURE_FLAG_OVERRIDE: multibackend=true++ # Uncomment to use Big Query backend for analytics+ # GOOGLE_PROJECT_ID: ${GOOGLE_PROJECT_ID}+ # GOOGLE_PROJECT_NUMBER: ${GOOGLE_PROJECT_NUMBER}+ entrypoint: |+ sh -c `cat <<'EOF' > run.sh && sh run.sh+ ./logflare eval Logflare.Release.migrate+ ./logflare start --sname logflare+ EOF+ `+# Comment out everything below this point if you are using an external Postgres databasedb:container_name: supabase-db@@ -272,6 +378,14 @@ services:interval: 5stimeout: 5sretries: 10+ depends_on:+ vector:+ condition: service_healthy+ logging:+ driver: syslog+ options:+ syslog-address: "tcp://localhost:${VECTOR_PORT}"+ tag: dbcommand:- postgres- -c@@ -298,5 +412,29 @@ services:- ./volumes/db/roles.sql:/docker-entrypoint-initdb.d/init-scripts/99-roles.sql:Z# PGDATA directory is persisted between restarts- ./volumes/db/data:/var/lib/postgresql/data:Z+ # Changes required for Analytics support+ - ./volumes/db/logs.sql:/docker-entrypoint-initdb.d/migrations/99-logs.sql:Z++ vector:+ container_name: supabase-vector+ image: timberio/vector:0.28.1-alpine+ healthcheck:+ test:+ [-# If you want to use logging, please run with `docker compose -f docker-compose.yml -f docker-compose-logging.yml up`+ "CMD",+ "wget",+ "--no-verbose",+ "--tries=1",+ "--spider",+ "http://localhost:${VECTOR_API_PORT}/health"+ ]+ timeout: 5s+ interval: 5s+ retries: 3+ ports:+ - ${VECTOR_PORT}:${VECTOR_PORT}+ - ${VECTOR_API_PORT}:${VECTOR_API_PORT}+ volumes:+ - ./volumes/logs/vector.yml:/etc/vector/vector.yml:ro+ command: [ "--config", "etc/vector/vector.yml" ]