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

[WIP]: Tarantool 3 #227

Closed
Closed
Changes from 1 commit
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
Prev Previous commit
example: introduce Tarantool 3 cluster
Introduce Tarantool 3 cluster for manual Tarantool 3 dashboard check-up
and screenshot making (for repo, PRs and official pages).

Part of #224
DifferentialOrange committed Jul 5, 2024
commit 3f702f6f6f61109f234b0815a5a79ba05e6aad73
84 changes: 84 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
services:
app:
build:
context: ./example_cluster/tarantool3_project
dockerfile: app.Dockerfile
networks:
tarantool_dashboard_dev:
ports:
- 13301:13301
- 13302:13302
- 13303:13303
- 13304:13304
- 13305:13305
- 8081:8081
- 8082:8082
- 8083:8083
- 8084:8084
- 8085:8085

load_generator:
build:
context: ./example_cluster/tarantool3_project
dockerfile: load.Dockerfile
networks:
tarantool_dashboard_dev:

telegraf:
image: telegraf:1.13-alpine
networks:
tarantool_dashboard_dev:
volumes:
# configure telegraf to work out of the box
- ./example_cluster/telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro

influxdb:
image: influxdb:1.7-alpine
environment:
INFLUXDB_REPORTING_DISABLED: "true"
INFLUXDB_DB: "metrics"
INFLUXDB_ADMIN_USER: "admin"
INFLUXDB_ADMIN_PASSWORD: "admin"
INFLUXDB_USER: "telegraf"
INFLUXDB_USER_PASSWORD: "telegraf"
INFLUXDB_HTTP_AUTH_ENABLED: "true"
networks:
tarantool_dashboard_dev:
ports:
- 8086:8086

prometheus:
image: prom/prometheus:v2.17.2
networks:
tarantool_dashboard_dev:
ports:
- 9090:9090
volumes:
- ./example_cluster/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
- ./example_cluster/prometheus/alerts.yml:/etc/prometheus/alerts.yml

grafana:
image: grafana/grafana:8.1.3
environment:
GF_SECURITY_DISABLE_INITIAL_ADMIN_CREATION: "true"
GF_AUTH_ANONYMOUS_ENABLED: "true"
GF_AUTH_ANONYMOUS_ORG_ROLE: "Admin"
GF_AUTH_DISABLE_SIGNOUT_MENU: "true"
GF_AUTH_DISABLE_LOGIN_FORM: "true"
networks:
tarantool_dashboard_dev:
ports:
- 3000:3000
volumes:
- ./example_cluster/grafana/provisioning:/etc/grafana/provisioning
# Map to different folders to prevent name collision.
- ./tests/Prometheus/dashboard_compiled.json:/usr/lib/dashboards/Prometheus-common/dashboard.json
- ./tests/Prometheus/dashboard_static_compiled.json:/usr/lib/dashboards/Prometheus-static/dashboard.json
- ./tests/Prometheus/dashboard_static_with_instance_variable_compiled.json:/usr/lib/dashboards/Prometheus-static-var/dashboard.json
- ./tests/InfluxDB/dashboard_compiled.json:/usr/lib/dashboards/InfluxDB-common/dashboard.json
- ./tests/InfluxDB/dashboard_static_compiled.json:/usr/lib/dashboards/InfluxDB-static/dashboard.json
- ./tests/InfluxDB/dashboard_static_with_instance_variable_compiled.json:/usr/lib/dashboards/InfluxDB-static-var/dashboard.json

networks:
tarantool_dashboard_dev:
driver: bridge
28 changes: 28 additions & 0 deletions example_cluster/tarantool3_project/app.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM golang:1.22-bullseye

WORKDIR /app

RUN DEBIAN_FRONTEND=noninteractive apt update
RUN DEBIAN_FRONTEND=noninteractive apt install -y git \
cmake \
make \
gcc \
g++ \
unzip \
curl
COPY . .
RUN mkdir -p tmp

