diff options
author | Oto Šťáva <oto.stava@nic.cz> | 2024-03-21 12:17:59 +0100 |
---|---|---|
committer | Aleš Mrázek <ales.mrazek@nic.cz> | 2024-04-15 16:28:37 +0200 |
commit | 5a212e337a56e5b365487cf4d25f907b5c6e42c1 (patch) | |
tree | 8c5f06ce37ca093968920aa5218ab270241c5bea /modules | |
parent | modules/stats: split stats.list() into sub-objects (diff) | |
download | knot-resolver-5a212e337a56e5b365487cf4d25f907b5c6e42c1.tar.xz knot-resolver-5a212e337a56e5b365487cf4d25f907b5c6e42c1.zip |
modules/{stats,http}: fix built-in Prometheus and tests
Diffstat (limited to 'modules')
-rw-r--r-- | modules/http/prometheus.lua | 8 | ||||
-rw-r--r-- | modules/stats/test.integr/kresd_config.j2 | 48 |
2 files changed, 32 insertions, 24 deletions
diff --git a/modules/http/prometheus.lua b/modules/http/prometheus.lua index 3218552f..3164e9d5 100644 --- a/modules/http/prometheus.lua +++ b/modules/http/prometheus.lua @@ -15,8 +15,12 @@ local function merge(t, results, prefix) for _, result in pairs(results) do if type(result) == 'table' then for k, v in pairs(result) do - local val = t[prefix..k] - t[prefix..k] = (val or 0) + v + if type(result) == 'table' then + merge(t, result, prefix..k..'.') + else + local val = t[prefix..k] + t[prefix..k] = (val or 0) + v + end end end end diff --git a/modules/stats/test.integr/kresd_config.j2 b/modules/stats/test.integr/kresd_config.j2 index 872ce2e3..d0707691 100644 --- a/modules/stats/test.integr/kresd_config.j2 +++ b/modules/stats/test.integr/kresd_config.j2 @@ -9,32 +9,36 @@ FWD_TARGET = policy.FORWARD('192.0.2.1') function check_stats(got) log_info(ffi.C.LOG_GRP_TESTS, 'checking if stat values match expected values:') local expected = { - ['answer.cd'] = 2, - ['answer.cached'] = 1, - ['answer.nodata'] = 1, - ['answer.noerror'] = 2, - ['answer.nxdomain'] = 1, - ['answer.servfail'] = 2, - ['answer.edns0'] = 6, - ['answer.ra'] = 6, - ['answer.rd'] = 5, - ['answer.do'] = 1, - ['answer.ad'] = 0, - ['answer.tc'] = 0, - ['answer.aa'] = 0, - ['answer.total'] = 6 + ['answer'] = { + ['cd'] = 2, + ['cached'] = 1, + ['nodata'] = 1, + ['noerror'] = 2, + ['nxdomain'] = 1, + ['servfail'] = 2, + ['edns0'] = 6, + ['ra'] = 6, + ['rd'] = 5, + ['do'] = 1, + ['ad'] = 0, + ['tc'] = 0, + ['aa'] = 0, + ['total'] = 6 + } } print(table_print(expected)) local ok = true - for key, expval in pairs(expected) do - if got[key] ~= expval then - log_info(ffi.C.LOG_GRP_TESTS, - 'ERROR: stats key ' .. key - .. ' has unexpected value' - .. ' (expected ' .. tostring(expval) - .. ' got ' .. tostring(got[key] .. ')')) - ok = false + for sup_key, sup in pairs(expected) do + for sub_key, expval in pairs(sup) do + if got[sup_key][sub_key] ~= expval then + log_info(ffi.C.LOG_GRP_TESTS, + 'ERROR: stats key ' .. key + .. ' has unexpected value' + .. ' (expected ' .. tostring(expval) + .. ' got ' .. tostring(got[key] .. ')')) + ok = false + end end end if ok then |