]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: dns: add missing sent counter and parent id to dns counters.
authorEmeric Brun <ebrun@haproxy.com>
Mon, 4 Jan 2021 09:40:46 +0000 (10:40 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 13 Feb 2021 08:43:17 +0000 (09:43 +0100)
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
include/haproxy/dns-t.h
include/haproxy/server.h
src/action.c
src/dns.c
src/server.c

index 709d17c5f2e82948f32ccb038f58e2ee522f35c7..edd34f1d3fe0e6b6d3159b5d601473c00d64401b 100644 (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)
index 191edf6ae9de48092de2cb1126635dd6ff670a12..c9199045c7cfd62c59cb60be9a657e258ebad2ce 100644 (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 */
index 5ca0fe90dc5adbd169d7d44a17d8091a0078f741..a19d76922f1d56b37347b85fb21deaf106c2c3ab 100644 (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);
index 5f4d7c1f85f09b4bb23879d61daeca83cfa6d352..a7e5a4983dbd9f87198d00675fe49e426dd9c1cf 100644 (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;
 
index 69045ce69fe4a0e624312957f4699194532d24a7..d589f9ed9eaca4226fb009cfd565c44a43b67f52 100644 (file)
--- 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;
                                }
                        }
                }
index cafa7fdb823fcbbbcd3737e4569eb247ae433b3a..5e63266486df57651c089fc4271ed8d391efb0e1 100644 (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);