RUN curl -L https://tarantool.io/release/3/installer.sh | bash
RUN DEBIAN_FRONTEND=noninteractive apt install -y tarantool tarantool-dev tt

RUN tt init
# Need tt log
RUN DEBIAN_FRONTEND=noninteractive apt install -y git patch
RUN git clone https://github.com/magefile/mage && \
cd mage && \
go run bootstrap.go
RUN tt install tt master

RUN tt rocks make
ENTRYPOINT tt start && tt log -f
122 changes: 122 additions & 0 deletions example_cluster/tarantool3_project/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
credentials:
users:
admin:
password: 'secret'
roles: [super]
replicator:
password: 'secret'
roles: [replication]
storage:
password: 'secret'
roles: [sharding]

sharding:
bucket_count: 3000

groups:
routers:
sharding:
roles: [router]
app:
module: router
roles:
- roles.crud-router
- roles.pseudoapp
roles_cfg:
roles.crud-router:
stats: true
stats_driver: metrics
stats_quantiles: true
replicasets:
routers:
instances:
router:
roles_cfg:
roles.pseudoapp:
listen: 0.0.0.0:8081
iproto:
listen:
- uri: 0.0.0.0:13301
advertise:
peer:
login: replicator
uri: localhost:13301
sharding:
login: storage
uri: localhost:13301
client: localhost:13301
storages:
sharding:
roles: [storage]
roles:
- roles.crud-storage
- roles.pseudoapp
replication:
failover: manual
replicasets:
storages_1:
leader: storage_1_master
instances:
storage_1_master:
roles_cfg:
roles.pseudoapp:
listen: 0.0.0.0:8082
iproto:
listen:
- uri: 0.0.0.0:13302
advertise:
peer:
login: replicator
uri: localhost:13302
sharding:
login: storage
uri: localhost:13302
client: localhost:13302
storage_1_replica:
roles_cfg:
roles.pseudoapp:
listen: 0.0.0.0:8083
iproto:
listen:
- uri: 0.0.0.0:13303
advertise:
peer:
login: replicator
uri: localhost:13303
sharding:
login: storage
uri: localhost:13303
client: localhost:13303
storages_2:
leader: storage_2_master
instances:
storage_2_master:
roles_cfg:
roles.pseudoapp:
listen: 0.0.0.0:8084
iproto:
listen:
- uri: 0.0.0.0:13304
advertise:
peer:
login: replicator
uri: localhost:13304
sharding:
login: storage
uri: localhost:13304
client: localhost:13304
storage_2_replica:
roles_cfg:
roles.pseudoapp:
listen: 0.0.0.0:8085
iproto:
listen:
- uri: 0.0.0.0:13305
advertise:
peer:
login: replicator
uri: localhost:13305
sharding:
login: storage
uri: localhost:13305
client: localhost:13305
713 changes: 713 additions & 0 deletions example_cluster/tarantool3_project/generate_load.lua

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions example_cluster/tarantool3_project/instances.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
router:
storage_1_master:
storage_1_replica:
storage_2_master:
storage_2_replica:
19 changes: 19 additions & 0 deletions example_cluster/tarantool3_project/load.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM ubuntu:22.04

WORKDIR /app

RUN DEBIAN_FRONTEND=noninteractive apt update
RUN DEBIAN_FRONTEND=noninteractive apt install -y git \
cmake \
make \
gcc \
g++ \
unzip \
curl
COPY . .
RUN mkdir -p tmp

RUN curl -L https://tarantool.io/release/3/installer.sh | bash
RUN DEBIAN_FRONTEND=noninteractive apt install -y tarantool

ENTRYPOINT tarantool ./generate_load.lua
143 changes: 143 additions & 0 deletions example_cluster/tarantool3_project/roles/pseudoapp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
local fiber = require('fiber')
local metrics = require('metrics')
local json_exporter = require('metrics.plugins.json')
local prometheus_exporter = require('metrics.plugins.prometheus')

local http_server = require('http.server')

local httpd

