Skip to content

Commit

Permalink
Add flags to filter errors and status codes (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
taran-p authored Nov 6, 2023
1 parent 669d33f commit 779bde0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions http-tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io"
"io/ioutil"
"net/http"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -301,6 +302,16 @@ func doTrace(trace TraceInfo, backend *Backend) {
return
}

if globalErrorsOnly && (st.StatusCode < 400 || st.StatusCode >= 600) {
return
}

if len(globalStatusCodes) > 0 {
if !slices.Contains(globalStatusCodes, st.StatusCode) {
return
}
}

if globalJSONEnabled {
if globalDebugEnabled {
buf := &bytes.Buffer{}
Expand Down
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ var (
globalTrace string
globalJSONEnabled bool
globalConsoleDisplay bool
globalErrorsOnly bool
globalStatusCodes []int
globalConnStats []*ConnStats
log2 *logrus.Logger
)
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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}}
Expand Down

0 comments on commit 779bde0

Please sign in to comment.