map_t map;
struct {
namehash_t *frequent;
- namehash_t *expiring;
} queries;
struct {
addrlist_t q;
{
memcpy(key, &type, sizeof(type));
int key_len = knot_dname_to_wire((uint8_t *)key + sizeof(type), name, KNOT_DNAME_MAXLEN);
- if (key_len > 0) {
- return key_len + sizeof(type);
+ if (key_len < 0) {
+ return kr_error(key_len);
}
- return key_len;
+ return key_len + sizeof(type);
}
static void collect_sample(struct stat_data *data, struct kr_rplan *rplan, knot_pkt_t *pkt)
/* Sample key = {[2] type, [1-255] owner} */
char key[sizeof(uint16_t) + KNOT_DNAME_MAXLEN];
for (size_t i = 0; i < rplan->resolved.len; ++i) {
- /* Sample queries leading to iteration or expiring */
+ /* Sample queries leading to iteration */
struct kr_query *qry = rplan->resolved.at[i];
- if ((qry->flags.CACHED) && !(qry->flags.EXPIRING)) {
+ if (qry->flags.CACHED) {
continue;
}
- int key_len = collect_key(key, qry->sname, qry->stype);
- if (qry->flags.EXPIRING) {
- unsigned *count = lru_get_new(data->queries.expiring, key, key_len);
- if (count)
- *count += 1;
/* Consider 1 in N for frequent sampling. */
- } else if (kr_rand_uint(FREQUENT_PSAMPLE) <= 1) {
+ if (kr_rand_uint(FREQUENT_PSAMPLE) <= 1) {
+ int key_len = collect_key(key, qry->sname, qry->stype);
+ if (key_len < 0) {
+ assert(false);
+ continue;
+ }
unsigned *count = lru_get_new(data->queries.frequent, key, key_len);
if (count)
*count += 1;
return NULL;
}
-static char* dump_expiring(void *env, struct kr_module *module, const char *args)
-{
- struct stat_data *data = module->data;
- return dump_list(env, module, args, data->queries.expiring);
-}
-
-static char* clear_expiring(void *env, struct kr_module *module, const char *args)
-{
- struct stat_data *data = module->data;
- lru_reset(data->queries.expiring);
- return NULL;
-}
-
static char* dump_upstreams(void *env, struct kr_module *module, const char *args)
{
struct stat_data *data = module->data;
data->map = map_make();
module->data = data;
lru_create(&data->queries.frequent, FREQUENT_COUNT, NULL, NULL);
- lru_create(&data->queries.expiring, FREQUENT_COUNT, NULL, NULL);
/* Initialize ring buffer of recently visited upstreams */
array_init(data->upstreams.q);
if (array_reserve(data->upstreams.q, UPSTREAMS_COUNT) != 0) {
if (data) {
map_clear(&data->map);
lru_free(data->queries.frequent);
- lru_free(data->queries.expiring);
array_clear(data->upstreams.q);
free(data);
}
{ &stats_list, "list", "List observed metrics.", },
{ &dump_frequent, "frequent", "List most frequent queries.", },
{ &clear_frequent,"clear_frequent", "Clear frequent queries log.", },
- { &dump_expiring, "expiring", "List expiring records.", },
- { &clear_expiring,"clear_expiring", "Clear expiring records log.", },
{ &dump_upstreams, "upstreams", "List recently seen authoritatives.", },
{ NULL, NULL, NULL }
};