mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Add btests to cover storage metrics
This commit is contained in:
parent
a0ffe7f748
commit
f73ac7089f
9 changed files with 241 additions and 33 deletions
|
@ -3,4 +3,23 @@ open result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=<opaque of
|
||||||
put result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=<uninitialized>]
|
put result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=<uninitialized>]
|
||||||
get result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=value5678]
|
get result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=value5678]
|
||||||
get result same as inserted, T
|
get result same as inserted, T
|
||||||
|
|
||||||
|
Post-operation metrics:
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backends_opened_total, [], [], 1.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_data_read_bytes_total, [config, type], [server_addr-testing, Storage::STORAGE_BACKEND_REDIS], 34.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_expired_entries_total, [config, type], [server_addr-testing, Storage::STORAGE_BACKEND_REDIS], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, erase, error, Storage::STORAGE_BACKEND_REDIS], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, erase, fail, Storage::STORAGE_BACKEND_REDIS], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, erase, success, Storage::STORAGE_BACKEND_REDIS], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, erase, timeout, Storage::STORAGE_BACKEND_REDIS], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, get, error, Storage::STORAGE_BACKEND_REDIS], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, get, fail, Storage::STORAGE_BACKEND_REDIS], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, get, success, Storage::STORAGE_BACKEND_REDIS], 1.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, get, timeout, Storage::STORAGE_BACKEND_REDIS], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, put, error, Storage::STORAGE_BACKEND_REDIS], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, put, fail, Storage::STORAGE_BACKEND_REDIS], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, put, success, Storage::STORAGE_BACKEND_REDIS], 1.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, put, timeout, Storage::STORAGE_BACKEND_REDIS], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_data_written_bytes_total, [config, type], [server_addr-testing, Storage::STORAGE_BACKEND_REDIS], 18.0
|
||||||
|
|
||||||
close result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=<uninitialized>]
|
close result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=<uninitialized>]
|
||||||
|
|
|
@ -9,5 +9,25 @@ get result same as originally inserted, T
|
||||||
put result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=<uninitialized>]
|
put result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=<uninitialized>]
|
||||||
get result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=value2345]
|
get result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=value2345]
|
||||||
get result same as overwritten, T
|
get result same as overwritten, T
|
||||||
Storage::backend_opened, Storage::STORAGE_BACKEND_REDIS, [serializer=Storage::STORAGE_SERIALIZER_JSON, redis=[server_host=127.0.0.1, server_port=xxxx/tcp, server_unix_socket=<uninitialized>, key_prefix=testing, connect_timeout=5.0 secs, operation_timeout=5.0 secs, username=<uninitialized>, password=<uninitialized>]]
|
get result, [code=Storage::KEY_NOT_FOUND, error_str=<uninitialized>, value=<uninitialized>]
|
||||||
Storage::backend_lost, Storage::STORAGE_BACKEND_REDIS, [serializer=Storage::STORAGE_SERIALIZER_JSON, redis=[server_host=127.0.0.1, server_port=xxxx/tcp, server_unix_socket=<uninitialized>, key_prefix=testing, connect_timeout=5.0 secs, operation_timeout=5.0 secs, username=<uninitialized>, password=<uninitialized>]], Client disconnected
|
Storage::backend_opened, Storage::STORAGE_BACKEND_REDIS, [serializer=Storage::STORAGE_SERIALIZER_JSON, redis=[server_host=127.0.0.1, server_port=XXXX/tcp, server_unix_socket=<uninitialized>, key_prefix=testing, connect_timeout=5.0 secs, operation_timeout=5.0 secs, username=<uninitialized>, password=<uninitialized>]]
|
||||||
|
|
||||||
|
Post-operation metrics:
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backends_opened_total, [], [], 1.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_data_read_bytes_total, [config, type], [server_addr-testing, Storage::STORAGE_BACKEND_REDIS], 102.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_expired_entries_total, [config, type], [server_addr-testing, Storage::STORAGE_BACKEND_REDIS], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, erase, error, Storage::STORAGE_BACKEND_REDIS], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, erase, fail, Storage::STORAGE_BACKEND_REDIS], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, erase, success, Storage::STORAGE_BACKEND_REDIS], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, erase, timeout, Storage::STORAGE_BACKEND_REDIS], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, get, error, Storage::STORAGE_BACKEND_REDIS], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, get, fail, Storage::STORAGE_BACKEND_REDIS], 1.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, get, success, Storage::STORAGE_BACKEND_REDIS], 3.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, get, timeout, Storage::STORAGE_BACKEND_REDIS], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, put, error, Storage::STORAGE_BACKEND_REDIS], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, put, fail, Storage::STORAGE_BACKEND_REDIS], 1.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, put, success, Storage::STORAGE_BACKEND_REDIS], 2.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [server_addr-testing, put, timeout, Storage::STORAGE_BACKEND_REDIS], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_data_written_bytes_total, [config, type], [server_addr-testing, Storage::STORAGE_BACKEND_REDIS], 54.0
|
||||||
|
|
||||||
|
Storage::backend_lost, Storage::STORAGE_BACKEND_REDIS, [serializer=Storage::STORAGE_SERIALIZER_JSON, redis=[server_host=127.0.0.1, server_port=XXXX/tcp, server_unix_socket=<uninitialized>, key_prefix=testing, connect_timeout=5.0 secs, operation_timeout=5.0 secs, username=<uninitialized>, password=<uninitialized>]], Client disconnected
|
||||||
|
|
|
@ -9,4 +9,23 @@ open result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=<opaque of
|
||||||
put result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=<uninitialized>]
|
put result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=<uninitialized>]
|
||||||
get result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=value5678]
|
get result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=value5678]
|
||||||
get result same as inserted, T
|
get result same as inserted, T
|
||||||
|
|
||||||
|
Post-operation metrics:
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backends_opened_total, [], [], 1.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_data_read_bytes_total, [config, type], [test.sqlite-testing, Storage::STORAGE_BACKEND_SQLITE], 18.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_expired_entries_total, [config, type], [test.sqlite-testing, Storage::STORAGE_BACKEND_SQLITE], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, erase, error, Storage::STORAGE_BACKEND_SQLITE], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, erase, fail, Storage::STORAGE_BACKEND_SQLITE], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, erase, success, Storage::STORAGE_BACKEND_SQLITE], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, erase, timeout, Storage::STORAGE_BACKEND_SQLITE], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, get, error, Storage::STORAGE_BACKEND_SQLITE], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, get, fail, Storage::STORAGE_BACKEND_SQLITE], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, get, success, Storage::STORAGE_BACKEND_SQLITE], 1.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, get, timeout, Storage::STORAGE_BACKEND_SQLITE], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, put, error, Storage::STORAGE_BACKEND_SQLITE], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, put, fail, Storage::STORAGE_BACKEND_SQLITE], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, put, success, Storage::STORAGE_BACKEND_SQLITE], 1.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, put, timeout, Storage::STORAGE_BACKEND_SQLITE], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_data_written_bytes_total, [config, type], [test.sqlite-testing, Storage::STORAGE_BACKEND_SQLITE], 18.0
|
||||||
|
|
||||||
closed succesfully
|
closed succesfully
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
|
@ -0,0 +1,24 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
|
open result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=<opaque of BackendHandleVal>]
|
||||||
|
put result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=<uninitialized>]
|
||||||
|
get result 1, [code=Storage::SUCCESS, error_str=<uninitialized>, value=value5678]
|
||||||
|
erase result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=<uninitialized>]
|
||||||
|
get result 2, [code=Storage::KEY_NOT_FOUND, error_str=<uninitialized>, value=<uninitialized>]
|
||||||
|
|
||||||
|
Post-operation metrics:
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backends_opened_total, [], [], 1.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_data_read_bytes_total, [config, type], [test.sqlite-testing, Storage::STORAGE_BACKEND_SQLITE], 18.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_expired_entries_total, [config, type], [test.sqlite-testing, Storage::STORAGE_BACKEND_SQLITE], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, erase, error, Storage::STORAGE_BACKEND_SQLITE], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, erase, fail, Storage::STORAGE_BACKEND_SQLITE], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, erase, success, Storage::STORAGE_BACKEND_SQLITE], 1.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, erase, timeout, Storage::STORAGE_BACKEND_SQLITE], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, get, error, Storage::STORAGE_BACKEND_SQLITE], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, get, fail, Storage::STORAGE_BACKEND_SQLITE], 1.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, get, success, Storage::STORAGE_BACKEND_SQLITE], 1.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, get, timeout, Storage::STORAGE_BACKEND_SQLITE], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, put, error, Storage::STORAGE_BACKEND_SQLITE], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, put, fail, Storage::STORAGE_BACKEND_SQLITE], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, put, success, Storage::STORAGE_BACKEND_SQLITE], 1.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_operation_results_total, [config, operation, result, type], [test.sqlite-testing, put, timeout, Storage::STORAGE_BACKEND_SQLITE], 0.0
|
||||||
|
Telemetry::COUNTER, zeek, zeek_storage_backend_data_written_bytes_total, [config, type], [test.sqlite-testing, Storage::STORAGE_BACKEND_SQLITE], 18.0
|
|
@ -4,16 +4,43 @@
|
||||||
# @TEST-PORT: REDIS_PORT
|
# @TEST-PORT: REDIS_PORT
|
||||||
|
|
||||||
# @TEST-EXEC: btest-bg-run redis-server run-redis-server ${REDIS_PORT%/tcp}
|
# @TEST-EXEC: btest-bg-run redis-server run-redis-server ${REDIS_PORT%/tcp}
|
||||||
# @TEST-EXEC: zeek -b %INPUT > out
|
# @TEST-EXEC: zeek -b %INPUT | sed "s|-${REDIS_PORT%/tcp}-|-XXXX-|g" > out
|
||||||
# @TEST-EXEC: btest-bg-wait -k 0
|
# @TEST-EXEC: btest-bg-wait -k 0
|
||||||
|
|
||||||
# @TEST-EXEC: btest-diff out
|
# @TEST-EXEC: btest-diff out
|
||||||
|
|
||||||
@load base/frameworks/storage/async
|
@load base/frameworks/storage/async
|
||||||
@load base/frameworks/storage/sync
|
|
||||||
@load policy/frameworks/storage/backend/redis
|
@load policy/frameworks/storage/backend/redis
|
||||||
|
@load base/frameworks/telemetry
|
||||||
|
|
||||||
|
# Make sure the telemetry output is in a fixed order.
|
||||||
|
redef running_under_test = T;
|
||||||
|
|
||||||
redef exit_only_after_terminate = T;
|
redef exit_only_after_terminate = T;
|
||||||
|
global b : opaque of Storage::BackendHandle;
|
||||||
|
|
||||||
|
event print_metrics_and_close()
|
||||||
|
{
|
||||||
|
print "";
|
||||||
|
print "Post-operation metrics:";
|
||||||
|
local storage_metrics = Telemetry::collect_metrics("zeek", "storage*");
|
||||||
|
for (_, m in storage_metrics)
|
||||||
|
{
|
||||||
|
print m$opts$metric_type, m$opts$prefix, m$opts$name, m$label_names, m$label_values, m$value;
|
||||||
|
}
|
||||||
|
print "";
|
||||||
|
|
||||||
|
when [] ( local close_res = Storage::Async::close_backend(b) )
|
||||||
|
{
|
||||||
|
print "close result", close_res;
|
||||||
|
terminate();
|
||||||
|
}
|
||||||
|
timeout 5sec
|
||||||
|
{
|
||||||
|
print "close result", close_res;
|
||||||
|
terminate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
event zeek_init()
|
event zeek_init()
|
||||||
{
|
{
|
||||||
|
@ -28,29 +55,20 @@ event zeek_init()
|
||||||
Storage::STORAGE_BACKEND_REDIS, opts, string, string) )
|
Storage::STORAGE_BACKEND_REDIS, opts, string, string) )
|
||||||
{
|
{
|
||||||
print "open result", open_res;
|
print "open result", open_res;
|
||||||
local b = open_res$value;
|
b = open_res$value;
|
||||||
|
|
||||||
when [b, key, value] ( local put_res = Storage::Async::put(b, [ $key=key,
|
when [key, value] ( local put_res = Storage::Async::put(b, [ $key=key,
|
||||||
$value=value ]) )
|
$value=value ]) )
|
||||||
{
|
{
|
||||||
print "put result", put_res;
|
print "put result", put_res;
|
||||||
|
|
||||||
when [b, key, value] ( local get_res = Storage::Async::get(b, key) )
|
when [key, value] ( local get_res = Storage::Async::get(b, key) )
|
||||||
{
|
{
|
||||||
print "get result", get_res;
|
print "get result", get_res;
|
||||||
if ( get_res$code == Storage::SUCCESS && get_res?$value )
|
if ( get_res$code == Storage::SUCCESS && get_res?$value )
|
||||||
print "get result same as inserted", value == ( get_res$value as string );
|
print "get result same as inserted", value == ( get_res$value as string );
|
||||||
|
|
||||||
when [b] ( local close_res = Storage::Async::close_backend(b) )
|
schedule 100 msec { print_metrics_and_close() };
|
||||||
{
|
|
||||||
print "close result", close_res;
|
|
||||||
terminate();
|
|
||||||
}
|
|
||||||
timeout 5sec
|
|
||||||
{
|
|
||||||
print "close request timed out";
|
|
||||||
terminate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
timeout 5sec
|
timeout 5sec
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,13 +4,34 @@
|
||||||
# @TEST-PORT: REDIS_PORT
|
# @TEST-PORT: REDIS_PORT
|
||||||
|
|
||||||
# @TEST-EXEC: btest-bg-run redis-server run-redis-server ${REDIS_PORT%/tcp}
|
# @TEST-EXEC: btest-bg-run redis-server run-redis-server ${REDIS_PORT%/tcp}
|
||||||
# @TEST-EXEC: zeek -b %INPUT | sed 's|=[0-9]*/tcp|=xxxx/tcp|g' > out
|
# @TEST-EXEC: zeek -b %INPUT | sed 's|=[0-9]*/tcp|=XXXX/tcp|g' | sed "s|-${REDIS_PORT%/tcp}-|-XXXX-|g" > out
|
||||||
# @TEST-EXEC: btest-bg-wait -k 0
|
# @TEST-EXEC: btest-bg-wait -k 0
|
||||||
|
|
||||||
# @TEST-EXEC: btest-diff out
|
# @TEST-EXEC: btest-diff out
|
||||||
|
|
||||||
@load base/frameworks/storage/sync
|
@load base/frameworks/storage/sync
|
||||||
@load policy/frameworks/storage/backend/redis
|
@load policy/frameworks/storage/backend/redis
|
||||||
|
@load base/frameworks/telemetry
|
||||||
|
|
||||||
|
# Make sure the telemetry output is in a fixed order.
|
||||||
|
redef running_under_test = T;
|
||||||
|
|
||||||
|
global b : opaque of Storage::BackendHandle;
|
||||||
|
|
||||||
|
event print_metrics_and_close()
|
||||||
|
{
|
||||||
|
print "";
|
||||||
|
print "Post-operation metrics:";
|
||||||
|
local storage_metrics = Telemetry::collect_metrics("zeek", "storage*");
|
||||||
|
for (i in storage_metrics)
|
||||||
|
{
|
||||||
|
local m = storage_metrics[i];
|
||||||
|
print m$opts$metric_type, m$opts$prefix, m$opts$name, m$label_names, m$label_values, m$value;
|
||||||
|
}
|
||||||
|
print "";
|
||||||
|
|
||||||
|
Storage::Sync::close_backend(b);
|
||||||
|
}
|
||||||
|
|
||||||
event Storage::backend_opened(tag: Storage::Backend, config: any) {
|
event Storage::backend_opened(tag: Storage::Backend, config: any) {
|
||||||
print "Storage::backend_opened", tag, config;
|
print "Storage::backend_opened", tag, config;
|
||||||
|
@ -35,7 +56,7 @@ event zeek_init()
|
||||||
local res = Storage::Sync::open_backend(Storage::STORAGE_BACKEND_REDIS, opts, string, string);
|
local res = Storage::Sync::open_backend(Storage::STORAGE_BACKEND_REDIS, opts, string, string);
|
||||||
print "open_result", res;
|
print "open_result", res;
|
||||||
|
|
||||||
local b = res$value;
|
b = res$value;
|
||||||
|
|
||||||
# Put a first value. This should return Storage::SUCCESS.
|
# Put a first value. This should return Storage::SUCCESS.
|
||||||
res = Storage::Sync::put(b, [$key=key, $value=value]);
|
res = Storage::Sync::put(b, [$key=key, $value=value]);
|
||||||
|
@ -67,5 +88,9 @@ event zeek_init()
|
||||||
if ( res$code == Storage::SUCCESS && res?$value )
|
if ( res$code == Storage::SUCCESS && res?$value )
|
||||||
print "get result same as overwritten", value2 == (res$value as string);
|
print "get result same as overwritten", value2 == (res$value as string);
|
||||||
|
|
||||||
Storage::Sync::close_backend(b);
|
# Attempt to get a value that doesn't exist.
|
||||||
|
res = Storage::Sync::get(b, "testing");
|
||||||
|
print "get result", res;
|
||||||
|
|
||||||
|
schedule 100 msec { print_metrics_and_close() };
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,39 @@
|
||||||
|
|
||||||
@load base/frameworks/storage/async
|
@load base/frameworks/storage/async
|
||||||
@load policy/frameworks/storage/backend/sqlite
|
@load policy/frameworks/storage/backend/sqlite
|
||||||
|
@load base/frameworks/telemetry
|
||||||
|
|
||||||
|
# Make sure the telemetry output is in a fixed order.
|
||||||
|
redef running_under_test = T;
|
||||||
|
|
||||||
redef exit_only_after_terminate = T;
|
redef exit_only_after_terminate = T;
|
||||||
|
|
||||||
|
global b : opaque of Storage::BackendHandle;
|
||||||
|
|
||||||
|
event print_metrics_and_close()
|
||||||
|
{
|
||||||
|
print "";
|
||||||
|
print "Post-operation metrics:";
|
||||||
|
local storage_metrics = Telemetry::collect_metrics("zeek", "storage*");
|
||||||
|
for (i in storage_metrics)
|
||||||
|
{
|
||||||
|
local m = storage_metrics[i];
|
||||||
|
print m$opts$metric_type, m$opts$prefix, m$opts$name, m$label_names, m$label_values, m$value;
|
||||||
|
}
|
||||||
|
print "";
|
||||||
|
|
||||||
|
when [] ( local close_res = Storage::Async::close_backend(b) )
|
||||||
|
{
|
||||||
|
print "closed succesfully";
|
||||||
|
terminate();
|
||||||
|
}
|
||||||
|
timeout 5sec
|
||||||
|
{
|
||||||
|
print "close request timed out";
|
||||||
|
terminate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
event Storage::backend_opened(tag: Storage::Backend, config: any) {
|
event Storage::backend_opened(tag: Storage::Backend, config: any) {
|
||||||
print "Storage::backend_opened", tag, config;
|
print "Storage::backend_opened", tag, config;
|
||||||
}
|
}
|
||||||
|
@ -28,29 +58,20 @@ event zeek_init()
|
||||||
Storage::STORAGE_BACKEND_SQLITE, opts, string, string) )
|
Storage::STORAGE_BACKEND_SQLITE, opts, string, string) )
|
||||||
{
|
{
|
||||||
print "open result", open_res;
|
print "open result", open_res;
|
||||||
local b = open_res$value;
|
b = open_res$value;
|
||||||
|
|
||||||
when [b, key, value] ( local put_res = Storage::Async::put(b, [ $key=key,
|
when [key, value] ( local put_res = Storage::Async::put(b, [ $key=key,
|
||||||
$value=value ]) )
|
$value=value ]) )
|
||||||
{
|
{
|
||||||
print "put result", put_res;
|
print "put result", put_res;
|
||||||
|
|
||||||
when [b, key, value] ( local get_res = Storage::Async::get(b, key) )
|
when [key, value] ( local get_res = Storage::Async::get(b, key) )
|
||||||
{
|
{
|
||||||
print "get result", get_res;
|
print "get result", get_res;
|
||||||
if ( get_res$code == Storage::SUCCESS && get_res?$value )
|
if ( get_res$code == Storage::SUCCESS && get_res?$value )
|
||||||
print "get result same as inserted", value == ( get_res$value as string );
|
print "get result same as inserted", value == ( get_res$value as string );
|
||||||
|
|
||||||
when [b] ( local close_res = Storage::Async::close_backend(b) )
|
schedule 100 msec { print_metrics_and_close() };
|
||||||
{
|
|
||||||
print "closed succesfully";
|
|
||||||
terminate();
|
|
||||||
}
|
|
||||||
timeout 5sec
|
|
||||||
{
|
|
||||||
print "close request timed out";
|
|
||||||
terminate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
timeout 5sec
|
timeout 5sec
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
# @TEST-DOC: Test metrics for storage/sqlite in a sync context
|
||||||
|
# @TEST-EXEC: zeek -b %INPUT > out
|
||||||
|
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
|
||||||
|
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
|
||||||
|
|
||||||
|
@load base/frameworks/telemetry
|
||||||
|
@load base/frameworks/storage/sync
|
||||||
|
@load policy/frameworks/storage/backend/sqlite
|
||||||
|
|
||||||
|
# Make sure the telemetry output is in a fixed order.
|
||||||
|
redef running_under_test = T;
|
||||||
|
|
||||||
|
global b : opaque of Storage::BackendHandle;
|
||||||
|
|
||||||
|
event print_metrics_and_close()
|
||||||
|
{
|
||||||
|
print "";
|
||||||
|
print "Post-operation metrics:";
|
||||||
|
local storage_metrics = Telemetry::collect_metrics("zeek", "storage*");
|
||||||
|
for (i in storage_metrics)
|
||||||
|
{
|
||||||
|
local m = storage_metrics[i];
|
||||||
|
print m$opts$metric_type, m$opts$prefix, m$opts$name, m$label_names, m$label_values, m$value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Storage::Sync::close_backend(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
event zeek_init()
|
||||||
|
{
|
||||||
|
# Create a database file in the .tmp directory with a 'testing' table
|
||||||
|
local opts: Storage::BackendOptions;
|
||||||
|
opts$sqlite = [ $database_path="test.sqlite", $table_name="testing" ];
|
||||||
|
|
||||||
|
local key = "key1234";
|
||||||
|
local value = "value5678";
|
||||||
|
|
||||||
|
# Test inserting/retrieving a key/value pair that we know won't be in
|
||||||
|
# the backend yet.
|
||||||
|
local res = Storage::Sync::open_backend(Storage::STORAGE_BACKEND_SQLITE, opts, string, string);
|
||||||
|
print "open result", res;
|
||||||
|
b = res$value;
|
||||||
|
|
||||||
|
res = Storage::Sync::put(b, [$key=key, $value=value]);
|
||||||
|
print "put result", res;
|
||||||
|
|
||||||
|
res = Storage::Sync::get(b, key);
|
||||||
|
print "get result 1", res;
|
||||||
|
|
||||||
|
res = Storage::Sync::erase(b, key);
|
||||||
|
print "erase result", res;
|
||||||
|
|
||||||
|
local res2 = Storage::Sync::get(b, key);
|
||||||
|
print "get result 2", res2;
|
||||||
|
|
||||||
|
# Schedule this part for two reasons:
|
||||||
|
# 1. To let the backend_opened event happen before we print metrics.
|
||||||
|
# 2. To print the metrics before closing so that the page_count and file_size callbacks
|
||||||
|
# run before closing.
|
||||||
|
schedule 100 msecs { print_metrics_and_close() };
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue