From 50c870e4de5e8e5fa51e33b54edb6c3f4fd87e85 Mon Sep 17 00:00:00 2001 From: Emeric Brun Date: Mon, 4 Jan 2021 10:40:46 +0100 Subject: [PATCH] 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). --- include/haproxy/action.h | 2 +- include/haproxy/dns-t.h | 3 ++- include/haproxy/server.h | 2 +- src/action.c | 2 +- src/dns.c | 17 +++++++++++++---- src/server.c | 12 ++++++------ 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/include/haproxy/action.h b/include/haproxy/action.h index 709d17c5f..edd34f1d3 100644 --- a/include/haproxy/action.h +++ b/include/haproxy/action.h @@ -27,7 +27,7 @@ #include #include -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) diff --git a/include/haproxy/dns-t.h b/include/haproxy/dns-t.h index 191edf6ae..c9199045c 100644 --- a/include/haproxy/dns-t.h +++ b/include/haproxy/dns-t.h @@ -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 */ diff --git a/include/haproxy/server.h b/include/haproxy/server.h index 5ca0fe90d..a19d76922 100644 --- a/include/haproxy/server.h +++ b/include/haproxy/server.h @@ -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); diff --git a/src/action.c b/src/action.c index 5f4d7c1f8..a7e5a4983 100644 --- a/src/action.c +++ b/src/action.c @@ -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; diff --git a/src/dns.c b/src/dns.c index 69045ce69..d589f9ed9 100644 --- a/src/dns.c +++ b/src/dns.c @@ -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; } } } diff --git a/src/server.c b/src/server.c index cafa7fdb8..5e6326648 100644 --- a/src/server.c +++ b/src/server.c @@ -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);