local function parse(listen)
local parts = listen:split(':')
return parts[1], tonumber(parts[2])
end

local function validate(cfg)
assert(type(cfg.listen) == 'string')
local host, port = parse(cfg.listen)
assert(type(host) == 'string')
assert(host ~= '')
assert(port ~= 0)
end

local function apply(cfg)
if httpd ~= nil then
return
end

fiber.leak_backtrace_enable()

local host, port = parse(cfg.listen)
httpd = http_server.new(host, port)

httpd:route(
{ method = 'GET', path = '/metrics/prometheus' },
prometheus_exporter.collect_http
)

httpd:route(
{ method = 'GET', path = '/metrics/json' },
function(request)
return request:render({ text = json_exporter.export() })
end
)

local http_middleware = metrics.http_middleware
http_middleware.configure_default_collector('summary')

httpd:route(
{ method = 'GET', path = '/hello' },
http_middleware.v1(
function()
fiber.sleep(0.02)
return { status = 200, body = 'Hello world!' }
end
)
)
httpd:route(
{ method = 'GET', path = '/hell0' },
http_middleware.v1(
function()
fiber.sleep(0.01)
return { status = 400, body = 'Hell0 world!' }
end
)
)
httpd:route(
{ method = 'POST', path = '/goodbye' },
http_middleware.v1(
function()
fiber.sleep(0.005)
return { status = 500, body = 'Goodbye cruel world!' }
end
)
)

httpd:start()

box.watch('box.status', function()
if box.info.ro then
return
end

box.ctl.promote()

local sp = box.schema.space.create('MY_SPACE', { if_not_exists = true })
sp:format({
{ name = 'key', type = 'number', is_nullable = false },
{ name = 'value', type = 'string', is_nullable = false },
})
sp:create_index('pk', { parts = { 'key' }, if_not_exists = true })

local v_sp = box.schema.space.create('MY_VINYL_SPACE', { if_not_exists = true, engine = 'vinyl' })
v_sp:format({
{ name = 'key', type = 'number', is_nullable = false },
{ name = 'value', type = 'string', is_nullable = false },
})
v_sp:create_index('pk', { parts = { 'key' }, if_not_exists = true })

for _, space_name in ipairs({'customers', 'clients'}) do
local space = box.schema.space.create(space_name, {
format = {
{name = 'id', type = 'unsigned'},
{name = 'bucket_id', type = 'unsigned'},
{name = 'name', type = 'string'},
{name = 'age', type = 'number'},
},
if_not_exists = true,
engine = 'memtx',
is_sync = true,
})
-- primary index
space:create_index('id_index', {
parts = {{field = 'id'}},
if_not_exists = true,
})
space:create_index('bucket_id', {
parts = { {field = 'bucket_id'} },
unique = false,
if_not_exists = true,
})
space:create_index('name_index', {
parts = { {field = 'name'} },
unique = false,
if_not_exists = true,
})
end
end)

rawset(_G, 'include_vinyl_count', true)
end

local function stop()
if httpd ~= nil then
httpd:stop()
httpd = nil
end
end

return {
validate = validate,
apply = apply,
stop = stop,
}
22 changes: 22 additions & 0 deletions example_cluster/tarantool3_project/router.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
local clock = require('clock')
local fiber = require('fiber')
local log = require('log')

local vshard = require('vshard')

local TIMEOUT = 60
local DELAY = 0.1

local start = clock.monotonic()
while clock.monotonic() - start < TIMEOUT do
local ok, err = vshard.router.bootstrap({
if_not_bootstrapped = true,
})

if ok then
break
end

log.info(('Router bootstrap error: %s'):format(err))
fiber.sleep(DELAY)
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package = 'tarantool3_project'
version = 'scm-1'
source = {
url = '/dev/null',
}
dependencies = {
'tarantool',
'lua >= 5.1',
'crud == 1.5.2-1',
'metrics == scm-1',
'expirationd == 1.3.1-1',
'http == 1.5.0-1',
}
build = {
type = 'none';
}