Skip to content

Commit

Permalink
Merge !1591: modules/stats add answer.stale
Browse files Browse the repository at this point in the history
  • Loading branch information
vcunat committed Aug 19, 2024
2 parents 380e4d8 + b905135 commit e641138
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------
Expand Down
1 change: 1 addition & 0 deletions daemon/lua/kres-gen-33.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/resolve.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
6 changes: 6 additions & 0 deletions manager/knot_resolver_manager/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ def _parse_resolver_metrics(instance_id: "KresID", metrics: Any) -> Generator[Me
label=("instance_id", sid),
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",
Expand Down
7 changes: 5 additions & 2 deletions modules/serve_stale/serve_stale.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions modules/stats/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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** |
Expand Down
8 changes: 7 additions & 1 deletion modules/stats/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -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));

Expand Down

0 comments on commit e641138

Please sign in to comment.