Skip to content

Commit 2727911

Browse files
authored
examples: Bye, Redis! (Webinar source code.) (#6227)
1 parent c2b7165 commit 2727911

File tree

7 files changed

+295
-0
lines changed

7 files changed

+295
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
version: '2.2'
2+
3+
services:
4+
cube:
5+
image: nginx:latest
6+
ports:
7+
- 4000:4000
8+
volumes:
9+
- ./nginx:/etc/nginx/conf.d
10+
depends_on:
11+
- cube_api_1
12+
- cube_api_2
13+
14+
cube_api_1:
15+
restart: always
16+
image: cubejs/cube:v0.31.67
17+
environment:
18+
- CUBEJS_DB_TYPE=postgres
19+
- CUBEJS_DB_HOST=demo-db-examples.cube.dev
20+
- CUBEJS_DB_PORT=5432
21+
- CUBEJS_DB_NAME=ecom
22+
- CUBEJS_DB_USER=cube
23+
- CUBEJS_DB_PASS=12345
24+
- CUBEJS_CUBESTORE_HOST=cubestore_router
25+
# - CUBEJS_CACHE_AND_QUEUE_DRIVER=cubestore
26+
- CUBEJS_REDIS_URL=redis://redis:6379
27+
- CUBEJS_API_SECRET=SECRET
28+
- CUBEJS_LOG_LEVEL=info
29+
volumes:
30+
- .:/cube/conf
31+
depends_on:
32+
- cubestore_router
33+
- cube_refresh_worker
34+
- redis
35+
36+
cube_api_2:
37+
restart: always
38+
image: cubejs/cube:v0.31.67
39+
environment:
40+
- CUBEJS_DB_TYPE=postgres
41+
- CUBEJS_DB_HOST=demo-db-examples.cube.dev
42+
- CUBEJS_DB_PORT=5432
43+
- CUBEJS_DB_NAME=ecom
44+
- CUBEJS_DB_USER=cube
45+
- CUBEJS_DB_PASS=12345
46+
- CUBEJS_CUBESTORE_HOST=cubestore_router
47+
# - CUBEJS_CACHE_AND_QUEUE_DRIVER=cubestore
48+
- CUBEJS_REDIS_URL=redis://redis:6379
49+
- CUBEJS_API_SECRET=SECRET
50+
- CUBEJS_LOG_LEVEL=info
51+
volumes:
52+
- .:/cube/conf
53+
depends_on:
54+
- cubestore_router
55+
- cube_refresh_worker
56+
- redis
57+
58+
cube_refresh_worker:
59+
restart: always
60+
image: cubejs/cube:v0.31.67
61+
environment:
62+
- CUBEJS_DB_TYPE=postgres
63+
- CUBEJS_DB_HOST=demo-db-examples.cube.dev
64+
- CUBEJS_DB_PORT=5432
65+
- CUBEJS_DB_NAME=ecom
66+
- CUBEJS_DB_USER=cube
67+
- CUBEJS_DB_PASS=12345
68+
- CUBEJS_CUBESTORE_HOST=cubestore_router
69+
# - CUBEJS_CACHE_AND_QUEUE_DRIVER=cubestore
70+
- CUBEJS_REDIS_URL=redis://redis:6379
71+
- CUBEJS_API_SECRET=SECRET
72+
- CUBEJS_LOG_LEVEL=info
73+
- CUBEJS_REFRESH_WORKER=true
74+
volumes:
75+
- .:/cube/conf
76+
depends_on:
77+
- cubestore_router
78+
- redis
79+
80+
cubestore_router:
81+
restart: always
82+
image: cubejs/cubestore:v0.31.67-arm64v8
83+
ports:
84+
- 3306:3306
85+
environment:
86+
- CUBESTORE_WORKERS=cubestore_worker_1:10001,cubestore_worker_2:10002
87+
- CUBESTORE_REMOTE_DIR=/cube/data
88+
- CUBESTORE_META_PORT=9999
89+
- CUBESTORE_SERVER_NAME=cubestore_router:9999
90+
volumes:
91+
- .cubestore:/cube/data
92+
93+
cubestore_worker_1:
94+
restart: always
95+
image: cubejs/cubestore:v0.31.67-arm64v8
96+
environment:
97+
- CUBESTORE_WORKERS=cubestore_worker_1:10001,cubestore_worker_2:10002
98+
- CUBESTORE_SERVER_NAME=cubestore_worker_1:10001
99+
- CUBESTORE_WORKER_PORT=10001
100+
- CUBESTORE_REMOTE_DIR=/cube/data
101+
- CUBESTORE_META_ADDR=cubestore_router:9999
102+
volumes:
103+
- .cubestore:/cube/data
104+
depends_on:
105+
- cubestore_router
106+
107+
cubestore_worker_2:
108+
restart: always
109+
image: cubejs/cubestore:v0.31.67-arm64v8
110+
environment:
111+
- CUBESTORE_WORKERS=cubestore_worker_1:10001,cubestore_worker_2:10002
112+
- CUBESTORE_SERVER_NAME=cubestore_worker_2:10002
113+
- CUBESTORE_WORKER_PORT=10002
114+
- CUBESTORE_REMOTE_DIR=/cube/data
115+
- CUBESTORE_META_ADDR=cubestore_router:9999
116+
volumes:
117+
- .cubestore:/cube/data
118+
depends_on:
119+
- cubestore_router
120+
121+
redis:
122+
image: bitnami/redis:latest
123+
ports:
124+
- 6379:6379
125+
environment:
126+
- ALLOW_EMPTY_PASSWORD=yes
127+
logging:
128+
driver: none

examples/bye-redis/nginx/cube.conf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
upstream cube {
2+
server cube_api_1:4000;
3+
server cube_api_2:4000;
4+
}
5+
6+
server {
7+
listen 4000;
8+
server_name localhost;
9+
10+
location / {
11+
proxy_pass http://cube;
12+
}
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
cubes:
2+
- name: Orders
3+
sql: SELECT * FROM public.orders
4+
5+
measures:
6+
- name: count
7+
type: count
8+
9+
dimensions:
10+
- name: created_at
11+
sql: created_at
12+
type: time

examples/bye-redis/scripts/1.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import http from 'k6/http';
2+
3+
export const options = {
4+
vus: 10,
5+
duration: '5s',
6+
summaryTrendStats: [ 'min', 'med', 'p(95)', 'max' ],
7+
summaryTimeUnit: 'ms'
8+
};
9+
10+
export default function() {
11+
const url = 'http://localhost:4000/cubejs-api/v1/load';
12+
13+
const params = {
14+
headers: {
15+
'Authorization': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjEwMDAwMDAwMDAsImV4cCI6NTAwMDAwMDAwMH0.OHZOpOBVKr-sCwn8sbZ5UFsqI3uCs6e4omT7P6WVMFw',
16+
'Content-Type': 'application/json'
17+
},
18+
};
19+
20+
const payload = {
21+
query: {
22+
measures: [
23+
'Orders.count'
24+
]
25+
}
26+
};
27+
28+
http.post(url, JSON.stringify(payload), params);
29+
}

examples/bye-redis/scripts/2.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import http from 'k6/http';
2+
3+
export const options = {
4+
vus: 10,
5+
duration: '5s',
6+
summaryTrendStats: [ 'min', 'med', 'p(95)', 'max' ],
7+
summaryTimeUnit: 'ms'
8+
};
9+
10+
export default function() {
11+
const url = 'http://localhost:4000/cubejs-api/v1/load';
12+
13+
const params = {
14+
headers: {
15+
'Authorization': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjEwMDAwMDAwMDAsImV4cCI6NTAwMDAwMDAwMH0.OHZOpOBVKr-sCwn8sbZ5UFsqI3uCs6e4omT7P6WVMFw',
16+
'Content-Type': 'application/json'
17+
},
18+
};
19+
20+
const payload = {
21+
query: {
22+
measures: [
23+
'Orders.count'
24+
],
25+
timeDimensions: [ {
26+
dimension: 'Orders.created_at',
27+
granularity: 'month'
28+
} ]
29+
}
30+
};
31+
32+
http.post(url, JSON.stringify(payload), params);
33+
}

examples/bye-redis/scripts/3.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import http from 'k6/http';
2+
3+
export const options = {
4+
vus: 10,
5+
duration: '5s',
6+
summaryTrendStats: [ 'min', 'med', 'p(95)', 'max' ],
7+
summaryTimeUnit: 'ms'
8+
};
9+
10+
export default function() {
11+
const url = 'http://localhost:4000/cubejs-api/v1/load';
12+
13+
const params = {
14+
headers: {
15+
'Authorization': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjEwMDAwMDAwMDAsImV4cCI6NTAwMDAwMDAwMH0.OHZOpOBVKr-sCwn8sbZ5UFsqI3uCs6e4omT7P6WVMFw',
16+
'Content-Type': 'application/json'
17+
},
18+
};
19+
20+
const month1 = Math.floor(Math.random() * 12 + 1);
21+
const month2 = Math.floor(Math.random() * 12 + 1);
22+
23+
const payload = {
24+
query: {
25+
measures: [
26+
'Orders.count'
27+
],
28+
timeDimensions: [ {
29+
dimension: 'Orders.created_at',
30+
granularity: 'month',
31+
dateRange:[
32+
`2020-${month1.toString().padStart(2, '0')}-01`,
33+
`2022-${month2.toString().padStart(2, '0')}-01`
34+
]
35+
} ]
36+
}
37+
};
38+
39+
http.post(url, JSON.stringify(payload), params);
40+
}

examples/bye-redis/scripts/4.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import http from 'k6/http';
2+
3+
export const options = {
4+
vus: 10,
5+
duration: '60s',
6+
summaryTrendStats: [ 'min', 'med', 'p(95)', 'max' ],
7+
summaryTimeUnit: 'ms'
8+
};
9+
10+
export default function() {
11+
const url = 'http://localhost:4000/cubejs-api/v1/load';
12+
13+
const params = {
14+
headers: {
15+
'Authorization': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjEwMDAwMDAwMDAsImV4cCI6NTAwMDAwMDAwMH0.OHZOpOBVKr-sCwn8sbZ5UFsqI3uCs6e4omT7P6WVMFw',
16+
'Content-Type': 'application/json'
17+
},
18+
};
19+
20+
const month1 = Math.floor(Math.random() * 12 + 1);
21+
const month2 = Math.floor(Math.random() * 12 + 1);
22+
23+
const payload = {
24+
query: {
25+
measures: [
26+
'Orders.count'
27+
],
28+
timeDimensions: [ {
29+
dimension: 'Orders.created_at',
30+
granularity: 'month',
31+
dateRange:[
32+
`2020-${month1.toString().padStart(2, '0')}-01`,
33+
`2022-${month2.toString().padStart(2, '0')}-01`
34+
]
35+
} ]
36+
}
37+
};
38+
39+
http.post(url, JSON.stringify(payload), params);
40+
}

0 commit comments

Comments
 (0)