0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-21 21:49:51 +01:00
posthog/bin/docker-server
Frank Hamand 789bc23c91
feat: Add kafka rack aware injection on docker-server (#17541)
Add kafka rack aware injection on docker-server

Currently we only inject this in plugin-server (aka reading from kafka)

Let's add it as well to docker-server (aka capture/writing to kafka)
2023-09-20 10:14:58 +01:00

33 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
set -e
./bin/migrate-check
# To ensure we are able to expose metrics from multiple processes, we need to
# provide a directory for `prometheus_client` to store a shared registry.
export PROMETHEUS_MULTIPROC_DIR=$(mktemp -d)
trap 'rm -rf "$PROMETHEUS_MULTIPROC_DIR"' EXIT
export PROMETHEUS_METRICS_EXPORT_PORT=8001
export STATSD_PORT=${STATSD_PORT:-8125}
if [[ -n $INJECT_EC2_CLIENT_RACK ]]; then
# To avoid cross-AZ Kafka traffic, set KAFKA_CLIENT_RACK from the EC2 metadata endpoint.
# TODO: switch to the downwards API when https://github.com/kubernetes/kubernetes/issues/40610 is released
TOKEN=$(curl --max-time 0.1 -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
export KAFKA_CLIENT_RACK=$(curl --max-time 0.1 -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/placement/availability-zone-id)
fi
exec gunicorn posthog.wsgi \
--config gunicorn.config.py \
--bind 0.0.0.0:8000 \
--log-file - \
--log-level info \
--access-logfile - \
--worker-tmp-dir /dev/shm \
--workers=2 \
--threads=8 \
--worker-class=gthread \
${STATSD_HOST:+--statsd-host $STATSD_HOST:$STATSD_PORT} \
--limit-request-line=16384 $@