BUG/MINOR: dns: add missing sent counter and parent id to dns counters.

Resolv callbacks are also updated to rely on counters and not on
nameservers.
"show stat domain dns" will now show the parent id (i.e. resolvers
section name).
This commit is contained in:
Emeric Brun 2021-01-04 10:40:46 +01:00 committed by Willy Tarreau
parent 147b3f05b5
commit 50c870e4de
6 changed files with 24 additions and 14 deletions

View File

@ -27,7 +27,7 @@
#include <haproxy/list.h>
#include <haproxy/sample.h>
int act_resolution_cb(struct dns_requester *requester, struct dns_nameserver *nameserver);
int act_resolution_cb(struct dns_requester *requester, struct dns_counters *counters);
int act_resolution_error_cb(struct dns_requester *requester, int error_code);
static inline struct action_kw *action_lookup(struct list *keywords, const char *kw)

View File

@ -219,6 +219,7 @@ struct dns_nameserver {
struct dns_counters {
char *id;
char *pid;
long long sent; /* - queries sent */
long long snd_error; /* - sending errors */
long long valid; /* - valid response */
@ -290,7 +291,7 @@ struct dns_requester {
enum obj_type *owner; /* pointer to the owner (server or dns_srvrq) */
struct dns_resolution *resolution; /* pointer to the owned DNS resolution */
int (*requester_cb)(struct dns_requester *, struct dns_nameserver *); /* requester callback for valid response */
int (*requester_cb)(struct dns_requester *, struct dns_counters *); /* requester callback for valid response */
int (*requester_error_cb)(struct dns_requester *, int); /* requester callback, for error management */
struct list list; /* requester list */

View File

@ -60,7 +60,7 @@ struct server *new_server(struct proxy *proxy);
/* functions related to server name resolution */
int snr_update_srv_status(struct server *s, int has_no_ip);
const char *update_server_fqdn(struct server *server, const char *fqdn, const char *updater, int dns_locked);
int snr_resolution_cb(struct dns_requester *requester, struct dns_nameserver *nameserver);
int snr_resolution_cb(struct dns_requester *requester, struct dns_counters *counters);
int snr_resolution_error_cb(struct dns_requester *requester, int error_code);
struct server *snr_check_ip_callback(struct server *srv, void *ip, unsigned char *ip_family);
struct task *srv_cleanup_idle_connections(struct task *task, void *ctx, unsigned short state);

View File

@ -117,7 +117,7 @@ int check_capture(struct act_rule *rule, struct proxy *px, char **err)
return 1;
}
int act_resolution_cb(struct dns_requester *requester, struct dns_nameserver *nameserver)
int act_resolution_cb(struct dns_requester *requester, struct dns_counters *counters)
{
struct stream *stream;

View File

@ -59,6 +59,8 @@ unsigned int dns_failed_resolutions = 0;
enum {
DNS_STAT_ID,
DNS_STAT_PID,
DNS_STAT_SENT,
DNS_STAT_SND_ERROR,
DNS_STAT_VALID,
DNS_STAT_UPDATE,
@ -78,6 +80,8 @@ enum {
static struct name_desc dns_stats[] = {
[DNS_STAT_ID] = { .name = "id", .desc = "ID" },
[DNS_STAT_PID] = { .name = "pid", .desc = "Parent ID" },
[DNS_STAT_SENT] = { .name = "sent", .desc = "Sent" },
[DNS_STAT_SND_ERROR] = { .name = "send_error", .desc = "Send error" },
[DNS_STAT_VALID] = { .name = "valid", .desc = "Valid" },
[DNS_STAT_UPDATE] = { .name = "update", .desc = "Update" },
@ -100,6 +104,8 @@ static void dns_fill_stats(void *d, struct field *stats)
{
struct dns_counters *counters = d;
stats[DNS_STAT_ID] = mkf_str(FO_CONFIG, counters->id);
stats[DNS_STAT_PID] = mkf_str(FO_CONFIG, counters->pid);
stats[DNS_STAT_SENT] = mkf_u64(FN_GAUGE, counters->sent);
stats[DNS_STAT_SND_ERROR] = mkf_u64(FN_GAUGE, counters->snd_error);
stats[DNS_STAT_VALID] = mkf_u64(FN_GAUGE, counters->valid);
stats[DNS_STAT_UPDATE] = mkf_u64(FN_GAUGE, counters->update);
@ -1865,7 +1871,8 @@ void dns_unlink_resolution(struct dns_requester *requester)
*/
static void dns_resolve_recv(struct dgram_conn *dgram)
{
struct dns_nameserver *ns, *tmpns;
struct dns_nameserver *ns;
struct dns_counters *tmpcounters;
struct dns_resolvers *resolvers;
struct dns_resolution *res;
struct dns_query_item *query;
@ -2039,16 +2046,16 @@ static void dns_resolve_recv(struct dgram_conn *dgram)
report_res_success:
/* Only the 1rst requester s managed by the server, others are
* from the cache */
tmpns = ns;
tmpcounters = ns->counters;
list_for_each_entry(req, &res->requesters, list) {
struct server *s = objt_server(req->owner);
if (s)
HA_SPIN_LOCK(SERVER_LOCK, &s->lock);
req->requester_cb(req, tmpns);
req->requester_cb(req, tmpcounters);
if (s)
HA_SPIN_UNLOCK(SERVER_LOCK, &s->lock);
tmpns = NULL;
tmpcounters = NULL;
}
dns_reset_resolution(res);
@ -2311,6 +2318,7 @@ static int dns_finalize_config(void)
if (ns->extra_counters) {
ns->counters = EXTRA_COUNTERS_GET(ns->extra_counters, &dns_stats_module);
ns->counters->id = ns->id;
ns->counters->pid = ns->resolvers->id;
}
}
@ -2500,6 +2508,7 @@ int dns_allocate_counters(struct list *stat_modules)
if (strcmp(mod->name, "dns") == 0) {
ns->counters = (struct dns_counters *)ns->extra_counters->data + mod->counters_off[COUNTERS_DNS];
ns->counters->id = ns->id;
ns->counters->pid = ns->resolvers->id;
}
}
}

View File

@ -3974,7 +3974,7 @@ int snr_update_srv_status(struct server *s, int has_no_ip)
*
* Must be called with server lock held
*/
int snr_resolution_cb(struct dns_requester *requester, struct dns_nameserver *nameserver)
int snr_resolution_cb(struct dns_requester *requester, struct dns_counters *counters)
{
struct server *s = NULL;
struct dns_resolution *resolution = NULL;
@ -4043,10 +4043,10 @@ int snr_resolution_cb(struct dns_requester *requester, struct dns_nameserver *na
}
save_ip:
if (nameserver) {
nameserver->counters->update++;
if (counters) {
counters->update++;
/* save the first ip we found */
chunk_printf(chk, "%s/%s", nameserver->resolvers->id, nameserver->id);
chunk_printf(chk, "%s/%s", counters->pid, counters->id);
}
else
chunk_printf(chk, "DNS cache");
@ -4057,8 +4057,8 @@ int snr_resolution_cb(struct dns_requester *requester, struct dns_nameserver *na
return 1;
invalid:
if (nameserver) {
nameserver->counters->invalid++;
if (counters) {
counters->invalid++;
goto update_status;
}
snr_update_srv_status(s, has_no_ip);