From 796a4ae043a63ae8bcefbf624f1825b0564cdac5 Mon Sep 17 00:00:00 2001 From: Matthew Fala Date: Fri, 21 Oct 2022 00:49:30 +0000 Subject: [PATCH] network: add instrumentation Signed-off-by: Matthew Fala --- src/flb_network.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/flb_network.c b/src/flb_network.c index 992eb1db0e0..110435ac9d6 100644 --- a/src/flb_network.c +++ b/src/flb_network.c @@ -49,6 +49,11 @@ #include #include +// Instrumentation start +#include +#include +// Instrumentation end + #ifndef SOL_TCP #define SOL_TCP IPPROTO_TCP #endif @@ -1183,6 +1188,7 @@ flb_sockfd_t flb_net_tcp_connect(const char *host, unsigned long port, char address[41]; struct addrinfo hints; struct addrinfo *sorted_res, *res, *rp; + char stop_buf[100]; if (is_async == FLB_TRUE && !u_conn) { flb_error("[net] invalid async mode with not set upstream connection"); @@ -1210,6 +1216,7 @@ flb_sockfd_t flb_net_tcp_connect(const char *host, unsigned long port, } /* retrieve DNS info */ + flb_log_recurring_event_prefixed("flb_net_tcp_connect_getaddrinfo", "start, "); if (use_async_dns) { ret = flb_net_getaddrinfo(host, _port, &hints, &res, u_conn->u->net.dns_mode, connect_timeout); @@ -1225,6 +1232,8 @@ flb_sockfd_t flb_net_tcp_connect(const char *host, unsigned long port, else { flb_warn("[net] getaddrinfo(host='%s', err=%d): %s", host, ret, gai_strerror(ret)); } + sprintf(stop_buf, "stop, error=%s", (use_async_dns) ? ares_strerror(ret) : gai_strerror(ret)); + flb_log_recurring_event_prefixed("flb_net_tcp_connect_getaddrinfo", "stop, dns_timeout"); return -1; } @@ -1241,9 +1250,11 @@ flb_sockfd_t flb_net_tcp_connect(const char *host, unsigned long port, freeaddrinfo(res); } + flb_log_recurring_event_prefixed("flb_net_tcp_connect_getaddrinfo", (u_conn->net_error) ? "stop, dns_timeout" : "stop, unknown_err"); return -1; } + sorted_res = res; if (u_conn->u->net.dns_prefer_ipv4) { @@ -1259,10 +1270,15 @@ flb_sockfd_t flb_net_tcp_connect(const char *host, unsigned long port, freeaddrinfo(res); } + flb_log_recurring_event_prefixed("flb_net_tcp_connect_getaddrinfo", "stop, result_error"); + return -1; } } + flb_log_recurring_event_prefixed("flb_net_tcp_connect_getaddrinfo", "stop, success"); + + /* * Try to connect: on this iteration we try to connect to the first * available address.