From 1523f51b1da7de05189d01837391406eaf308493 Mon Sep 17 00:00:00 2001 From: taran-p Date: Thu, 2 Nov 2023 05:34:32 +0000 Subject: [PATCH 1/3] add filters for errors and specific status codes --- http-tracer.go | 11 +++++++++++ main.go | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/http-tracer.go b/http-tracer.go index 4078e0c..9206259 100644 --- a/http-tracer.go +++ b/http-tracer.go @@ -22,6 +22,7 @@ import ( "io" "io/ioutil" "net/http" + "slices" "strconv" "strings" "time" @@ -301,6 +302,16 @@ func doTrace(trace TraceInfo, backend *Backend) { return } + if globalErrorsOnly && st.StatusCode == http.StatusOK { + return + } + + if len(globalStatusCodes) > 0 { + if !slices.Contains(globalStatusCodes, st.StatusCode) { + return + } + } + if globalJSONEnabled { if globalDebugEnabled { buf := &bytes.Buffer{} diff --git a/main.go b/main.go index ab70460..19b40a9 100644 --- a/main.go +++ b/main.go @@ -66,6 +66,8 @@ var ( globalTrace string globalJSONEnabled bool globalConsoleDisplay bool + globalErrorsOnly bool + globalStatusCodes []int globalConnStats []*ConnStats log2 *logrus.Logger ) @@ -807,6 +809,8 @@ func sidekickMain(ctx *cli.Context) { globalQuietEnabled = ctx.GlobalBool("quiet") globalConsoleDisplay = globalLoggingEnabled || ctx.IsSet("trace") || !term.IsTerminal(int(os.Stdout.Fd())) globalDebugEnabled = ctx.GlobalBool("debug") + globalErrorsOnly = ctx.GlobalBool("errors") + globalStatusCodes = ctx.GlobalIntSlice("status-code") go func() { t := time.NewTicker(ctx.GlobalDuration("dns-ttl")) @@ -961,6 +965,14 @@ func main() { Usage: "choose custom DNS TTL value for DNS refreshes for load balanced endpoints", Value: 10 * time.Minute, }, + cli.BoolFlag{ + Name: "errors , e", + Usage: "filter out any non-error responses", + }, + cli.IntSliceFlag{ + Name: "status-code", + Usage: "filter by given status code", + }, } app.CustomAppHelpTemplate = `NAME: {{.Name}} - {{.Description}} From 341f1bd9133a7c0ddc741c76e10b62d46e11573f Mon Sep 17 00:00:00 2001 From: taran-p Date: Thu, 2 Nov 2023 17:51:19 +0000 Subject: [PATCH 2/3] change errors check --- http-tracer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http-tracer.go b/http-tracer.go index 9206259..6b55f3b 100644 --- a/http-tracer.go +++ b/http-tracer.go @@ -302,7 +302,7 @@ func doTrace(trace TraceInfo, backend *Backend) { return } - if globalErrorsOnly && st.StatusCode == http.StatusOK { + if globalErrorsOnly && st.StatusCode >= 400 && st.StatusCode < 600 { return } From f1280928f490b6cb9d1aa59ce0d0544fc866a83c Mon Sep 17 00:00:00 2001 From: taran-p Date: Thu, 2 Nov 2023 17:53:37 +0000 Subject: [PATCH 3/3] . --- http-tracer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http-tracer.go b/http-tracer.go index 6b55f3b..d89cc23 100644 --- a/http-tracer.go +++ b/http-tracer.go @@ -302,7 +302,7 @@ func doTrace(trace TraceInfo, backend *Backend) { return } - if globalErrorsOnly && st.StatusCode >= 400 && st.StatusCode < 600 { + if globalErrorsOnly && (st.StatusCode < 400 || st.StatusCode >= 600) { return }