diff options
author | Julius Goryavsky <julius.goryavsky@mariadb.com> | 2022-11-22 12:11:49 +0100 |
---|---|---|
committer | Julius Goryavsky <julius.goryavsky@mariadb.com> | 2022-11-22 12:11:49 +0100 |
commit | d0523998c1e0db9aebc710c0ba26cbde71aba169 (patch) | |
tree | 17cd14e67065c733b949436b9c6ba0b3e83b04f6 | |
parent | b35a048ece4f5dd7c6757d86a303f27187a16117 (diff) | |
download | mariadb-git-bb-10.9-sysprg-hashicorp-stats.tar.gz |
hashicorp vault plugin: added statistics variablesbb-10.9-sysprg-hashicorp-stats
6 files changed, 64 insertions, 20 deletions
diff --git a/mysql-test/include/mtr_check.sql b/mysql-test/include/mtr_check.sql index 5d73d1f59f1..2971bec774d 100644 --- a/mysql-test/include/mtr_check.sql +++ b/mysql-test/include/mtr_check.sql @@ -29,6 +29,7 @@ BEGIN -- that are supposed to change SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE variable_name NOT IN ('timestamp') + AND variable_name not like ('hashicorp_key_management_stat_%') AND variable_name not like "Last_IO_Err*" AND variable_name != 'INNODB_IBUF_MAX_SIZE' AND variable_name != 'INNODB_USE_NATIVE_AIO' diff --git a/plugin/hashicorp_key_management/hashicorp_key_management_plugin.cc b/plugin/hashicorp_key_management/hashicorp_key_management_plugin.cc index 7c72af688e4..8f18053e933 100644 --- a/plugin/hashicorp_key_management/hashicorp_key_management_plugin.cc +++ b/plugin/hashicorp_key_management/hashicorp_key_management_plugin.cc @@ -175,6 +175,11 @@ static clock_t ms_to_ticks (long ms) return ticks + ((clock_t) (ticks_1000 % 1000) >= 500); } +static unsigned long stat_data_reads; +static unsigned long stat_data_hits; +static unsigned long stat_version_reads; +static unsigned long stat_version_hits; + void HCData::cache_add (const KEY_INFO& info, bool update_version) { unsigned int key_id = info.key_id; @@ -190,9 +195,9 @@ void HCData::cache_add (const KEY_INFO& info, bool update_version) #if HASHICORP_DEBUG_LOGGING my_printf_error(ER_UNKNOWN_ERROR, PLUGIN_ERROR_HEADER "cache_add: key_id = %u, key_version = %u, " - "timestamp = %u, update_version = %u, new version = %u", + "timestamp = %lu, update_version = %u, new version = %u", ME_ERROR_LOG_ONLY | ME_NOTE, key_id, key_version, - ver_info.timestamp, (int) update_version, + (unsigned long) ver_info.timestamp, (int) update_version, ver_info.key_version); #endif mtx.unlock(); @@ -206,6 +211,7 @@ unsigned int unsigned int version = key_version; clock_t current_time = clock(); mtx.lock(); + stat_data_reads++; if (key_version == ENCRYPTION_KEY_VERSION_INVALID) { clock_t timestamp; @@ -233,11 +239,12 @@ unsigned int #if HASHICORP_DEBUG_LOGGING my_printf_error(ER_UNKNOWN_ERROR, PLUGIN_ERROR_HEADER "cache_get: key_id = %u, key_version = %u, " - "last version = %u, version timestamp = %u, " - "current time = %u, diff = %u", + "last version = %u, version timestamp = %lu, " + "current time = %lu, diff = %lu", ME_ERROR_LOG_ONLY | ME_NOTE, key_id, key_version, - version, timestamp, current_time, - current_time - timestamp); + version, (unsigned long) timestamp, + (unsigned long) current_time, + (unsigned long) (current_time - timestamp)); #endif if (with_timeouts && current_time - timestamp > cache_max_ver_time) { @@ -265,21 +272,30 @@ unsigned int mtx.unlock(); return ENCRYPTION_KEY_VERSION_INVALID; } + if (with_timeouts && current_time - info.timestamp <= cache_max_time) + { + stat_data_hits++; + } + else + { + version = ENCRYPTION_KEY_VERSION_INVALID; + } mtx.unlock(); #if HASHICORP_DEBUG_LOGGING my_printf_error(ER_UNKNOWN_ERROR, PLUGIN_ERROR_HEADER "cache_get: key_id = %u, key_version = %u, " - "effective version = %u, key data timestamp = %u, " - "current time = %u, diff = %u", + "effective version = %u, key data timestamp = %lu, " + "current time = %lu, diff = %lu", ME_ERROR_LOG_ONLY | ME_NOTE, key_id, key_version, - version, info.timestamp, current_time, - current_time - info.timestamp); + version, (unsigned long) info.timestamp, + (unsigned long) current_time, + (unsigned long) (current_time - info.timestamp)); #endif - unsigned int length= info.length; - if (with_timeouts && current_time - info.timestamp > cache_max_time) + if (version == ENCRYPTION_KEY_VERSION_INVALID) { return ENCRYPTION_KEY_VERSION_INVALID; } + unsigned int length = info.length; unsigned int max_length = *buflen; *buflen = length; if (max_length >= length) @@ -305,6 +321,7 @@ unsigned int HCData::cache_get_version (unsigned int key_id) { unsigned int version; mtx.lock(); + stat_version_reads++; #if HASHICORP_HAVE_EXCEPTIONS try { @@ -322,6 +339,7 @@ unsigned int HCData::cache_get_version (unsigned int key_id) { version = ENCRYPTION_KEY_VERSION_INVALID; } + stat_version_hits++; mtx.unlock(); return version; } @@ -363,11 +381,12 @@ unsigned int HCData::cache_check_version (unsigned int key_id) #if HASHICORP_DEBUG_LOGGING my_printf_error(ER_UNKNOWN_ERROR, PLUGIN_ERROR_HEADER "cache_check_version: key_id = %u, " - "last version = %u, version timestamp = %u, " - "current time = %u, diff = %u", + "last version = %u, version timestamp = %lu, " + "current time = %lu, diff = %lu", ME_ERROR_LOG_ONLY | ME_NOTE, key_id, version, - version, timestamp, current_time, - current_time - timestamp); + version, (unsigned long) timestamp, + (unsigned long) current_time, + (unsigned long) (current_time - timestamp)); #endif if (current_time - timestamp <= cache_max_ver_time) { @@ -466,6 +485,26 @@ static MYSQL_SYSVAR_BOOL(use_cache_on_timeout, use_cache_on_timeout, "use the value taken from the cache", NULL, NULL, 0); +static MYSQL_SYSVAR_ULONG(stat_data_reads, stat_data_reads, + PLUGIN_VAR_READONLY | PLUGIN_VAR_RQCMDARG, + "Number of calls to read the key data", + NULL, NULL, 0, 0, ULONG_MAX, 1); + +static MYSQL_SYSVAR_ULONG(stat_data_hits, stat_data_hits, + PLUGIN_VAR_READONLY | PLUGIN_VAR_RQCMDARG, + "Number of key data reads from the cache", + NULL, NULL, 0, 0, ULONG_MAX, 1); + +static MYSQL_SYSVAR_ULONG(stat_version_reads, stat_version_reads, + PLUGIN_VAR_READONLY | PLUGIN_VAR_RQCMDARG, + "Number of calls to read the key version", + NULL, NULL, 0, 0, ULONG_MAX, 1); + +static MYSQL_SYSVAR_ULONG(stat_version_hits, stat_version_hits, + PLUGIN_VAR_READONLY | PLUGIN_VAR_RQCMDARG, + "Number of key version reads from the cache", + NULL, NULL, 0, 0, ULONG_MAX, 1); + static struct st_mysql_sys_var *settings[] = { MYSQL_SYSVAR(vault_url), MYSQL_SYSVAR(token), @@ -477,6 +516,10 @@ static struct st_mysql_sys_var *settings[] = { MYSQL_SYSVAR(cache_version_timeout), MYSQL_SYSVAR(use_cache_on_timeout), MYSQL_SYSVAR(check_kv_version), + MYSQL_SYSVAR(stat_data_reads), + MYSQL_SYSVAR(stat_data_hits), + MYSQL_SYSVAR(stat_version_reads), + MYSQL_SYSVAR(stat_version_hits), NULL }; diff --git a/plugin/hashicorp_key_management/mysql-test/vault/r/hashicorp_encode.result b/plugin/hashicorp_key_management/mysql-test/vault/r/hashicorp_encode.result index 04ac22b9626..5e72304c6db 100644 --- a/plugin/hashicorp_key_management/mysql-test/vault/r/hashicorp_encode.result +++ b/plugin/hashicorp_key_management/mysql-test/vault/r/hashicorp_encode.result @@ -1,4 +1,4 @@ -SHOW GLOBAL variables LIKE "hashicorp%"; +SHOW GLOBAL variables WHERE (Variable_name LIKE "hashicorp%" AND Variable_name NOT LIKE "hashicorp_key_management_stat_%"); Variable_name Value hashicorp_key_management_cache_timeout 60000 hashicorp_key_management_cache_version_timeout 0 diff --git a/plugin/hashicorp_key_management/mysql-test/vault/r/hashicorp_key_rotation_age.result b/plugin/hashicorp_key_management/mysql-test/vault/r/hashicorp_key_rotation_age.result index 6e06e0f1d30..228cdfd9c9b 100644 --- a/plugin/hashicorp_key_management/mysql-test/vault/r/hashicorp_key_rotation_age.result +++ b/plugin/hashicorp_key_management/mysql-test/vault/r/hashicorp_key_rotation_age.result @@ -1,4 +1,4 @@ -SHOW GLOBAL variables LIKE "hashicorp%"; +SHOW GLOBAL variables WHERE (Variable_name LIKE "hashicorp%" AND Variable_name NOT LIKE "hashicorp_key_management_stat_%"); Variable_name Value hashicorp_key_management_cache_timeout 60000 hashicorp_key_management_cache_version_timeout 0 diff --git a/plugin/hashicorp_key_management/mysql-test/vault/t/hashicorp_encode.test b/plugin/hashicorp_key_management/mysql-test/vault/t/hashicorp_encode.test index 338b3413e77..8aaa0cf5850 100644 --- a/plugin/hashicorp_key_management/mysql-test/vault/t/hashicorp_encode.test +++ b/plugin/hashicorp_key_management/mysql-test/vault/t/hashicorp_encode.test @@ -4,7 +4,7 @@ --source hashicorp_init.inc replace_result $VAULT_ADDR VAULT_ADDR; -SHOW GLOBAL variables LIKE "hashicorp%"; +SHOW GLOBAL variables WHERE (Variable_name LIKE "hashicorp%" AND Variable_name NOT LIKE "hashicorp_key_management_stat_%"); create table t1(c1 bigint not null, b char(200)) engine=innodb encrypted=yes encryption_key_id=1; show create table t1; diff --git a/plugin/hashicorp_key_management/mysql-test/vault/t/hashicorp_key_rotation_age.test b/plugin/hashicorp_key_management/mysql-test/vault/t/hashicorp_key_rotation_age.test index ce99406ab06..954a8f4bc9c 100644 --- a/plugin/hashicorp_key_management/mysql-test/vault/t/hashicorp_key_rotation_age.test +++ b/plugin/hashicorp_key_management/mysql-test/vault/t/hashicorp_key_rotation_age.test @@ -5,7 +5,7 @@ --source hashicorp_init.inc replace_result $VAULT_ADDR VAULT_ADDR; -SHOW GLOBAL variables LIKE "hashicorp%"; +SHOW GLOBAL variables WHERE (Variable_name LIKE "hashicorp%" AND Variable_name NOT LIKE "hashicorp_key_management_stat_%"); --echo # Restart the server with encryption let $default_parameters="--innodb-tablespaces-encryption --innodb_encrypt_tables=ON"; |