Skip to content

Commit 212a6fa

Browse files
committed
Add support for http debugging
This depends on prometheus/common#985 for the infrastructure, but adds an --http.debug flag that uses the prometheus/common debug roundtripper to provide debug logs with credentials censored. Signed-off-by: Phil Dibowitz <phil@ipom.com>
1 parent 1cd42e0 commit 212a6fa

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

cli/root.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var (
4242
output string
4343
timeout time.Duration
4444
httpConfigFile string
45+
httpDebug bool
4546
versionCheck bool
4647
featureFlags string
4748

@@ -122,7 +123,12 @@ func NewAlertmanagerClient(amURL *url.URL) *client.AlertmanagerAPI {
122123
if err != nil {
123124
kingpin.Fatalf("failed to create a new HTTP client: %v", err)
124125
}
126+
if httpDebug {
127+
httpclient.Transport = promconfig.NewDebugRoundTripper(os.Stderr, httpclient.Transport)
128+
}
125129
cr = clientruntime.NewWithClient(address, path.Join(amURL.Path, defaultAmApiv2path), schemes, httpclient)
130+
} else if httpDebug {
131+
cr.Transport = promconfig.NewDebugRoundTripper(os.Stderr, cr.Transport)
126132
}
127133

128134
c := client.New(cr, strfmt.Default)
@@ -155,6 +161,7 @@ func Execute() {
155161
app.Flag("output", "Output formatter (simple, extended, json)").Short('o').Default("simple").EnumVar(&output, "simple", "extended", "json")
156162
app.Flag("timeout", "Timeout for the executed command").Default("30s").DurationVar(&timeout)
157163
app.Flag("http.config.file", "HTTP client configuration file for amtool to connect to Alertmanager.").PlaceHolder("<filename>").ExistingFileVar(&httpConfigFile)
164+
app.Flag("http.debug", "Log outgoing HTTP requests and responses to stderr (credentials are redacted). Useful for diagnosing connectivity and authentication issues.").BoolVar(&httpDebug)
158165
app.Flag("version-check", "Check alertmanager version. Use --no-version-check to disable.").Default("true").BoolVar(&versionCheck)
159166
app.Flag("enable-feature", fmt.Sprintf("Experimental features to enable, comma separated. Valid options: %s", strings.Join(featurecontrol.AllowedFlags, ", "))).Default("").StringVar(&featureFlags)
160167

0 commit comments

Comments
 (0)