Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ SQLFlow is a stream processing engine that lets you define pipelines with just S

One click runs SQLFlow on Render: a webhook that accepts metrics, a one-minute
aggregation into Postgres, and an HTTP API that reads them back. It asks for
one secret and is a paid deploy. See [`render/`](render/README.md).
a signing secret and a client id, and is a paid deploy. Telemetry is off. See
[`render/`](render/README.md).

# Quick Start (Getting Started in 5 Minutes)

Expand Down
23 changes: 11 additions & 12 deletions render.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
# This file is at the repository root because the button reads it from there.
# Everything it deploys is under render/.
#
# The deploy asks for three values. The first two are yours to choose, so you
# have them when the deploy finishes. `openssl rand -hex 32` and `openssl rand -hex 16`
# The deploy asks for two values. Both are yours to choose, so you have them
# when the deploy finishes. `openssl rand -hex 32` and `openssl rand -hex 16`
# make good ones.
# SQLFLOW_WEBHOOK_HMAC_SECRET signs what you send. A blank one fails the
# ingest service: the pipeline will not start
# unsigned unless SQLFLOW_WEBHOOK_AUTH is none.
# SQLFLOW_SERVE_CLIENT_ID reads what you sent, as ?client_id=. A blank
# one fails the API service. Letters, digits,
# '.', '_', '~' and '-' only.
# SQLFLOW_TELEMETRY leave it blank, or type off. Blank sends the
# sqlflow maintainers two events, ever: that
# this was deployed, and that it received its
# first metric. render/README.md, "What this
# sends", prints both in full.
#
# Telemetry is off: SQLFLOW_TELEMETRY is unset, and the deploy does not ask
# for it. Setting it to on sends the sqlflow maintainers two events, ever:
# that this was deployed, and that it received its first metric.
# render/README.md, "What this sends", prints both in full.
databases:
- name: sqlflow-metrics-db
plan: 0.1c-256mb
Expand Down Expand Up @@ -59,11 +59,10 @@ services:
# Prompted for during the deploy.
- key: SQLFLOW_WEBHOOK_HMAC_SECRET
sync: false
# Prompted for during the deploy, so that it is seen before anything is
# sent rather than found afterwards. Blank is on. off sends nothing.
# sync: false also means a later sync never touches what was typed.
- key: SQLFLOW_TELEMETRY
sync: false
# SQLFLOW_TELEMETRY is not here, on purpose. Unset, nothing is sent.
# To opt in, add it to this service in the dashboard with the value on.
# A variable this file does not name survives a sync, so the opt-in is
# kept.
# SQLFLOW_WEBHOOK_AUTH is not here, on purpose. Unset, the pipeline
# requires a signature. To accept unsigned requests, add it to this
# service in the dashboard with the value none. Render keeps a variable
Expand Down
24 changes: 11 additions & 13 deletions render/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ services, in `virginia`. Render shows the price before you confirm.

## Deploy

Render asks for three values. Make the first two before you click, and keep
them. You choose both, so you have
them when the deploy finishes:
Render asks for two values. Make both before you click, and keep them. You
choose both, so you have them when the deploy finishes:

