forked from splitio/split-synchronizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
341 lines (280 loc) · 14 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#!/bin/bash
# Environment vars:
#
# Common vars:
# - SPLIT_SYNC_API_KEY Split service API-KEY grabbed from webconsole
# - SPLIT_SYNC_SPLITS_REFRESH_RATE Refresh rate of splits fetcher
# - SPLIT_SYNC_SEGMENTS_REFRESH_RATE Refresh rate of segments fetcher
# - SPLIT_SYNC_IMPRESSIONS_POST_RATE Post rate of impressions recorder
# - SPLIT_SYNC_EVENTS_POST_RATE Post rate of events recorder
# - SPLIT_SYNC_METRICS_POST_RATE Post rate of metrics recorder
# - SPLIT_SYNC_HTTP_TIMEOUT Timeout specifies a time limit for requests
# - SPLIT_SYNC_LOG_DEBUG Enable debug mode: Set as 'on'
# - SPLIT_SYNC_LOG_VERBOSE Enable verbose mode: Set as 'on'
# - SPLIT_SYNC_LOG_STDOUT Enable standard output: Set as 'on'
# - SPLIT_SYNC_LOG_FILE Set the log file
# - SPLIT_SYNC_LOG_FILE_MAX_SIZE Max file log size in bytes
# - SPLIT_SYNC_LOG_BACKUP_COUNT Number of last log files to keep in filesystem
# - SPLIT_SYNC_LOG_SLACK_CHANNEL Set the Slack channel or user
# - SPLIT_SYNC_LOG_SLACK_WEBHOOK Set the Slack webhook url
# - SPLIT_SYNC_IP_ADDRESSES_ENABLED Flag to disable IP addresses and host name from being sent to the Split backend
# - SPLIT_SYNC_STREAMING_ENABLED Flag to enable/disable streaming
# - SPLIT_SYNC_IMPRESSIONS_MODE Set the mode of sending impressions to Split Servers
#
# - SPLIT_SYNC_ADVANCED_PARAMETERS Set custom parameters that are not configured via provided Env vars.
# Sample:
# SPLIT_SYNC_ADVANCED_PARAMETERS="-redis-read-timeout=20 -redis-max-retries=10"
# - SPLIT_SYNC_IMPRESSION_LISTENER_ENDPOINT Custom user HTTP Endpoint where impressions will be posted.
#
# Proxy vars:
# - SPLIT_SYNC_PROXY Enables the proxy mode: Set as 'on'
# - SPLIT_SYNC_PROXY_SDK_APIKEYS List of custom API-KEYs for your SDKs (Comma separated string)
# - SPLIT_SYNC_PROXY_ADMIN_USER HTTP basic auth username for admin endpoints
# - SPLIT_SYNC_PROXY_ADMIN_PASS HTTP basic auth password for admin endpoints
# - SPLIT_SYNC_PROXY_DASHBOARD_TITLE Title to be shown in admin dashboard
# - SPLIT_SYNC_PROXY_IMPRESSIONS_MAX_SIZE Max size, in bytes, to send impressions in proxy mode
# - SPLIT_SYNC_PROXY_EVENTS_MAX_SIZE Max size, in bytes, to send events in proxy mode
#
# Producer vars:
# - SPLIT_SYNC_REDIS_HOST Redis server hostname
# - SPLIT_SYNC_REDIS_PORT Redis Server port
# - SPLIT_SYNC_REDIS_DB Redis DB number
# - SPLIT_SYNC_REDIS_PASS Redis password
# - SPLIT_SYNC_REDIS_PREFIX Redis key prefix
# - SPLIT_SYNC_IMPRESSIONS_PER_POST Number of impressions to send in a POST request
# - SPLIT_SYNC_IMPRESSIONS_THREADS Number of impressions recorder threads
# - SPLIT_SYNC_ADMIN_USER HTTP basic auth username for admin endpoints
# - SPLIT_SYNC_ADMIN_PASS HTTP basic auth password for admin endpoints
# - SPLIT_SYNC_DASHBOARD_TITLE Title to be shown in admin dashboard
# - SPLIT_SYNC_EVENTS_PER_POST Number of events to send in a POST request
# - SPLIT_SYNC_EVENTS_THREADS Number of events recorder threads
# - SPLIT_SYNC_REDIS_SENTINEL_REPLICATION Flag to signal that redis sentinel replication will be used
# - SPLIT_SYNC_REDIS_SENTINEL_MASTER Name of the master node of sentinel cluster
# - SPLIT_SYNC_REDIS_SENTINEL_ADDRESSES Comma-separated list of <HOST:PORT> addresses of redis sentinels
# - SPLIT_SYNC_REDIS_CLUSTER_MODE Flag to signal that redis cluster mode will be used
# - SPLIT_SYNC_REDIS_CLUSTER_NODES Comma-separated list of <HOST:PORT> nodes of redis cluster
# - SPLIT_SYNC_REDIS_CLUSTER_KEYHASHTAG String keyHashTag for redis cluster
# - SPLIT_SYNC_REDIS_TLS Enable TLS Encryption for redis connections
# - SPLIT_SYNC_REDIS_TLS_SERVER_NAME Name of the redis server as it appears in the server certificate (defaults to the host)
# - SPLIT_SYNC_REDIS_TLS_SKIP_NAME_VALIDATION Don't check the server name in the received certificate
# - SPLIT_SYNC_REDIS_TLS_CA_ROOT_CERTS Comma-separated list of CA root certificate file names.
# - SPLIT_SYNC_REDIS_TLS_CLIENT_KEY Path to the client's PEM-encoded private key
# - SPLIT_SYNC_REDIS_TLS_CLIENT_CERTIFICATE Path to the client's certificate with a signed public key.
# - SPLIT_SYNC_REDIS_FORCE_CLEANUP Cleanup redis (DB and prefix only) before starting.
is_true() {
normalized=$(echo "$1" | tr 'A-Z' 'a-z')
case $normalized in
true|on|yes)
return 0
;;
*)
return 1
;;
esac
}
is_false() {
normalized=$(echo $1 | tr 'A-Z' 'a-z')
case $normalized in
false|off|no)
return 0
;;
*)
return 1
;;
esac
}
# COMMON PARAMETERS
PARAMETERS="-api-key=${SPLIT_SYNC_API_KEY}"
if [ ! -z ${SPLIT_SYNC_SPLITS_REFRESH_RATE+x} ]; then
PARAMETERS="${PARAMETERS} -split-refresh-rate=${SPLIT_SYNC_SPLITS_REFRESH_RATE}"
fi
if [ ! -z ${SPLIT_SYNC_SEGMENTS_REFRESH_RATE+x} ]; then
PARAMETERS="${PARAMETERS} -segment-refresh-rate=${SPLIT_SYNC_SEGMENTS_REFRESH_RATE}"
fi
if [ ! -z ${SPLIT_SYNC_IMPRESSIONS_POST_RATE+x} ]; then
PARAMETERS="${PARAMETERS} -impressions-post-rate=${SPLIT_SYNC_IMPRESSIONS_POST_RATE}"
fi
if [ ! -z ${SPLIT_SYNC_EVENTS_POST_RATE+x} ]; then
PARAMETERS="${PARAMETERS} -events-post-rate=${SPLIT_SYNC_EVENTS_POST_RATE}"
fi
if [ ! -z ${SPLIT_SYNC_METRICS_POST_RATE+x} ]; then
PARAMETERS="${PARAMETERS} -metrics-post-rate=${SPLIT_SYNC_METRICS_POST_RATE}"
fi
if [ ! -z ${SPLIT_SYNC_HTTP_TIMEOUT+x} ]; then
PARAMETERS="${PARAMETERS} -http-timeout=${SPLIT_SYNC_HTTP_TIMEOUT}"
fi
if is_true "$SPLIT_SYNC_LOG_DEBUG"; then
PARAMETERS="${PARAMETERS} -log-debug"
elif is_false "$SPLIT_SYNC_LOG_DEBUG"; then
PARAMETERS="${PARAMETERS} -log-debug=false"
fi
if is_true "$SPLIT_SYNC_LOG_VERBOSE"; then
PARAMETERS="${PARAMETERS} -log-verbose"
elif is_false "$SPLIT_SYNC_LOG_VERBOSE"; then
PARAMETERS="${PARAMETERS} -log-verbose=false"
fi
if is_true "$SPLIT_SYNC_LOG_STDOUT"; then
PARAMETERS="${PARAMETERS} -log-stdout"
elif is_false "$SPLIT_SYNC_LOG_STDOUT"; then
PARAMETERS="${PARAMETERS} -log-stdout=false"
fi
if [ ! -z ${SPLIT_SYNC_LOG_FILE+x} ]; then
PARAMETERS="${PARAMETERS} -log-file=${SPLIT_SYNC_LOG_FILE}"
fi
if [ ! -z ${SPLIT_SYNC_LOG_FILE_MAX_SIZE+x} ]; then
PARAMETERS="${PARAMETERS} -log-file-max-size=${SPLIT_SYNC_LOG_FILE_MAX_SIZE}"
fi
if [ ! -z ${SPLIT_SYNC_LOG_BACKUP_COUNT+x} ]; then
PARAMETERS="${PARAMETERS} -log-file-backup-count=${SPLIT_SYNC_LOG_BACKUP_COUNT}"
fi
if [ ! -z ${SPLIT_SYNC_LOG_SLACK_CHANNEL+x} ]; then
PARAMETERS="${PARAMETERS} -log-slack-channel=${SPLIT_SYNC_LOG_SLACK_CHANNEL}"
fi
if [ ! -z ${SPLIT_SYNC_LOG_SLACK_WEBHOOK+x} ]; then
PARAMETERS="${PARAMETERS} -log-slack-webhook-url=${SPLIT_SYNC_LOG_SLACK_WEBHOOK}"
fi
if [ ! -z ${SPLIT_SYNC_IMPRESSION_LISTENER_ENDPOINT+x} ]; then
PARAMETERS="${PARAMETERS} -impression-listener-endpoint=${SPLIT_SYNC_IMPRESSION_LISTENER_ENDPOINT}"
fi
if is_true "$split_sync_ip_addresses_enabled"; then
parameters="${parameters} -ip-addresses-enabled"
elif is_false "$split_sync_ip_addresses_enabled"; then
parameters="${parameters} -ip-addresses-enabled=false"
fi
if is_true "$SPLIT_SYNC_STREAMING_ENABLED"; then
PARAMETERS="${PARAMETERS} -streaming-enabled"
elif is_false "$SPLIT_SYNC_STREAMING_ENABLED"; then
PARAMETERS="${PARAMETERS} -streaming-enabled=false"
fi
if [ ! -z ${SPLIT_SYNC_IMPRESSIONS_MODE+x} ]; then
PARAMETERS="${PARAMETERS} -impressions-mode=${SPLIT_SYNC_IMPRESSIONS_MODE}"
fi
# PROXY MODE ON
if is_true "$SPLIT_SYNC_PROXY";
then
printf "Running in PROXY mode"
PARAMETERS="${PARAMETERS} -proxy"
if [ ! -z ${SPLIT_SYNC_PROXY_SDK_APIKEYS+x} ]; then
PARAMETERS="${PARAMETERS} -proxy-apikeys=${SPLIT_SYNC_PROXY_SDK_APIKEYS}"
fi
if [ ! -z ${SPLIT_SYNC_PROXY_ADMIN_USER+x} ]; then
PARAMETERS="${PARAMETERS} -proxy-admin-username=${SPLIT_SYNC_PROXY_ADMIN_USER}"
fi
if [ ! -z ${SPLIT_SYNC_PROXY_ADMIN_PASS+x} ]; then
PARAMETERS="${PARAMETERS} -proxy-admin-password=${SPLIT_SYNC_PROXY_ADMIN_PASS}"
fi
if [ ! -z ${SPLIT_SYNC_PROXY_DASHBOARD_TITLE+x} ]; then
PARAMETERS="${PARAMETERS} -proxy-dashboard-title=${SPLIT_SYNC_PROXY_DASHBOARD_TITLE}"
fi
if [ ! -z ${SPLIT_SYNC_PROXY_IMPRESSIONS_MAX_SIZE+x} ]; then
PARAMETERS="${PARAMETERS} -proxy-impressions-max-size=${SPLIT_SYNC_PROXY_IMPRESSIONS_MAX_SIZE}"
fi
if [ ! -z ${SPLIT_SYNC_PROXY_EVENTS_MAX_SIZE+x} ]; then
PARAMETERS="${PARAMETERS} -proxy-events-max-size=${SPLIT_SYNC_PROXY_EVENTS_MAX_SIZE}"
fi
#PRODUCER MODE ON
else
printf "Running in PRODUCER mode"
if [ ! -z ${REDIS_TLS_URL+x} ]; then
echo "REDIS_TLS_URL available, using that instead of REDIS_URL"
REDIS_URL=$REDIS_TLS_URL
fi
if [ ! -z ${REDIS_URL+x} ]; then
# Redis URLs starting with `rediss://:` are TLS enabled, while those starting with `redis://:` are not
REDIS_PREFIX=$(echo "$REDIS_URL" | awk -F':' '{ print $1 }')
if [[ "$REDIS_PREFIX" == "rediss" ]]; then
echo "Using Split Synchronizer with Redis TLS"
SPLIT_SYNC_REDIS_TLS=true
elif [[ "$REDIS_PREFIX" == "redis" ]]; then
echo "Using Split Synchronizer without Redis TLS"
SPLIT_SYNC_REDIS_TLS=false
fi
# REDIS_URL is in the form redis://:pass@host:port or rediss://:pass@host:port if using TLS
# Use : as delimiter on REDIS_URL in the form of pass@host, then separate into pass and host
CONNECTION_STRING=$(echo "$REDIS_URL" | awk -F':' '{ print $3 }')
# Use @ as delimiter on CONNECTION_STRING to separate pass@host into pass (1) and host (2)
SPLIT_SYNC_REDIS_PASS=$(echo "$CONNECTION_STRING" | awk -F'@' '{ print $1 }')
PARAMETERS="${PARAMETERS} -redis-pass=${SPLIT_SYNC_REDIS_PASS}"
SPLIT_SYNC_REDIS_HOST=$(echo "$CONNECTION_STRING" | awk -F'@' '{ print $2 }')
echo "Using Redis host $SPLIT_SYNC_REDIS_HOST"
PARAMETERS="${PARAMETERS} -redis-host=${SPLIT_SYNC_REDIS_HOST}"
SPLIT_SYNC_REDIS_PORT=$(echo "$REDIS_URL" | awk -F':' '{ print $4 }')
echo "Using Redis port $SPLIT_SYNC_REDIS_PORT"
PARAMETERS="${PARAMETERS} -redis-port=${SPLIT_SYNC_REDIS_PORT}"
fi
if [ ! -z ${SPLIT_SYNC_REDIS_DB+x} ]; then
PARAMETERS="${PARAMETERS} -redis-db=${SPLIT_SYNC_REDIS_DB}"
fi
if [ ! -z ${SPLIT_SYNC_REDIS_PREFIX+x} ]; then
PARAMETERS="${PARAMETERS} -redis-prefix=${SPLIT_SYNC_REDIS_PREFIX}"
fi
# redis sentinel config
if is_true "$SPLIT_SYNC_REDIS_SENTINEL_REPLICATION"; then
PARAMETERS="${PARAMETERS} -redis-sentinel-replication"
if [ ! -z ${SPLIT_SYNC_REDIS_SENTINEL_MASTER+x} ]; then
PARAMETERS="${PARAMETERS} -redis-sentinel-master=${SPLIT_SYNC_REDIS_SENTINEL_MASTER}"
fi
if [ ! -z ${SPLIT_SYNC_REDIS_SENTINEL_ADDRESSES+x} ]; then
PARAMETERS="${PARAMETERS} -redis-sentinel-addresses=${SPLIT_SYNC_REDIS_SENTINEL_ADDRESSES}"
fi
fi
# redis cluster config
if is_true "$SPLIT_SYNC_REDIS_CLUSTER_MODE"; then
PARAMETERS="${PARAMETERS} -redis-cluster-mode"
if [ ! -z ${SPLIT_SYNC_REDIS_CLUSTER_NODES+x} ]; then
PARAMETERS="${PARAMETERS} -redis-cluster-nodes=${SPLIT_SYNC_REDIS_CLUSTER_NODES}"
fi
if [ ! -z ${SPLIT_SYNC_REDIS_CLUSTER_KEYHASHTAG+x} ]; then
PARAMETERS="${PARAMETERS} -redis-cluster-key-hashtag=${SPLIT_SYNC_REDIS_CLUSTER_KEYHASHTAG}"
fi
fi
# TLS specific config
if is_true "$SPLIT_SYNC_REDIS_TLS"; then
PARAMETERS="${PARAMETERS} -redis-tls"
if [ ! -z ${SPLIT_SYNC_REDIS_TLS_SERVER_NAME+x} ]; then
PARAMETERS="${PARAMETERS} -redis-tls-server-name ${SPLIT_SYNC_REDIS_TLS_SERVER_NAME}"
fi
if is_true "$SPLIT_SYNC_REDIS_TLS_SKIP_NAME_VALIDATION"; then
PARAMETERS="${PARAMETERS} -redis-tls-skip-name-validation"
fi
if [ ! -z ${SPLIT_SYNC_REDIS_TLS_CA_ROOT_CERTS+x} ]; then
PARAMETERS="${PARAMETERS} -redis-tls-ca-certs ${SPLIT_SYNC_REDIS_TLS_CA_ROOT_CERTS}"
fi
if [ ! -z ${SPLIT_SYNC_REDIS_TLS_CLIENT_KEY+x} ]; then
PARAMETERS="${PARAMETERS} -redis-tls-client-key ${SPLIT_SYNC_REDIS_TLS_CLIENT_KEY}"
fi
if [ ! -z ${SPLIT_SYNC_REDIS_TLS_CLIENT_CERTIFICATE+x} ]; then
PARAMETERS="${PARAMETERS} -redis-tls-client-certificate ${SPLIT_SYNC_REDIS_TLS_CLIENT_CERTIFICATE}"
fi
if is_true "$SPLIT_SYNC_REDIS_FORCE_CLEANUP"; then
PARAMETERS="${PARAMETERS} -force-fresh-startup"
elif is_false "$SPLIT_SYNC_REDIS_FORCE_CLEANUP"; then
PARAMETERS="${PARAMETERS} -force-fresh-startup=false"
fi
fi
if [ ! -z ${SPLIT_SYNC_IMPRESSIONS_PER_POST+x} ]; then
PARAMETERS="${PARAMETERS} -impressions-per-post=${SPLIT_SYNC_IMPRESSIONS_PER_POST}"
fi
if [ ! -z ${SPLIT_SYNC_IMPRESSIONS_THREADS+x} ]; then
PARAMETERS="${PARAMETERS} -impressions-threads=${SPLIT_SYNC_IMPRESSIONS_THREADS}"
fi
if [ ! -z ${SPLIT_SYNC_ADMIN_USER+x} ]; then
PARAMETERS="${PARAMETERS} -sync-admin-username=${SPLIT_SYNC_ADMIN_USER}"
fi
if [ ! -z ${SPLIT_SYNC_ADMIN_PASS+x} ]; then
PARAMETERS="${PARAMETERS} -sync-admin-password=${SPLIT_SYNC_ADMIN_PASS}"
fi
if [ ! -z ${SPLIT_SYNC_DASHBOARD_TITLE+x} ]; then
PARAMETERS="${PARAMETERS} -sync-dashboard-title=${SPLIT_SYNC_DASHBOARD_TITLE}"
fi
if [ ! -z ${SPLIT_SYNC_EVENTS_PER_POST+x} ]; then
PARAMETERS="${PARAMETERS} -events-per-post=${SPLIT_SYNC_EVENTS_PER_POST}"
fi
if [ ! -z ${SPLIT_SYNC_EVENTS_THREADS+x} ]; then
PARAMETERS="${PARAMETERS} -events-threads=${SPLIT_SYNC_EVENTS_THREADS}"
fi
fi
if [ ! -z ${SPLIT_SYNC_ADVANCED_PARAMETERS+x} ]; then
PARAMETERS="${PARAMETERS} ${SPLIT_SYNC_ADVANCED_PARAMETERS}"
fi
exec split-sync ${PARAMETERS} -sync-admin-port $PORT