summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrantisek Tobias <frantisek.tobias@nic.cz>2024-08-19 17:16:38 +0200
committerVladimír Čunát <vladimir.cunat@nic.cz>2024-08-19 17:16:38 +0200
commitb905135b48b64e034c1ea83cc9e759654b3aa2b3 (patch)
tree9a795530576928cb32024695b804fa9456431bf8
parentMerge !1588: validator: avoid clearing EDE if request didn't actually fail (diff)
downloadknot-resolver-b905135b48b64e034c1ea83cc9e759654b3aa2b3.tar.xz
knot-resolver-b905135b48b64e034c1ea83cc9e759654b3aa2b3.zip
modules/stats: add answer.stale
-rw-r--r--NEWS1
-rw-r--r--daemon/lua/kres-gen-33.lua1
-rw-r--r--lib/resolve.h1
-rw-r--r--manager/knot_resolver_manager/statistics.py6
-rw-r--r--modules/serve_stale/serve_stale.lua7
-rw-r--r--modules/stats/README.rst2
-rw-r--r--modules/stats/stats.c8
7 files changed, 23 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index a9540326..11c4bc45 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@ Improvements
- answer NOTIMPL for meta-types and non-IN RR classes (!1589)
- views: improve interaction with old-style policies (!1576)
+- stats: add stale answer counter 'answer.stale' (!1591)
Bugfixes
--------
diff --git a/daemon/lua/kres-gen-33.lua b/daemon/lua/kres-gen-33.lua
index 6be16bc4..40a03453 100644
--- a/daemon/lua/kres-gen-33.lua
+++ b/daemon/lua/kres-gen-33.lua
@@ -248,6 +248,7 @@ struct kr_request {
ranked_rr_array_t add_selected;
_Bool answ_validated;
_Bool auth_validated;
+ _Bool stale_accounted;
uint8_t rank;
struct kr_rplan rplan;
trace_log_f trace_log;
diff --git a/lib/resolve.h b/lib/resolve.h
index 443fef29..cbc20877 100644
--- a/lib/resolve.h
+++ b/lib/resolve.h
@@ -260,6 +260,7 @@ struct kr_request {
ranked_rr_array_t add_selected;
bool answ_validated; /**< internal to validator; beware of caching, etc. */
bool auth_validated; /**< see answ_validated ^^ ; TODO */
+ bool stale_accounted;
/** Overall rank for the request.
*
diff --git a/manager/knot_resolver_manager/statistics.py b/manager/knot_resolver_manager/statistics.py
index 4a0eb783..ae9d9811 100644
--- a/manager/knot_resolver_manager/statistics.py
+++ b/manager/knot_resolver_manager/statistics.py
@@ -120,6 +120,12 @@ if _prometheus_support:
value=metrics["answer"]["cached"],
)
yield _counter(
+ "resolver_answer_stale",
+ "number of queries that utilized stale data",
+ label=("instance_id", sid),
+ value=metrics["answer"]["stale"],
+ )
+ yield _counter(
"resolver_answer_rcode_noerror",
"number of NOERROR answers",
label=("instance_id", sid),
diff --git a/modules/serve_stale/serve_stale.lua b/modules/serve_stale/serve_stale.lua
index faf07fbe..c1528e80 100644
--- a/modules/serve_stale/serve_stale.lua
+++ b/modules/serve_stale/serve_stale.lua
@@ -8,9 +8,10 @@ local ffi = require('ffi')
M.timeout = 3*sec
M.callback = ffi.cast("kr_stale_cb",
- function (ttl) --, name, type, qry)
+ function (ttl, _, _, qry)
--log_debug(ffi.C.SRVSTALE, ' => called back with TTL: ' .. tostring(ttl))
if ttl + 3600 * 24 > 0 then -- at most one day stale
+ qry.request.stale_accounted = true
return 1
else
return -1
@@ -27,7 +28,9 @@ M.layer = {
local now = ffi.C.kr_now()
local deadline = qry.creation_time_mono + M.timeout
if now > deadline or qry.flags.NO_NS_FOUND then
- log_debug(ffi.C.LOG_GRP_SRVSTALE, ' => no reachable NS, using stale data')
+ log_qry(qry, ffi.C.LOG_GRP_SRVSTALE,
+ ' => no reachable NS, using stale data "%s"',
+ kres.dname2str(qry:name()))
qry.stale_cb = M.callback
-- TODO: probably start the same request that doesn't stale-serve,
-- but first we need some detection of non-interactive / internal requests.
diff --git a/modules/stats/README.rst b/modules/stats/README.rst
index 1def925c..e9258274 100644
--- a/modules/stats/README.rst
+++ b/modules/stats/README.rst
@@ -55,6 +55,8 @@ Built-in counters keep track of number of queries and answers matching specific
+-----------------+----------------------------------+
| answer.cached | queries answered from cache |
+-----------------+----------------------------------+
+| answer.stale | queries that utilized stale data |
++-----------------+----------------------------------+
+-----------------+----------------------------------+
| **Answers categorized by RCODE** |
diff --git a/modules/stats/stats.c b/modules/stats/stats.c
index deed9c94..596847d7 100644
--- a/modules/stats/stats.c
+++ b/modules/stats/stats.c
@@ -37,12 +37,17 @@
#define UPSTREAMS_COUNT 512 /* Size of recent upstreams */
#endif
-/** @cond internal Fixed-size map of predefined metrics. */
+/** @cond internal Fixed-size map of predefined metrics.
+ *
+ * When changing the list, don't forget _parse_resolver_metrics()
+ * in ../../manager/knot_resolver_manager/statistics.py
+ */
#define CONST_METRICS(X) \
X(answer,total) X(answer,noerror) X(answer,nodata) X(answer,nxdomain) X(answer,servfail) \
X(answer,cached) X(answer,1ms) X(answer,10ms) X(answer,50ms) X(answer,100ms) \
X(answer,250ms) X(answer,500ms) X(answer,1000ms) X(answer,1500ms) X(answer,slow) \
X(answer,sum_ms) \
+ X(answer,stale) \
X(answer,aa) X(answer,tc) X(answer,rd) X(answer,ra) X(answer, ad) X(answer,cd) \
X(answer,edns0) X(answer,do) \
X(query,edns) X(query,dnssec) \
@@ -303,6 +308,7 @@ static int collect(kr_layer_t *ctx)
DEPRECATED
use new names metric_answer_edns0 and metric_answer_do
*/
+ stat_const_add(data, metric_answer_stale, param->stale_accounted);
stat_const_add(data, metric_query_edns, knot_pkt_has_edns(param->answer));
stat_const_add(data, metric_query_dnssec, knot_pkt_has_dnssec(param->answer));