Skip to content

Commit

Permalink
feat(core) upstreams (#1735)
Browse files Browse the repository at this point in the history
* adds loadbalancing on specified targets
* adds service registry
* implements #157
* adds entities: upstreams and targets
* modifies timestamps to millisecond precision (except for the non-related tables when using postgres)
* adds collecting health-data on a per-request basis (unused for now)
  • Loading branch information
Tieske authored and thibaultcha committed Jan 12, 2017
1 parent 8e961d6 commit 2f87c3c
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
13 changes: 13 additions & 0 deletions kong/core/hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ local function invalidate(message_t)

elseif message_t.collection == "ssl_servers_names" then
cache.delete(cache.certificate_key(message_t.entity.name))

elseif message_t.collection == "targets" then
-- targets only append new entries, we're not changing anything
-- but we need to reload the related upstreams target-history, so invalidate
-- that instead of the target
cache.delete(cache.targets_key(message_t.entity.upstream_id))

elseif message_t.collection == "upstreams" then
--we invalidate the list, the individual upstream, and its target history
cache.delete(cache.upstreams_dict_key())
cache.delete(cache.upstream_key(message_t.entity.id))
cache.delete(cache.targets_key(message_t.entity.id))
balancer.invalidate_balancer(message_t.entity.name)
end
end

Expand Down
36 changes: 35 additions & 1 deletion kong/dao/migrations/cassandra.lua
Original file line number Diff line number Diff line change
Expand Up @@ -307,5 +307,39 @@ return {
ALTER TABLE apis DROP https_only;
ALTER TABLE apis DROP http_if_terminated;
]]
}
},
{
name = "2016-09-16-141423_upstreams",
-- Note on the timestamps;
-- The Cassandra timestamps are created in Lua code, and hence ALL entities
-- will now be created in millisecond precision. The existing entries will
-- remain in second precision, but new ones (for ALL entities!) will be
-- in millisecond precision.
-- This differs from the Postgres one where only the new entities (upstreams
-- and targets) will get millisecond precision.
up = [[
CREATE TABLE IF NOT EXISTS upstreams(
id uuid,
name text,
slots int,
orderlist text,
created_at timestamp,
PRIMARY KEY (id)
);
CREATE INDEX IF NOT EXISTS ON upstreams(name);
CREATE TABLE IF NOT EXISTS targets(
id uuid,
target text,
weight int,
upstream_id uuid,
created_at timestamp,
PRIMARY KEY (id)
);
CREATE INDEX IF NOT EXISTS ON targets(upstream_id);
]],
down = [[
DROP TABLE upstreams;
DROP TABLE targets;
]],
},
}
38 changes: 38 additions & 0 deletions kong/dao/migrations/postgres.lua
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,42 @@ return {
ALTER TABLE apis DROP COLUMN IF EXISTS http_if_terminated;
]]
},
{
name = "2016-09-16-141423_upstreams",
-- Note on the timestamps below; these use a precision of milliseconds
-- this differs from the other tables above, as they only use second precision.
-- This differs from the change to the Cassandra entities.
up = [[
CREATE TABLE IF NOT EXISTS upstreams(
id uuid PRIMARY KEY,
name text UNIQUE,
slots int NOT NULL,
orderlist text NOT NULL,
created_at timestamp without time zone default (CURRENT_TIMESTAMP(3) at time zone 'utc')
);
DO $$
BEGIN
IF (SELECT to_regclass('upstreams_name_idx')) IS NULL THEN
CREATE INDEX upstreams_name_idx ON upstreams(name);
END IF;
END$$;
CREATE TABLE IF NOT EXISTS targets(
id uuid PRIMARY KEY,
target text NOT NULL,
weight int NOT NULL,
upstream_id uuid REFERENCES upstreams(id) ON DELETE CASCADE,
created_at timestamp without time zone default (CURRENT_TIMESTAMP(3) at time zone 'utc')
);
DO $$
BEGIN
IF (SELECT to_regclass('targets_target_idx')) IS NULL THEN
CREATE INDEX targets_target_idx ON targets(target);
END IF;
END$$;
]],
down = [[
DROP TABLE upstreams;
DROP TABLE targets;
]],
},
}

0 comments on commit 2f87c3c

Please sign in to comment.