Skip to content

Commit

Permalink
command/run: wrap proxy dialer with logger
Browse files Browse the repository at this point in the history
2024/02/28 14:55:23.447579 [proxy] [DEBUG] closing connection from 127.0.0.1:54332 duration=1.982912042s
2024/02/28 14:56:10.294136 [proxy] [DEBUG] accepted connection from 127.0.0.1:54337
2024/02/28 14:56:10.294249 [proxy] [DEBUG] [2-4c948b90] read CONNECT request host=google.com:443
2024/02/28 14:56:10.294267 [proxy] [DEBUG] [2-4c948b90] CONNECT to host directly: google.com:443
2024/02/28 14:56:10.294271 [proxy] [DEBUG] [2-4c948b90] opening connection to tcp google.com:443
2024/02/28 14:56:10.353445 [proxy] [DEBUG] [2-4c948b90] connection to tcp google.com:443 established duration=59.166ms

Fixes #645
  • Loading branch information
mmatczuk committed Feb 28, 2024
1 parent 1af2c67 commit 6ad7638
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions command/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type command struct {
goleak bool
}

func (c *command) runE(cmd *cobra.Command, _ []string) (cmdErr error) {
func (c *command) runE(cmd *cobra.Command, _ []string) (cmdErr error) { //nolint:gocyclo // Glue code
if f := c.logConfig.File; f != nil {
defer f.Close()
}
Expand Down Expand Up @@ -119,20 +119,16 @@ func (c *command) runE(cmd *cobra.Command, _ []string) (cmdErr error) {
}
}

var (
pr forwarder.PACResolver
rt http.RoundTripper
)

{
var err error
rt, err = forwarder.NewHTTPTransport(c.httpTransportConfig)
var pr forwarder.PACResolver
if c.pac != nil {
// Disable metrics for receiving PAC file.
cfg := *c.httpTransportConfig
cfg.PromRegistry = nil
rt, err := forwarder.NewHTTPTransport(&cfg)
if err != nil {
return err
}
}

if c.pac != nil {
script, err := forwarder.ReadURLString(c.pac, rt)
if err != nil {
return fmt.Errorf("read PAC file: %w", err)
Expand Down Expand Up @@ -213,6 +209,12 @@ func (c *command) runE(cmd *cobra.Command, _ []string) (cmdErr error) {

g := runctx.NewGroup()
{
rt, err := forwarder.NewHTTPTransport(c.httpTransportConfig)
if err != nil {
return err
}
rt.DialContext = martianlog.LoggingDialContext(rt.DialContext)

p, err := forwarder.NewHTTPProxy(c.httpProxyConfig, pr, cm, rt, logger.Named("proxy"))
if err != nil {
return err
Expand Down

0 comments on commit 6ad7638

Please sign in to comment.