```sh
openssl rand -hex 32 # SQLFLOW_WEBHOOK_HMAC_SECRET
Expand All @@ -25,7 +24,6 @@ openssl rand -hex 16 # SQLFLOW_SERVE_CLIENT_ID
|---|---|
| `SQLFLOW_WEBHOOK_HMAC_SECRET` | Signs what you send. Any long random string. |
| `SQLFLOW_SERVE_CLIENT_ID` | Reads what you sent, as `?client_id=`. Letters, digits, `.`, `_`, `~` and `-` only, so it can be pasted into a URL. |
| `SQLFLOW_TELEMETRY` | Leave it blank, or type `off`. See [What this sends](#what-this-sends). |

A blank value fails its service, on purpose. The pipeline writes to your
database and will not start unsigned unless you set
Expand All @@ -39,10 +37,10 @@ When the deploy finishes, copy the URLs of `sqlflow-metrics-ingest` and

## What this sends

Unless you type `off` at the `SQLFLOW_TELEMETRY` prompt, this deploy sends the
sqlflow maintainers two events, once each, for as long as it exists. They
tell us that the template was deployed and that it worked. This is the whole
of both:
Nothing. The deploy leaves `SQLFLOW_TELEMETRY` unset and does not ask for it.
If you set it to `on`, this deploy sends the sqlflow maintainers two events,
once each, for as long as it exists. They tell us that the template was
deployed and that it worked. This is the whole of both:

```json
{"name": "install.deployed", "type": "count", "value": 1,
Expand Down Expand Up @@ -73,12 +71,12 @@ address it came from. The pipeline neither reads nor stores it. Render's
request log for that service holds it for a while, as any host's does.

The ingest service logs each event in full when it sends it. `bin/telemetry.sh`
is 91 lines and is the only code that sends anything. The sqlflow
is 97 lines and is the only code that sends anything. The sqlflow
binary itself never phones home.

**To turn it off**, type `off` at the prompt, or set `SQLFLOW_TELEMETRY=off` on
`sqlflow-metrics-ingest` later. `false`, `0` and `no` also work. Nothing is
sent, and the log says so.
**To turn it on**, add `SQLFLOW_TELEMETRY=on` to `sqlflow-metrics-ingest` in
the Render dashboard. `true`, `1` and `yes` also work. Any other value, blank
included, sends nothing, and the log says so.

A collector that is down, slow or gone never affects your deploy. A send is
bounded at five seconds, runs in the background, and is retried later.
Expand Down Expand Up @@ -273,7 +271,7 @@ not name and rewrites one it does, so a setting made here survives a sync.
| `SQLFLOW_WEBHOOK_HMAC_SECRET` | | Required under `hmac`. |
| `SQLFLOW_METRIC_NAME_PREFIX` | empty | When set, a metric whose name does not start with it is dropped. Letters, digits, `.`, `_` and `-`. |
| `SQLFLOW_WEBHOOK_MAX_BODY_BYTES` | 26214400 | A larger body is refused with 413. |
| `SQLFLOW_TELEMETRY` | on | `off` sends nothing. See [What this sends](#what-this-sends). |
| `SQLFLOW_TELEMETRY` | off | `on` sends two events. See [What this sends](#what-this-sends). |

## Run it locally

Expand Down
7 changes: 4 additions & 3 deletions render/bin/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ export SQLFLOW_WRITER_ID
/app/bin/migrate.sh

# Two events per install, ever, to the sqlflow maintainers: that this was
# deployed, and that it received its first metric. SQLFLOW_TELEMETRY=off stops
# both. In the background and detached from this script's fate: it logs and
# swallows its own failures, and nothing it does can stop the pipeline below.
# deployed, and that it received its first metric. Off unless
# SQLFLOW_TELEMETRY=on. In the background and detached from this script's
# fate: it logs and swallows its own failures, and nothing it does can stop
# the pipeline below.
/app/bin/telemetry.sh &

# exec keeps sqlflow as PID 1, so the platform's SIGTERM reaches it and the
Expand Down
11 changes: 7 additions & 4 deletions render/bin/telemetry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# received its first metric. Two events, each sent once per install, and
# nothing else, ever. render/README.md, "What this sends", prints both.
#
# SQLFLOW_TELEMETRY=off sends nothing. Also: false, 0, no.
# Off by default.
# SQLFLOW_TELEMETRY=on sends the two events. Also: true, 1, yes.
# anything else sends nothing, blank and unset included.
#
# bin/entrypoint.sh starts this in the background after the migrations. It must
# never be the reason a pipeline does not start or stops: every failure here is
Expand All @@ -13,9 +15,10 @@ set -uo pipefail

log() { echo "telemetry: $*" >&2; }

case "$(printf '%s' "${SQLFLOW_TELEMETRY:-on}" | tr '[:upper:]' '[:lower:]')" in
off|false|0|no)
log "off (SQLFLOW_TELEMETRY=${SQLFLOW_TELEMETRY}). Nothing is sent."
case "$(printf '%s' "${SQLFLOW_TELEMETRY:-}" | tr '[:upper:]' '[:lower:]')" in
on|true|1|yes) ;;
*)
log "off (SQLFLOW_TELEMETRY=${SQLFLOW_TELEMETRY:-}). Nothing is sent. Set it to on to send two events; see render/README.md."
exit 0
;;
esac
Expand Down
2 changes: 1 addition & 1 deletion render/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ services:
SQLFLOW_WEBHOOK_HMAC_SECRET: ${SQLFLOW_WEBHOOK_HMAC_SECRET-local-secret}
SQLFLOW_WEBHOOK_PORT: "10000"
SQLFLOW_METRIC_NAME_PREFIX: ${SQLFLOW_METRIC_NAME_PREFIX:-}
# No value: on unless the caller says off, as on Render.
# No value: off unless the caller says on, as on Render.
SQLFLOW_TELEMETRY:
SQLFLOW_TELEMETRY_URL: ${SQLFLOW_TELEMETRY_URL:-http://collector:10000}
SQLFLOW_TELEMETRY_POLL_SECONDS: "1"
Expand Down
29 changes: 19 additions & 10 deletions render/test/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ docker compose up -d --wait postgres
# Whatever ran before this, the pipelines below start with no claim held.
docker compose exec -T postgres psql -U metrics -d metrics -X -Atqc "UPDATE install SET deployed_claimed_at = NULL, first_request_claimed_at = NULL" >/dev/null 2>&1 || true

docker compose up -d collector ingest ingest2 api
# Telemetry is off by default. On here, inline rather than exported, so the
# telemetry section below has events to check and the probes after it start
# with the default.
SQLFLOW_TELEMETRY=on docker compose up -d collector ingest ingest2 api
wait_for ingest "$INGEST/events"
wait_for ingest2 "$INGEST2/events"
wait_for api "$API/healthz"
Expand Down Expand Up @@ -280,21 +283,27 @@ reset_install() { psqlc 'UPDATE install SET deployed_claimed_at = NULL, deployed
run_probe() { # run_probe <label> <env...>: starts a pipeline on :10077 and leaves it running
local label="$1"; shift
local args=(); for e in "$@"; do args+=(-e "$e"); done
docker compose run -d --rm --no-deps -p 127.0.0.1:10077:10000 "${args[@]}" ingest >/dev/null
# The guarded expansion: bash 3.2 calls an empty array unbound under set -u.
docker compose run -d --rm --no-deps -p 127.0.0.1:10077:10000 ${args[@]+"${args[@]}"} ingest >/dev/null
wait_for "$label" "http://127.0.0.1:10077/events"
}
stop_probe() { docker ps -q --filter "publish=10077" | xargs -r docker rm -f >/dev/null; }

reset_install
run_probe "ingest with telemetry off" SQLFLOW_TELEMETRY=off
sleep 6
[ "$(psqlc 'SELECT deployed_sent_at IS NULL AND deployed_claimed_at IS NULL FROM install')" = t ] \
|| fail "SQLFLOW_TELEMETRY=off still claimed or sent install.deployed"
stop_probe
echo "ok SQLFLOW_TELEMETRY=off sends nothing and claims nothing"
# Unset is the default: the Blueprint does not name the variable. Blank is a
# variable added with no value. Neither may send.
for env in "" "SQLFLOW_TELEMETRY=" "SQLFLOW_TELEMETRY=off" "SQLFLOW_TELEMETRY=maybe"; do
label="${env:-SQLFLOW_TELEMETRY unset}"
reset_install
if [ -n "$env" ]; then run_probe "ingest with $label" "$env"; else run_probe "ingest with $label"; fi
sleep 6
[ "$(psqlc 'SELECT deployed_sent_at IS NULL AND deployed_claimed_at IS NULL FROM install')" = t ] \
|| fail "$label still claimed or sent install.deployed"
stop_probe
echo "ok $label sends nothing and claims nothing"
done

reset_install
run_probe "ingest with a collector that is down" SQLFLOW_TELEMETRY_URL=http://127.0.0.1:9
run_probe "ingest with a collector that is down" SQLFLOW_TELEMETRY=on SQLFLOW_TELEMETRY_URL=http://127.0.0.1:9
sleep 6
[ "$(psqlc 'SELECT deployed_sent_at IS NULL FROM install')" = t ] \
|| fail "install.deployed is recorded as sent though the collector was down"
Expand Down
Loading