Skip to content

Commit a623e72

Browse files
authored
Integrate with MaxMind out of the box (#766)
Integrate with MaxMind out of the box
1 parent f885ece commit a623e72

File tree

8 files changed

+68
-2
lines changed

8 files changed

+68
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,6 @@ sentry/requirements.txt
8181
relay/credentials.json
8282
relay/config.yml
8383
symbolicator/config.yml
84+
geoip/GeoIP.conf
85+
geoip/*.mmdb
86+
geoip/.geoipupdate.lock

docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ x-sentry-defaults: &sentry_defaults
3131
volumes:
3232
- 'sentry-data:/data'
3333
- './sentry:/etc/sentry'
34+
- './geoip:/geoip:ro'
3435
x-snuba-defaults: &snuba_defaults
3536
<< : *restart_policy
3637
depends_on:
@@ -126,6 +127,14 @@ services:
126127
# If you have high volume and your search return incomplete results
127128
# You might want to change this to a higher value (and ensure your host has enough memory)
128129
MAX_MEMORY_USAGE_RATIO: 0.3
130+
geoipupdate:
131+
image: 'maxmindinc/geoipupdate:latest'
132+
# Override the entrypoint in order to avoid using envvars for config.
133+
# Futz with settings so we can keep mmdb and conf in same dir on host
134+
# (image looks for them in separate dirs by default).
135+
entrypoint: ['/usr/bin/geoipupdate', '-d', '/sentry', '-f', '/sentry/GeoIP.conf']
136+
volumes:
137+
- './geoip:/sentry'
129138
snuba-api:
130139
<< : *snuba_defaults
131140
# Kafka consumer responsible for feeding events into Clickhouse
@@ -233,6 +242,10 @@ services:
233242
read_only: true
234243
source: ./relay
235244
target: /work/.relay
245+
- type: bind
246+
read_only: true
247+
source: ./geoip
248+
target: /geoip
236249
depends_on:
237250
- kafka
238251
- redis

geoip/GeoLite2-City.mmdb.empty

1.03 KB
Binary file not shown.

install.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@ if [[ ! -f "$RELAY_CREDENTIALS_JSON" ]]; then
325325
echo "Relay credentials written to $RELAY_CREDENTIALS_JSON"
326326
fi
327327

328+
329+
./install/geoip.sh
330+
331+
328332
if [[ "$MINIMIZE_DOWNTIME" ]]; then
329333
# Start the whole setup, except nginx and relay.
330334
$dc up -d --remove-orphans $($dc config --services | grep -v -E '^(nginx|relay)$')

install/geoip.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
3+
if [ ! -f 'install.sh' ]; then echo 'Where are you?'; exit 1; fi
4+
5+
dc="docker-compose --no-ansi"
6+
dcr="$dc run --rm"
7+
8+
9+
install_geoip() {
10+
local mmdb='geoip/GeoLite2-City.mmdb'
11+
local conf='geoip/GeoIP.conf'
12+
local result='Done'
13+
14+
echo "Setting up IP address geolocation ..."
15+
if [[ ! -f "$mmdb" ]]; then
16+
echo -n "Installing (empty) IP address geolocation database ... "
17+
cp "$mmdb.empty" "$mmdb"
18+
echo "done."
19+
else
20+
echo "IP address geolocation database already exists."
21+
fi
22+
23+
if [[ ! -f "$conf" ]]; then
24+
echo "IP address geolocation is not configured for updates."
25+
echo "See https://develop.sentry.dev/self-hosted/geolocation/ for instructions."
26+
result='Error'
27+
else
28+
echo "IP address geolocation is configured for updates."
29+
echo "Updating IP address geolocation database ... "
30+
$dcr geoipupdate
31+
if [ $? -gt 0 ]; then
32+
result='Error'
33+
fi
34+
echo "$result updating IP address geolocation database."
35+
fi
36+
echo "$result setting up IP address geolocation."
37+
}
38+
39+
install_geoip

nginx/nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ http {
4545
proxy_set_header Connection '';
4646
proxy_set_header Host $host;
4747
proxy_set_header X-Real-IP $remote_addr;
48-
proxy_set_header X-Forwarded-For $remote_addr;
48+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
4949
proxy_set_header X-Forwarded-Proto $scheme;
5050
proxy_set_header X-Request-Id $request_id;
5151
proxy_read_timeout 30s;

relay/config.example.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ processing:
1010
- {name: "bootstrap.servers", value: "kafka:9092"}
1111
- {name: "message.max.bytes", value: 50000000} #50MB or bust
1212
redis: redis://redis:6379
13+
geoip_path: "/geoip/GeoLite2-City.mmdb"

sentry/sentry.conf.example.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,15 @@ def get_internal_network():
260260
}
261261
)
262262

263+
#######################
264+
# MaxMind Integration #
265+
#######################
266+
267+
GEOIP_PATH_MMDB = '/geoip/GeoLite2-City.mmdb'
268+
263269
#########################
264270
# Bitbucket Integration #
265-
########################
271+
#########################
266272

267273
# BITBUCKET_CONSUMER_KEY = 'YOUR_BITBUCKET_CONSUMER_KEY'
268274
# BITBUCKET_CONSUMER_SECRET = 'YOUR_BITBUCKET_CONSUMER_SECRET'

0 commit comments

Comments
 (0)