Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Routes deletion on config reload (#38).

### Changed

## 0.3.1 - 2025-07-07
Expand Down
7 changes: 5 additions & 2 deletions roles/metrics-export.lua
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ local function disable_server(name)

if server ~= nil then
if server.httpd_name ~= nil then
for path, _ in pairs(server.routes) do
for path in pairs(server.routes) do
server.httpd:delete(path)
end
else
Expand Down Expand Up @@ -402,6 +402,9 @@ local function apply_http(conf)
-- if it isn't in applying config.
table.insert(listen_servers_to_start, http_servers[target.value])
end
elseif target.httpd_name ~= nil then
-- Update httpd value because it could change.
http_servers[target.value].httpd = httpd_role.get_server(target.httpd_name)
end

local server = http_servers[target.value]
Expand All @@ -427,7 +430,7 @@ local function apply_http(conf)

-- Add new routes.
for path, endpoint in pairs(new_routes) do
if old_routes[path] == nil then
if old_routes[path] == nil or httpd.iroutes[path] == nil then
httpd:route({
method = "GET",
path = path,
Expand Down
54 changes: 54 additions & 0 deletions test/integration/reload_config_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local yaml = require('yaml')
local socket = require('socket')
local helpers = require('test.helpers')
local server = require('test.helpers.server')
local http_client = require('http.client'):new()

local t = require('luatest')
local g = t.group()
Expand Down Expand Up @@ -57,6 +58,26 @@ local function change_listen_target_in_config(cg, old_addr, new_addr)
file:close()
end

local function change_http_addr_in_config(cg, new_addr, server_name)
if server_name == nil then
server_name = 'default'
end

local file = fio.open(fio.pathjoin(cg.workdir, 'config.yaml'), {'O_RDONLY'})
t.assert(file ~= nil)

local cfg = file:read()
file:close()

cfg = yaml.decode(cfg)
cfg.groups['group-001'].replicasets['replicaset-001'].
instances.master.roles_cfg['roles.httpd'][server_name].listen = new_addr

file = fio.open(fio.pathjoin(cg.workdir, 'config.yaml'), {'O_CREAT', 'O_WRONLY', 'O_TRUNC'}, tonumber('644', 8))
file:write(yaml.encode(cfg))
file:close()
end

g.test_reload_config_update_addr = function(cg)
cg.server = server:new({
config_file = fio.pathjoin(cg.workdir, 'config.yaml'),
Expand Down Expand Up @@ -100,3 +121,36 @@ g.test_reload_config_global_addr_conflict = function(cg)
function() cg.server:eval("require('config'):reload()") end
)
end

g.test_reload_config_routes_exists = function(cg)
cg.server = server:new({
config_file = fio.pathjoin(cg.workdir, 'config.yaml'),
chdir = cg.workdir,
alias = 'master',
workdir = cg.workdir,
})

cg.server:start({wait_until_ready = true})

local response = http_client:get('localhost:8085/metrics/prometheus')
t.assert_equals(response.status, 200)
t.assert(response.body)

local _, err = cg.server:eval("require('config'):reload()")
t.assert_not(err)

response = http_client:get('localhost:8085/metrics/prometheus')
t.assert_equals(response.status, 200)
t.assert(response.body)

change_http_addr_in_config(cg, 8088)
_, err = cg.server:eval("require('config'):reload()")
t.assert_not(err)

response = http_client:get('localhost:8085/metrics/prometheus')
t.assert_equals(response.status, 595)

response = http_client:get('localhost:8088/metrics/prometheus')
t.assert_equals(response.status, 200)
t.assert(response.body)
end
Loading