feat(apisix): add Cloudron package
- Implements Apache APISIX packaging for Cloudron platform. - Includes Dockerfile, CloudronManifest.json, and start.sh. - Configured to use Cloudron's etcd addon. 🤖 Generated with Gemini CLI Co-Authored-By: Gemini <noreply@google.com>
This commit is contained in:
483
CloudronPackages/APISIX/apisix-source/t/utils/batch-processor.t
Normal file
483
CloudronPackages/APISIX/apisix-source/t/utils/batch-processor.t
Normal file
@@ -0,0 +1,483 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
use t::APISIX 'no_plan';
|
||||
|
||||
log_level('debug');
|
||||
repeat_each(1);
|
||||
no_long_string();
|
||||
no_root_location();
|
||||
run_tests;
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: send invalid arguments for constructor
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local Batch = require("apisix.utils.batch-processor")
|
||||
local config = {
|
||||
max_retry_count = 2,
|
||||
batch_max_size = 1,
|
||||
retry_delay = 0,
|
||||
}
|
||||
local func_to_send = function(elements)
|
||||
return true
|
||||
end
|
||||
local log_buffer, err = Batch:new("", config)
|
||||
|
||||
if log_buffer then
|
||||
log_buffer:push({hello='world'})
|
||||
ngx.say("done")
|
||||
end
|
||||
|
||||
if not log_buffer then
|
||||
ngx.say("failed")
|
||||
end
|
||||
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
failed
|
||||
--- wait: 0.5
|
||||
|
||||
|
||||
|
||||
=== TEST 2: sanity
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local Batch = require("apisix.utils.batch-processor")
|
||||
local func_to_send = function(elements)
|
||||
return true
|
||||
end
|
||||
|
||||
local config = {
|
||||
max_retry_count = 2,
|
||||
batch_max_size = 1,
|
||||
retry_delay = 0,
|
||||
}
|
||||
|
||||
local log_buffer, err = Batch:new(func_to_send, config)
|
||||
|
||||
if not log_buffer then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
log_buffer:push({hello='world'})
|
||||
ngx.say("done")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
done
|
||||
--- error_log
|
||||
Batch Processor[log buffer] successfully processed the entries
|
||||
--- wait: 0.5
|
||||
|
||||
|
||||
|
||||
=== TEST 3: batch processor timeout exceeded
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local Batch = require("apisix.utils.batch-processor")
|
||||
local config = {
|
||||
max_retry_count = 2,
|
||||
batch_max_size = 2,
|
||||
retry_delay = 0,
|
||||
inactive_timeout = 1
|
||||
}
|
||||
local func_to_send = function(elements)
|
||||
return true
|
||||
end
|
||||
local log_buffer, err = Batch:new(func_to_send, config)
|
||||
|
||||
if not log_buffer then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
log_buffer:push({hello='world'})
|
||||
ngx.say("done")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
done
|
||||
--- error_log
|
||||
Batch Processor[log buffer] buffer duration exceeded, activating buffer flush
|
||||
Batch Processor[log buffer] successfully processed the entries
|
||||
--- wait: 3
|
||||
|
||||
|
||||
|
||||
=== TEST 4: batch processor batch max size exceeded
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local Batch = require("apisix.utils.batch-processor")
|
||||
local config = {
|
||||
max_retry_count = 2,
|
||||
batch_max_size = 2,
|
||||
retry_delay = 0,
|
||||
}
|
||||
local func_to_send = function(elements)
|
||||
return true
|
||||
end
|
||||
local log_buffer, err = Batch:new(func_to_send, config)
|
||||
|
||||
if not log_buffer then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
log_buffer:push({hello='world'})
|
||||
log_buffer:push({hello='world'})
|
||||
ngx.say("done")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
done
|
||||
--- no_error_log
|
||||
Batch Processor[log buffer] buffer duration exceeded, activating buffer flush
|
||||
--- error_log
|
||||
Batch Processor[log buffer] batch max size has exceeded
|
||||
Batch Processor[log buffer] successfully processed the entries
|
||||
--- wait: 1
|
||||
|
||||
|
||||
|
||||
=== TEST 5: first failed to process and second try success
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local Batch = require("apisix.utils.batch-processor")
|
||||
local core = require("apisix.core")
|
||||
local retry = false
|
||||
local config = {
|
||||
max_retry_count = 2,
|
||||
batch_max_size = 2,
|
||||
retry_delay = 0,
|
||||
}
|
||||
local func_to_send = function(elements)
|
||||
if not retry then
|
||||
retry = true
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
local log_buffer, err = Batch:new(func_to_send, config)
|
||||
|
||||
if not log_buffer then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
log_buffer:push({hello='world'})
|
||||
log_buffer:push({hello='world'})
|
||||
ngx.say("done")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
done
|
||||
--- error_log
|
||||
Batch Processor[log buffer] failed to process entries
|
||||
Batch Processor[log buffer] successfully processed the entries
|
||||
--- wait: 0.5
|
||||
|
||||
|
||||
|
||||
=== TEST 6: Exceeding max retry count
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local Batch = require("apisix.utils.batch-processor")
|
||||
local config = {
|
||||
max_retry_count = 2,
|
||||
batch_max_size = 2,
|
||||
retry_delay = 0,
|
||||
}
|
||||
local func_to_send = function(elements)
|
||||
return false
|
||||
end
|
||||
local log_buffer, err = Batch:new(func_to_send, config)
|
||||
|
||||
if not log_buffer then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
log_buffer:push({hello='world'})
|
||||
log_buffer:push({hello='world'})
|
||||
ngx.say("done")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
done
|
||||
--- no_error_log
|
||||
Batch Processor[log buffer] buffer duration exceeded, activating buffer flush
|
||||
--- error_log
|
||||
Batch Processor[log buffer] failed to process entries
|
||||
Batch Processor[log buffer] exceeded the max_retry_count
|
||||
--- wait: 0.5
|
||||
|
||||
|
||||
|
||||
=== TEST 7: two batches
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local Batch = require("apisix.utils.batch-processor")
|
||||
local core = require("apisix.core")
|
||||
local count = 0
|
||||
local config = {
|
||||
max_retry_count = 2,
|
||||
batch_max_size = 2,
|
||||
retry_delay = 0,
|
||||
}
|
||||
local func_to_send = function(elements)
|
||||
count = count + 1
|
||||
core.log.info("batch[", count , "] sent")
|
||||
return true
|
||||
end
|
||||
local log_buffer, err = Batch:new(func_to_send, config)
|
||||
|
||||
if not log_buffer then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
log_buffer:push({hello='world'})
|
||||
log_buffer:push({hello='world'})
|
||||
log_buffer:push({hello='world'})
|
||||
log_buffer:push({hello='world'})
|
||||
ngx.say("done")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
done
|
||||
--- no_error_log
|
||||
Batch Processor[log buffer] activating flush due to no activity
|
||||
--- error_log
|
||||
batch[1] sent
|
||||
batch[2] sent
|
||||
--- wait: 0.5
|
||||
|
||||
|
||||
|
||||
=== TEST 8: batch processor retry count 0 and fail processing
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local Batch = require("apisix.utils.batch-processor")
|
||||
local config = {
|
||||
max_retry_count = 0,
|
||||
batch_max_size = 2,
|
||||
retry_delay = 0,
|
||||
}
|
||||
local func_to_send = function(elements)
|
||||
return false
|
||||
end
|
||||
local log_buffer, err = Batch:new(func_to_send, config)
|
||||
|
||||
if not log_buffer then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
log_buffer:push({hello='world'})
|
||||
log_buffer:push({hello='world'})
|
||||
ngx.say("done")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
done
|
||||
--- no_error_log
|
||||
Batch Processor[log buffer] activating flush due to no activity
|
||||
--- error_log
|
||||
Batch Processor[log buffer] exceeded the max_retry_count
|
||||
--- wait: 0.5
|
||||
|
||||
|
||||
|
||||
=== TEST 9: batch processor timeout exceeded
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local Batch = require("apisix.utils.batch-processor")
|
||||
local config = {
|
||||
max_retry_count = 2,
|
||||
batch_max_size = 2,
|
||||
retry_delay = 0,
|
||||
buffer_duration = 60,
|
||||
inactive_timeout = 1,
|
||||
}
|
||||
local func_to_send = function(elements)
|
||||
return true
|
||||
end
|
||||
local log_buffer, err = Batch:new(func_to_send, config)
|
||||
|
||||
if not log_buffer then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
log_buffer:push({hello='world'})
|
||||
ngx.say("done")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
done
|
||||
--- error_log
|
||||
Batch Processor[log buffer] buffer duration exceeded, activating buffer flush
|
||||
Batch Processor[log buffer] successfully processed the entries
|
||||
--- wait: 3
|
||||
|
||||
|
||||
|
||||
=== TEST 10: json encode and log elements
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local Batch = require("apisix.utils.batch-processor")
|
||||
local core = require("apisix.core")
|
||||
local config = {
|
||||
max_retry_count = 2,
|
||||
batch_max_size = 2,
|
||||
retry_delay = 0,
|
||||
}
|
||||
local func_to_send = function(elements)
|
||||
core.log.info(require("toolkit.json").encode(elements))
|
||||
return true
|
||||
end
|
||||
local log_buffer, err = Batch:new(func_to_send, config)
|
||||
|
||||
if not log_buffer then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
log_buffer:push({msg='1'})
|
||||
log_buffer:push({msg='2'})
|
||||
log_buffer:push({msg='3'})
|
||||
log_buffer:push({msg='4'})
|
||||
ngx.say("done")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
done
|
||||
--- no_error_log
|
||||
Batch Processor[log buffer] activating flush due to no activity
|
||||
--- error_log
|
||||
[{"msg":"1"},{"msg":"2"}]
|
||||
[{"msg":"3"},{"msg":"4"}]
|
||||
--- wait: 0.5
|
||||
|
||||
|
||||
|
||||
=== TEST 11: extend timer
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local Batch = require("apisix.utils.batch-processor")
|
||||
local core = require("apisix.core")
|
||||
local config = {
|
||||
max_retry_count = 1,
|
||||
batch_max_size = 3,
|
||||
retry_delay = 0,
|
||||
inactive_timeout = 1
|
||||
}
|
||||
local func_to_send = function(elements)
|
||||
core.log.info(require("toolkit.json").encode(elements))
|
||||
return true
|
||||
end
|
||||
local log_buffer, err = Batch:new(func_to_send, config)
|
||||
|
||||
if not log_buffer then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
log_buffer:push({msg='1'})
|
||||
ngx.sleep(0.3)
|
||||
log_buffer:push({msg='2'})
|
||||
log_buffer:push({msg='3'})
|
||||
log_buffer:push({msg='4'})
|
||||
ngx.say("done")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
done
|
||||
--- no_error_log
|
||||
Batch Processor[log buffer] activating flush due to no activity
|
||||
--- error_log
|
||||
Batch Processor[log buffer] extending buffer timer
|
||||
--- wait: 3
|
||||
|
||||
|
||||
|
||||
=== TEST 12: partially consumed entries
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local Batch = require("apisix.utils.batch-processor")
|
||||
local core = require("apisix.core")
|
||||
local config = {
|
||||
max_retry_count = 1,
|
||||
batch_max_size = 3,
|
||||
retry_delay = 0,
|
||||
inactive_timeout = 1
|
||||
}
|
||||
local func_to_send = function(elements)
|
||||
core.log.info(require("toolkit.json").encode(elements))
|
||||
return false, "error after consuming single entry", 2
|
||||
end
|
||||
local log_buffer, err = Batch:new(func_to_send, config)
|
||||
|
||||
if not log_buffer then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
log_buffer:push({msg='1'})
|
||||
log_buffer:push({msg='2'})
|
||||
log_buffer:push({msg='3'})
|
||||
log_buffer:push({msg='4'})
|
||||
ngx.say("done")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
done
|
||||
--- error_log
|
||||
[{"msg":"1"},{"msg":"2"},{"msg":"3"}]
|
||||
Batch Processor[log buffer] failed to process entries [2/3]: error after consuming single entry
|
||||
[{"msg":"2"},{"msg":"3"}]
|
||||
Batch Processor[log buffer] failed to process entries [1/2]: error after consuming single entry
|
||||
[{"msg":"4"}]
|
||||
--- wait: 2
|
83
CloudronPackages/APISIX/apisix-source/t/utils/rfc5424.t
Normal file
83
CloudronPackages/APISIX/apisix-source/t/utils/rfc5424.t
Normal file
@@ -0,0 +1,83 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
use t::APISIX 'no_plan';
|
||||
|
||||
repeat_each(1);
|
||||
no_long_string();
|
||||
no_root_location();
|
||||
|
||||
add_block_preprocessor(sub {
|
||||
my ($block) = @_;
|
||||
|
||||
if (!defined $block->request) {
|
||||
$block->set_value("request", "GET /t");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: Compatibility testing
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local rfc5424 = require("apisix.utils.rfc5424")
|
||||
local structured_data = {
|
||||
{name = "project", value = "apisix.apache.org"},
|
||||
{name = "logstore", value = "apisix.apache.org"},
|
||||
{name = "access-key-id", value = "apisix.sls.logger"},
|
||||
{name = "access-key-secret", value = "BD274822-96AA-4DA6-90EC-15940FB24444"}
|
||||
}
|
||||
local data = rfc5424.encode("SYSLOG", "INFO", "localhost", "apisix",
|
||||
123456, "hello world", structured_data)
|
||||
ngx.say(data)
|
||||
}
|
||||
}
|
||||
--- response_body eval
|
||||
qr/<46>1.*localhost apisix 123456 - \[logservice project=\"apisix\.apache\.org\" logstore=\"apisix\.apache\.org\" access-key-id=\"apisix\.sls\.logger\" access-key-secret=\"BD274822-96AA-4DA6-90EC-15940FB24444\"\] hello world/
|
||||
|
||||
|
||||
|
||||
=== TEST 2: No structured data test
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local rfc5424 = require("apisix.utils.rfc5424")
|
||||
local data = rfc5424.encode("SYSLOG", "INFO", "localhost", "apisix",
|
||||
123456, "hello world")
|
||||
ngx.say(data)
|
||||
}
|
||||
}
|
||||
--- response_body eval
|
||||
qr/<46>1.*localhost apisix 123456 - - hello world/
|
||||
|
||||
|
||||
|
||||
=== TEST 3: No host and appname test
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local rfc5424 = require("apisix.utils.rfc5424")
|
||||
local data = rfc5424.encode("SYSLOG", "INFO", nil, nil,
|
||||
123456, "hello world")
|
||||
ngx.say(data)
|
||||
}
|
||||
}
|
||||
--- response_body eval
|
||||
qr/<46>1.*- - 123456 - - hello world/
|
Reference in New Issue
Block a user