Skip to content

Commit

Permalink
Merge pull request #13 from statsig-io/10-29-updates_for_version_2.0.0
Browse files Browse the repository at this point in the history
Updates for version 2.0.0
  • Loading branch information
ealui-statsig authored Oct 29, 2024
2 parents b369030 + 15bc4ae commit 2ae01d0
Show file tree
Hide file tree
Showing 14 changed files with 329 additions and 354 deletions.
30 changes: 24 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,30 @@ COPY ./api-interface-definitions ./api-interface-definitions
RUN rm ./target/release/deps/server*
RUN cargo build --release

FROM amd64/rust:1.75-slim
FROM nginx:alpine

# copy the build artifact from the build stage
WORKDIR /app
COPY ./.cargo ./.cargo
COPY ./Rocket.toml ./Rocket.toml
# Copy Nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf

# Copy the build artifact from the build stage
COPY --from=builder /statsig_forward_proxy/target/release/server /usr/local/bin/statsig_forward_proxy

# Copy other necessary files
COPY ./.cargo /app/.cargo
COPY ./Rocket.toml /app/Rocket.toml

# Set working directory
WORKDIR /app

# Set environment variable
ENV ROCKET_ENV=prod
ENTRYPOINT [ "statsig_forward_proxy" ]

# Expose port 8001 for Nginx and 8000 for the proxy
EXPOSE 8000 8001

# Create an entrypoint script
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Use ENTRYPOINT to run the script
ENTRYPOINT ["/entrypoint.sh"]
46 changes: 36 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,51 @@ Usage: server [OPTIONS] <MODE> <CACHE>
Arguments:
<MODE> [possible values: grpc-and-http, grpc, http]
<CACHE> [possible values: disabled, local, redis]
<CACHE> [possible values: disabled, redis]
Options:
--double-write-cache-for-legacy-key
--datadog-logging
--statsd-logging
--statsig-logging
--debug-logging
-m, --maximum-concurrent-sdk-keys <MAXIMUM_CONCURRENT_SDK_KEYS> [default: 1000]
-p, --polling-interval-in-s <POLLING_INTERVAL_IN_S> [default: 10]
-u, --update-batch-size <UPDATE_BATCH_SIZE> [default: 64]
-r, --redis-leader-key-ttl <REDIS_LEADER_KEY_TTL> [default: 70]
--redis-cache-ttl-in-s <REDIS_CACHE_TTL_IN_S> [default: 86400]
-m, --maximum-concurrent-sdk-keys <MAXIMUM_CONCURRENT_SDK_KEYS>
[default: 1000]
-p, --polling-interval-in-s <POLLING_INTERVAL_IN_S>
[default: 10]
-u, --update-batch-size <UPDATE_BATCH_SIZE>
[default: 64]
-r, --redis-leader-key-ttl <REDIS_LEADER_KEY_TTL>
[default: 70]
--redis-cache-ttl-in-s <REDIS_CACHE_TTL_IN_S>
[default: 86400]
--log-event-process-queue-size <LOG_EVENT_PROCESS_QUEUE_SIZE>
[default: 20000]
--force-gcp-profiling-enabled
-g, --grpc-max-concurrent-streams <GRPC_MAX_CONCURRENT_STREAMS> [default: 500]
--clear-external-datastore-on-unauthorized
-g, --grpc-max-concurrent-streams <GRPC_MAX_CONCURRENT_STREAMS>
[default: 500]
--clear-datastore-on-unauthorized
--x509-server-cert-path <X509_SERVER_CERT_PATH>
--x509-server-key-path <X509_SERVER_KEY_PATH>
--x509-client-cert-path <X509_CLIENT_CERT_PATH>
-h, --help Print help
--enforce-tls <ENFORCE_TLS>
[default: true] [possible values: true, false]
--enforce-mtls
-h, --help
Print help
-V, --version
Print version
```
1. MODE: This can be configured as grpc or http or grpc-and-http to allow for easy migrations.
2. CACHE: This is for the backup cache. Local uses in process memory to cache backup values, while redis,
Expand All @@ -53,11 +78,12 @@ Additional logging parameters we support:
```
--debug-logging: This enables state tracking logging that is emitted for various events within the proxy.
It will also emit useful data such as latency for some events.
--double-write-cache-for-legacy-key: Starting in version 2.x.x, we begin to use a new key schema in preparation for SDKs to manage all key creation in external caches. This allows you to gracefully migrate by double writing to the old key as well.
--statsig-logging: Send events to Statsig to monitor performance and behaviour of proxy.
--statsd-logging: This will emit the same metrics and events using statsd.
--datadog-logging: Same as statsd logging, but uses distribution metrics instead of timing
--force_gcp_profiling_enabled: Enable gcp cloud profiler by force.
--clear-external-datastore-on-unauthorized: When a 401/403 is received, clear external caches (such as redis). Noting that this is a potential reliability trade off.
--clear-datastore-on-unauthorized: When a 401/403 is received, clear external caches (such as redis), as well as, internal caches. Noting that this is a potential reliability trade off.
```

# Configuration
Expand Down
3 changes: 2 additions & 1 deletion Rocket.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[global]
address = "0.0.0.0"
address = "127.0.0.1"
port = 8001
limits = { json = "5 MiB", string = "5 MiB" }
log_level = "critical"
workers = 128
Expand Down
8 changes: 8 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -e

# Start Nginx in the background, redirecting output to /dev/null
nginx -g 'daemon off; error_log /dev/stderr error;' > /dev/null 2>&1 &

# Execute the main application
exec statsig_forward_proxy "$@"
47 changes: 47 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
worker_processes auto;
worker_cpu_affinity auto;

events {
worker_connections 1024;
multi_accept on;
use epoll;
}

http {
proxy_cache_path /dev/shm/nginx levels=1:2 keys_zone=download_cache:10m max_size=1024m inactive=1m use_temp_path=off;

server {
listen 8000;
server_name localhost;

# Disable caching for /v1/log_event
location /v1/log_event {
proxy_pass http://127.0.0.1:8001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

# Disable caching for this location
proxy_cache off;
}

# Cache everything else
location / {
proxy_pass http://127.0.0.1:8001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

# Enable caching
proxy_cache download_cache;
proxy_cache_methods GET POST;
proxy_cache_key "$request_method$request_uri$http_statsig_api_key$http_accept_encoding$request_body";
proxy_cache_use_stale updating error timeout http_500 http_502 http_503 http_504;
proxy_cache_background_update on;
proxy_cache_valid 200 5s;
proxy_cache_lock on;
}
}
}
1 change: 0 additions & 1 deletion src/datastore/caching/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod disabled_cache;
pub mod in_memory_cache;
pub mod redis_cache;
Loading

0 comments on commit 2ae01d0

Please sign in to comment.