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

feat(stream) nginx directive injections for stream config #4148

Merged
merged 1 commit into from Jan 7, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions kong/conf_loader.lua
Expand Up @@ -39,6 +39,8 @@ local HEADER_KEY_TO_NAME = {
local DYNAMIC_KEY_PREFIXES = {
["nginx_http_directives"] = "nginx_http_",
["nginx_proxy_directives"] = "nginx_proxy_",
["nginx_stream_directives"] = "nginx_stream_",
["nginx_sproxy_directives"] = "nginx_sproxy_",
["nginx_admin_directives"] = "nginx_admin_",
}

Expand Down
4 changes: 2 additions & 2 deletions kong/templates/nginx_kong.lua
Expand Up @@ -110,7 +110,7 @@ server {
> end

# injected nginx_proxy_* directives
> for _, el in ipairs(nginx_proxy_directives) do
> for _, el in ipairs(nginx_proxy_directives) do
$(el.name) $(el.value);
> end

Expand Down Expand Up @@ -211,7 +211,7 @@ server {
> end

# injected nginx_admin_* directives
> for _, el in ipairs(nginx_admin_directives) do
> for _, el in ipairs(nginx_admin_directives) do
$(el.name) $(el.value);
> end

Expand Down
12 changes: 12 additions & 0 deletions kong/templates/nginx_kong_stream.lua
Expand Up @@ -18,6 +18,11 @@ lua_shared_dict stream_kong_cassandra 5m;
> end
lua_shared_dict stream_prometheus_metrics 5m;

# injected nginx_stream_* directives
> for _, el in ipairs(nginx_stream_directives) do
$(el.name) $(el.value);
> end

upstream kong_upstream {
server 0.0.0.1:1;
balancer_by_lua_block {
Expand Down Expand Up @@ -55,12 +60,19 @@ server {
access_log ${{PROXY_ACCESS_LOG}} basic;
error_log ${{PROXY_ERROR_LOG}} ${{LOG_LEVEL}};

# injected nginx_sproxy_* directives
> for _, el in ipairs(nginx_sproxy_directives) do
$(el.name) $(el.value);
> end

> if ssl_preread_enabled then
ssl_preread on;
> end

preread_by_lua_block {
Kong.preread()
}

proxy_pass kong_upstream;

log_by_lua_block {
Expand Down
41 changes: 36 additions & 5 deletions spec/01-unit/002-conf_loader_spec.lua
Expand Up @@ -227,9 +227,22 @@ describe("Configuration loader", function()
plugins = "off",
}))
assert.True(search_directive(conf.nginx_http_directives,
"lua_shared_dict", "custom_cache 5m"))
"variables_hash_bucket_size", '"128"'))
assert.True(search_directive(conf.nginx_stream_directives,
"variables_hash_bucket_size", '"128"'))

assert.True(search_directive(conf.nginx_http_directives,
"large_client_header_buffers", "8 24k"))
"lua_shared_dict", "custom_cache 5m"))
assert.True(search_directive(conf.nginx_stream_directives,
"lua_shared_dict", "custom_cache 5m"))

assert.True(search_directive(conf.nginx_proxy_directives,
"proxy_bind", "127.0.0.1 transparent"))
assert.True(search_directive(conf.nginx_sproxy_directives,
"proxy_bind", "127.0.0.1 transparent"))

assert.True(search_directive(conf.nginx_admin_directives,
"server_tokens", "off"))
end)

it("quotes numeric flexible prefix based configs", function()
Expand All @@ -244,15 +257,33 @@ describe("Configuration loader", function()

it("accepts flexible config values with precedence", function()
local conf = assert(conf_loader("spec/fixtures/nginx-directives.conf", {
["nginx_http_large_client_header_buffers"] = "4 16k",
["nginx_http_variables_hash_bucket_size"] = "256",
["nginx_stream_variables_hash_bucket_size"] = "256",
["nginx_http_lua_shared_dict"] = "custom_cache 2m",
["nginx_stream_lua_shared_dict"] = "custom_cache 2m",
["nginx_proxy_proxy_bind"] = "127.0.0.2 transparent",
["nginx_sproxy_proxy_bind"] = "127.0.0.2 transparent",
["nginx_admin_server_tokens"] = "build",
plugins = "off",
}))

assert.True(search_directive(conf.nginx_http_directives,
"lua_shared_dict", "custom_cache 2m"))
"variables_hash_bucket_size", '"256"'))
assert.True(search_directive(conf.nginx_stream_directives,
"variables_hash_bucket_size", '"256"'))

assert.True(search_directive(conf.nginx_http_directives,
"large_client_header_buffers", "4 16k"))
"lua_shared_dict", "custom_cache 2m"))
assert.True(search_directive(conf.nginx_stream_directives,
"lua_shared_dict", "custom_cache 2m"))

assert.True(search_directive(conf.nginx_proxy_directives,
"proxy_bind", "127.0.0.2 transparent"))
assert.True(search_directive(conf.nginx_sproxy_directives,
"proxy_bind", "127.0.0.2 transparent"))

assert.True(search_directive(conf.nginx_admin_directives,
"server_tokens", "build"))
end)
end)

Expand Down
22 changes: 17 additions & 5 deletions spec/fixtures/custom_nginx.template
Expand Up @@ -61,7 +61,7 @@ http {
lua_shared_dict kong_mock_upstream_loggers 10m;

# injected nginx_http_* directives
> for _, el in ipairs(nginx_http_directives) do
> for _, el in ipairs(nginx_http_directives) do
$(el.name) $(el.value);
> end

Expand Down Expand Up @@ -112,8 +112,8 @@ http {
set_real_ip_from $(trusted_ips[i]);
> end

# injected nginx_proxy_* directives
> for _, el in ipairs(nginx_proxy_directives) do
# injected nginx_proxy_* directives
> for _, el in ipairs(nginx_proxy_directives) do
$(el.name) $(el.value);
> end

Expand Down Expand Up @@ -207,8 +207,8 @@ http {
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
> end

# injected nginx_admin_* directives
> for _, el in ipairs(nginx_admin_directives) do
# injected nginx_admin_* directives
> for _, el in ipairs(nginx_admin_directives) do
$(el.name) $(el.value);
> end

Expand Down Expand Up @@ -478,6 +478,11 @@ stream {
> end
lua_shared_dict stream_prometheus_metrics 5m;

# injected nginx_stream_* directives
> for _, el in ipairs(nginx_stream_directives) do
$(el.name) $(el.value);
> end

upstream kong_upstream {
server 0.0.0.1:1;
balancer_by_lua_block {
Expand Down Expand Up @@ -515,12 +520,19 @@ stream {
access_log logs/access.log basic;
error_log logs/error.log debug;

# injected nginx_sproxy_* directives
> for _, el in ipairs(nginx_sproxy_directives) do
$(el.name) $(el.value);
> end

> if ssl_preread_enabled then
ssl_preread on;
> end

preread_by_lua_block {
Kong.preread()
}

proxy_pass kong_upstream;

log_by_lua_block {
Expand Down
7 changes: 6 additions & 1 deletion spec/fixtures/nginx-directives.conf
@@ -1,2 +1,7 @@
nginx_http_large_client_header_buffers = 8 24k
nginx_http_variables_hash_bucket_size = 128
nginx_stream_variables_hash_bucket_size = 128
nginx_http_lua_shared_dict = custom_cache 5m
nginx_stream_lua_shared_dict = custom_cache 5m
nginx_proxy_proxy_bind = 127.0.0.1 transparent
nginx_sproxy_proxy_bind = 127.0.0.1 transparent
nginx_admin_server_tokens = off