Skip to content

Commit 6d8ec11

Browse files
authored
Merge pull request #2 from nyaruka/master
Up merge with base repository
2 parents 113c0fa + 8f3f439 commit 6d8ec11

11 files changed

+257
-295
lines changed

.travis.yml

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
language: go
22

33
addons:
4-
postgresql: '9.6'
4+
postgresql: '10'
5+
apt:
6+
packages:
7+
- postgresql-10
8+
- postgresql-client-10
59

610
go:
7-
- "1.10"
11+
- "1.11"
12+
13+
env:
14+
global:
15+
- GO111MODULE=on
816

917
before_install:
1018
- wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.3.deb && sudo dpkg -i --force-confnew elasticsearch-6.2.3.deb
1119
- sudo service elasticsearch start
20+
- sudo sed -i -e '/local.*peer/s/postgres/all/' -e 's/peer\|md5/trust/g' /etc/postgresql/*/main/pg_hba.conf
21+
- sudo sed -i 's/port = 5433/port = 5432/' /etc/postgresql/10/main/postgresql.conf
22+
- sudo service postgresql restart 10
1223
- sleep 10
1324

1425
before_script:

CHANGELOG.md

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
v2.0.0
2+
----------
3+
* Ignore value of is_test on contacts
4+
5+
v1.0.27
6+
----------
7+
* update ES shards to match current ES best-practice guidance
8+
9+
v1.0.26
10+
----------
11+
* move to go module, dont ignore any keywords
12+
13+
v1.0.25
14+
----------
15+
* Changes to support both PG 10 and 9.6
16+
117
v1.0.24
218
----------
319
* increase batch size to 500k
@@ -28,7 +44,6 @@ v1.0.18
2844

2945
v1.0.17
3046
----------
31-
3247
* change to number instead of decimal field
3348
* add example not exists query
3449

@@ -51,7 +66,7 @@ v1.0.13
5166
v1.0.12
5267
----------
5368
* add modified_on_mu for sorting / index creation
54-
* add prefix name for index building
69+
* add prefix name for index building
5570

5671
v1.0.11
5772
----------
@@ -99,4 +114,3 @@ v1.0.2
99114
v1.0.1
100115
----------
101116
* Add changelog, move to fancy revving
102-

Gopkg.lock

-129
This file was deleted.

Gopkg.toml

-50
This file was deleted.

README.md

+72-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
Simple service for indexing RapidPro contacts into ElasticSearch.
44

5-
This service can run in two modes:
5+
# Deploying
6+
7+
As Indexer is a go application, it compiles to a binary and that binary along with the config file is all
8+
you need to run it on your server. You can find bundles for each platform in the
9+
[releases directory](https://github.com/nyaruka/rp-indexer/releases). You should only run a single indexer
10+
instance for a deployment.
11+
12+
Indexer can run in two modes:
613

714
1) the default mode, which simply queries the ElasticSearch database, finds the most recently
815
modified contact, then on a schedule queries the `contacts_contact` table on the RapidPro
@@ -14,36 +21,90 @@ all contacts on RapidPro. Once complete, this switches out the alias for the con
1421
with the newly build index. This can be run on a cron (in parallel with the mode above) to rebuild
1522
your index occasionally to get rid of bloat.
1623

17-
## Usage
24+
# Configuration
25+
26+
Indexer uses a tiered configuration system, each option takes precendence over the ones above it:
27+
1. The configuration file
28+
2. Environment variables starting with `INDEXER_`
29+
3. Command line parameters
30+
31+
We recommend running Indexer with no changes to the configuration and no parameters, using only
32+
environment variables to configure it. You can use `% rp-indexer --help` to see a list of the
33+
environment variables and parameters and for more details on each option.
1834

19-
It is recommended to run the service with two environment variables set:
35+
## RapidPro Configuration
36+
37+
For use with RapidPro, you will want to configure these settings:
2038

2139
* `INDEXER_DB`: a URL connection string for your RapidPro database
2240
* `INDEXER_ELASTIC_URL`: the URL for your ElasticSearch endpoint
41+
42+
Recommended settings for error reporting:
43+
44+
* `INDEXER_SENTRY_DSN`: The DSN to use when logging errors to Sentry
45+
46+
# Development
47+
48+
Install Indexer source in your workspace with:
49+
50+
```
51+
go get github.com/nyaruka/rp-indexer
52+
```
53+
54+
Build Indexer with:
55+
56+
```
57+
go build github.com/nyaruka/rp-indexer/cmd/rp-indexer
58+
```
59+
60+
This will create a new executable in your current directory `rp-indexer`
61+
62+
To run the tests you need to create the test database:
63+
64+
```
65+
$ createdb elastic_test
66+
```
67+
68+
To run all of the tests:
69+
70+
```
71+
go test github.com/nyaruka/rp-indexer/... -p=1
72+
```
73+
74+
# Usage
2375

2476
```
2577
Indexes RapidPro contacts to ElasticSearch
2678
2779
Usage of indexer:
80+
-cleanup
81+
whether to remove old indexes after a rebuild
2882
-db string
29-
the connection string for our database (default "postgres://localhost/rapidpro")
83+
the connection string for our database (default "postgres://localhost/rapidpro?sslmode=disable")
3084
-debug-conf
31-
print where config values are coming from
85+
print where config values are coming from
3286
-elastic-url string
33-
the url for our elastic search instance (default "http://localhost:9200")
87+
the url for our elastic search instance (default "http://localhost:9200")
3488
-help
35-
print usage information
89+
print usage information
3690
-index string
37-
the alias for our contact index (default "contacts")
91+
the alias for our contact index (default "contacts")
92+
-log-level string
93+
the log level, one of error, warn, info, debug (default "info")
3894
-poll int
39-
the number of seconds to wait between checking for updated contacts (default 5)
95+
the number of seconds to wait between checking for updated contacts (default 5)
4096
-rebuild
41-
whether to rebuild the index, swapping it when complete, then exiting (default false)
97+
whether to rebuild the index, swapping it when complete, then exiting (default false)
98+
-sentry-dsn string
99+
the sentry configuration to log errors to, if any
42100
43101
Environment variables:
102+
INDEXER_CLEANUP - bool
44103
INDEXER_DB - string
45104
INDEXER_ELASTIC_URL - string
46105
INDEXER_INDEX - string
106+
INDEXER_LOG_LEVEL - string
47107
INDEXER_POLL - int
48108
INDEXER_REBUILD - bool
49-
```
109+
INDEXER_SENTRY_DSN - string
110+
```

go.mod

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module github.com/nyaruka/rp-indexer
2+
3+
require (
4+
github.com/certifi/gocertifi v0.0.0-20180118203423-deb3ae2ef261
5+
github.com/davecgh/go-spew v1.1.0
6+
github.com/evalphobia/logrus_sentry v0.4.5
7+
github.com/fatih/structs v1.0.0
8+
github.com/fortytw2/leaktest v1.3.0 // indirect
9+
github.com/getsentry/raven-go v0.0.0-20180405121644-d1470f50d3a3
10+
github.com/lib/pq v0.0.0-20180327071824-d34b9ff171c2
11+
github.com/mailru/easyjson v0.0.0-20180323154445-8b799c424f57
12+
github.com/naoina/go-stringutil v0.1.0
13+
github.com/naoina/toml v0.1.1
14+
github.com/nyaruka/ezconf v0.2.1
15+
github.com/olivere/elastic v6.1.14+incompatible
16+
github.com/pkg/errors v0.8.0
17+
github.com/pmezard/go-difflib v1.0.0
18+
github.com/sirupsen/logrus v1.0.5
19+
github.com/stretchr/testify v1.2.1
20+
golang.org/x/crypto v0.0.0-20180322175230-88942b9c40a4
21+
golang.org/x/sys v0.0.0-20180326154331-13d03a9a82fb
22+
gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
23+
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
24+
)

0 commit comments

Comments
 (0)