Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flags to filter errors and status codes #95

Merged
merged 3 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading