Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: use a redis cluster #596

Merged
merged 21 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ coverage/
dist/
node_modules/
probes-stats/
test/
14 changes: 4 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ jobs:
NODE_ENV: test

services:
redis:
image: redis/redis-stack-server:latest
ports:
- 16379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5

mariadb:
image: mariadb:10.11.5
ports:
Expand All @@ -45,6 +35,10 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Set up Redis
run: |
cp config/redis/.env.redis ./
docker compose --env-file .env.redis up -d
- name: Build
run: |
npm ci
Expand Down
14 changes: 4 additions & 10 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ jobs:
NODE_ENV: test

services:
redis:
image: redis/redis-stack-server:latest
ports:
- 16379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5

mariadb:
image: mariadb:10.11.5
ports:
Expand All @@ -51,6 +41,10 @@ jobs:
sudo mv daemon.json /etc/docker/
sudo systemctl restart docker
docker restart $(docker ps -aq)
- name: Set up Redis
run: |
cp config/redis/.env.redis ./
docker compose --env-file .env.redis up -d
- name: Build
run: |
npm ci
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ coverage/
dist/
tmp/
config/local*
data/redis
data/DOMAIN_BLACKLIST.json
data/IP_BLACKLIST.json
data/AWS_IP_RANGES.json
Expand All @@ -18,3 +19,4 @@ probes-stats/all-result.csv
probes-stats/all-result.json
.eslintcache
.env
/.env.redis
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ if ! type cygpath > /dev/null 2>&1; then
PATH="$PATH:$(type -ap git | grep 'cmd/git' | sed 's$cmd/git$usr/bin$')"
fi

node_modules/.bin/lint-staged --no-stash --quiet
node_modules/.bin/lint-staged --quiet
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ Most IDEs have plugins integrating the used linter (eslint), including support f
- `SYSTEM_API_KEY={value}` used for integration with the dashboard
- `SERVER_SESSION_COOKIE_SECRET={value}` used to read the shared session cookie
- `DB_CONNECTION_HOST`, `DB_CONNECTION_USER`, `DB_CONNECTION_PASSWORD`, and `DB_CONNECTION_DATABASE` database connection details
- `REDIS_STANDALONE_PERSISTENT_URL`, `REDIS_STANDALONE_NON_PERSISTENT_URL`, `REDIS_CLUSTER_MEASUREMENTS_NODES_0`, `REDIS_CLUSTER_MEASUREMENTS_NODES_1`, `REDIS_CLUSTER_MEASUREMENTS_NODES_2`, and `REDIS_SHARED_OPTIONS_PASSWORD` - redis connection details
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:20-bullseye-slim AS builder
RUN apt-get update -y && apt-get install util-linux curl git -y

ENV NODE_ENV production
ENV NODE_ENV=production

COPY package.json package-lock.json /app/
WORKDIR /app
Expand All @@ -12,7 +12,7 @@ RUN npm run build
FROM node:20-bullseye-slim
RUN apt-get update -y && apt-get install tini util-linux curl -y

ENV NODE_ENV production
ENV NODE_ENV=production

COPY package.json package-lock.json /app/
WORKDIR /app
Expand Down
25 changes: 1 addition & 24 deletions config/custom-environment-variables.cjs
Original file line number Diff line number Diff line change
@@ -1,25 +1,2 @@
const _ = require('lodash');
const df = require('./default.cjs');

function mapEnvConfig (object, prefix = '') {
return _.mapValues(object, (value, key) => {
const currentKey = (prefix ? `${prefix}_` : '') + _.snakeCase(key).toUpperCase();

if (_.isObject(value)) {
return mapEnvConfig(value, currentKey);
}

if (typeof value === 'number' || typeof value === 'boolean') {
return {
__name: currentKey,
__format: typeof value,
};
}

return currentKey;
});
}

const mapped = mapEnvConfig(df);

module.exports = mapped;
module.exports = require('config-mapper-env')(df);
23 changes: 20 additions & 3 deletions config/default.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,26 @@ module.exports = {
},
},
redis: {
url: 'redis://localhost:6379',
socket: {
tls: false,
standalonePersistent: {
url: 'redis://localhost:7001',
},
standaloneNonPersistent: {
url: 'redis://localhost:7002',
},
clusterMeasurements: {
// listing three nodes here is enough, the rest will be discovered automatically
nodes: {
0: 'redis://localhost:7101',
1: 'redis://localhost:7102',
2: 'redis://localhost:7103',
},
options: {},
},
sharedOptions: {
password: 'PASSWORD',
socket: {
tls: false,
},
},
},
db: {
Expand Down
6 changes: 0 additions & 6 deletions config/development.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ module.exports = {
cookieSecret: 'xxx',
},
},
redis: {
url: 'redis://localhost:16379',
socket: {
tls: false,
},
},
db: {
connection: {
port: 13306,
Expand Down
6 changes: 6 additions & 0 deletions config/redis/.env.redis
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# standalone:
REDIS_ARGS="--requirepass PASSWORD"

# cluster:
REDIS_PASSWORD=PASSWORD
REDIS_PUBLIC_IP=127.0.0.1
17 changes: 12 additions & 5 deletions redis/setup.md → config/redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
```

## Config
### Docker config

1. Download redis.conf to /etc/redis/
2. Download zip file with json module to same folder
3. Unzip
4. Restart
Assuming you start in this directory:

```
cp .env.redis ../../
```

Set the redis password and return to the project root. Then:

```
docker compose --env-file .env.redis up -d
```
Loading
Loading