]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
modules/{stats,http}: fix built-in Prometheus and tests
authorOto Šťáva <oto.stava@nic.cz>
Thu, 21 Mar 2024 11:17:59 +0000 (12:17 +0100)
committerAleš Mrázek <ales.mrazek@nic.cz>
Mon, 15 Apr 2024 14:28:37 +0000 (16:28 +0200)
modules/http/prometheus.lua
modules/stats/test.integr/kresd_config.j2

index 3218552fb992dba49693a2a02cbdd1e87517504d..3164e9d5f71fde4c7d23e781ebd6750fbe104e77 100644 (file)
@@ -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
index 872ce2e391139938a6e12ec6d2e0622f9a8ff638..d070769102fcd79f99ecc92488bac533f70ac752 100644 (file)
@@ -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