From 47b39076f1b7985d9716cc1efb2bbf16d796d592 Mon Sep 17 00:00:00 2001 From: dbshah12 Date: Wed, 21 Oct 2026 15:47:50 +0530 Subject: [PATCH 1/3] DLPX-99899 connstat-stats.sh: replace stdbuf -oL with mawk -W interactive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit stdbuf -oL works by overriding libc stdio buffer settings via LD_PRELOAD. mawk 1.3.4 manages its own output buffers and calls write() directly on the pipe file descriptor — it never routes through the C stdio FILE* that stdbuf's preloaded library intercepts. The result is stdbuf -oL is silently ignored and mawk's output stays buffered until process exit. Since PR #128 switched to a single long-running connstat (no -c exit), mawk never exits, the buffer never flushes, and Telegraf receives zero tcp_stats data on any engine where /usr/bin/awk resolves to mawk — which is every stock Ubuntu 24.04 engine (mawk is Priority: required and the default alternative for /usr/bin/awk). PR #128 was validated only on dhruv5.dlpxdc.co, which had gawk installed as the awk alternative. gawk uses libc stdio and does honour stdbuf -oL, so the test passed there while every standard engine was silently broken. Fix: replace stdbuf -oL awk with mawk -W interactive. The -W interactive flag is mawk's own mechanism for per-line flushing — it forces mawk to flush its output buffer after every print, regardless of libc. Also correct the script comment, which incorrectly claimed stdbuf -oL works. Co-Authored-By: Claude Sonnet 4.6 (1M context) --- telegraf/connstat-stats.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/telegraf/connstat-stats.sh b/telegraf/connstat-stats.sh index dc83b0c..ee4dc83 100755 --- a/telegraf/connstat-stats.sh +++ b/telegraf/connstat-stats.sh @@ -18,11 +18,12 @@ # # mawk (the default awk on Delphix engines) does not flush its stdout buffer # when writing to a Telegraf execd pipe, even with explicit fflush() calls. -# stdbuf -oL forces line-buffered stdout on awk, so each output line is -# delivered to Telegraf immediately without needing awk to exit. +# stdbuf -oL has no effect on mawk because mawk manages its own output buffers +# and bypasses libc stdio — stdbuf's LD_PRELOAD trick cannot intercept it. +# -W interactive is mawk's native flag for per-line flushing. /usr/bin/connstat -PLe -i 10 -T u \ -o laddr,lport,raddr,rport,inbytes,outbytes,retranssegs,suna,unsent,swnd,cwnd,rwnd,rtt \ - | stdbuf -oL awk -F',' ' + | mawk -W interactive -F',' ' BEGIN { batch_ts = 0 # Load port->service mapping from /etc/services, same as LocalTCPStatsCollector. From 4b14f5a3164ec9dac544623034edfc82775e7675 Mon Sep 17 00:00:00 2001 From: dbshah12 Date: Thu, 22 Oct 2026 10:24:18 +0530 Subject: [PATCH 2/3] DLPX-99899 connstat-stats.sh: address PR review feedback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review on PR #131 clarified that mawk's problem is input-side block buffering, not output-side libc-stdio bypass. Reviewer verified with strace that: - mawk fills a 256 KB stdin buffer before processing any record - stdbuf -oL does take effect on mawk's stdout; it just cannot help because mawk never gets as far as writing - -W interactive fixes it by switching stdin to line-by-line reads (and also unbuffers stdout) Changes: - Update the script comment to describe the input-side cause. - Use /usr/bin/mawk full path to match /usr/bin/connstat style. - Drop the two fflush() calls — -W interactive already unbuffers stdout, so they are no-ops under the chosen fix. - Add mawk to debian/control Depends — mawk is Priority: required on Ubuntu 24.04 so already present, but declaring the hard runtime dependency documents the requirement. Co-Authored-By: Claude Sonnet 4.6 (1M context) --- debian/control | 2 +- telegraf/connstat-stats.sh | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/debian/control b/debian/control index eb993a9..0bc8a6b 100644 --- a/debian/control +++ b/debian/control @@ -13,6 +13,6 @@ Standards-Version: 4.1.2 Package: performance-diagnostics Architecture: any -Depends: python3-bpfcc, python3-minimal, python3-psutil, telegraf, docker-ce, influxdb2, curl, openssl, jq +Depends: python3-bpfcc, python3-minimal, python3-psutil, telegraf, docker-ce, influxdb2, curl, openssl, jq, mawk Description: eBPF-based Performance Diagnostic Tools A collection of eBPF-based tools for diagnosing performance issues. diff --git a/telegraf/connstat-stats.sh b/telegraf/connstat-stats.sh index ee4dc83..596b131 100755 --- a/telegraf/connstat-stats.sh +++ b/telegraf/connstat-stats.sh @@ -16,14 +16,14 @@ # swnd, cwnd, rwnd, rtt (averaged across connections) # connections (count of aggregated conns) # -# mawk (the default awk on Delphix engines) does not flush its stdout buffer -# when writing to a Telegraf execd pipe, even with explicit fflush() calls. -# stdbuf -oL has no effect on mawk because mawk manages its own output buffers -# and bypasses libc stdio — stdbuf's LD_PRELOAD trick cannot intercept it. -# -W interactive is mawk's native flag for per-line flushing. +# mawk (the default awk on Delphix engines) reads a pipe in blocks: it keeps +# reading until its 256 KB input buffer is full, or EOF, before processing any +# record. connstat never exits and writes a few KB per interval, so plain mawk +# prints nothing; stdbuf -oL and fflush() affect only output and don't help. +# -W interactive makes mawk read stdin line by line (and unbuffers stdout). /usr/bin/connstat -PLe -i 10 -T u \ -o laddr,lport,raddr,rport,inbytes,outbytes,retranssegs,suna,unsent,swnd,cwnd,rwnd,rtt \ - | mawk -W interactive -F',' ' + | /usr/bin/mawk -W interactive -F',' ' BEGIN { batch_ts = 0 # Load port->service mapping from /etc/services, same as LocalTCPStatsCollector. @@ -54,7 +54,6 @@ BEGIN { inb[key] "," outb[key] "," ret[key] "," sun[key] "," uns[key] "," \ int(sw[key]/n) "," int(cw[key]/n) "," int(rw[key]/n) "," int(rt[key]/n) "," n "," batch_ts } - fflush() ts = $0; sub(/^=[[:space:]]*/, "", ts); batch_ts = ts + 0 delete cnt; delete inb; delete outb; delete ret delete sun; delete uns; delete sw; delete cw; delete rw; delete rt @@ -82,6 +81,5 @@ END { inb[key] "," outb[key] "," ret[key] "," sun[key] "," uns[key] "," \ int(sw[key]/n) "," int(cw[key]/n) "," int(rw[key]/n) "," int(rt[key]/n) "," n "," batch_ts } - fflush() } ' From 083b679496c44feb0fda7f5605cef667f9566a0b Mon Sep 17 00:00:00 2001 From: dbshah12 Date: Thu, 22 Oct 2026 12:19:23 +0530 Subject: [PATCH 3/3] DLPX-99899 retrigger CI (style checks dropped webhook)