-
Notifications
You must be signed in to change notification settings - Fork 96
Explicit forward proxy support for HTTP with Basic Auth #1201
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
base: main
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,35 @@ | |||
# Agent Proxy Support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add this to the official NGINX docs https://github.com/nginx/documentation
@@ -337,6 +338,18 @@ type ( | |||
ExcludeFiles []string `yaml:"exclude_files" mapstructure:"exclude_files"` | |||
MonitoringFrequency time.Duration `yaml:"monitoring_frequency" mapstructure:"monitoring_frequency"` | |||
} | |||
|
|||
// nolint: govet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the nolint required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I tried everything to make it work, but it was consistently failing with fieldalignment error.
return http.ReadResponse(bufio.NewReader(conn), nil) | ||
} | ||
|
||
func wrapProxyError(ctx context.Context, msg string, err error, proxyURL string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are returning an error from a function then there is no need to log it as it should be logged by the caller
@@ -409,6 +418,14 @@ func (oc *Collector) restartCollector(ctx context.Context) { | |||
} | |||
} | |||
|
|||
func (oc *Collector) setProxyIfNeeded(ctx context.Context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be renamed to just setProxy ?
func (oc *Collector) setProxyIfNeeded(ctx context.Context) { | |
func (oc *Collector) setProxy(ctx context.Context) { |
proxyURL := proxy.URL | ||
parsedProxyURL, err := url.Parse(proxyURL) | ||
if err != nil { | ||
slog.ErrorContext(ctx, "Malformed proxy URL; skipping Proxy setup", "url", proxyURL, "error", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this error be updated to match the format of our other errors ? something like
slog.ErrorContext(ctx, "Malformed proxy URL; skipping Proxy setup", "url", proxyURL, "error", err) | |
slog.ErrorContext(ctx, "Malformed proxy URL, unable to configure proxy for collector ", "url", proxyURL, "error", err) |
if authLower == "basic" { | ||
setProxyWithBasicAuth(ctx, proxy, parsedProxyURL) | ||
} else { | ||
slog.ErrorContext(ctx, "Unknown auth type for proxy; Aborting Proxy Setup", "auth", auth, "url", proxyURL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this error be updated to match the format of our other errors ? something like
slog.ErrorContext(ctx, "Unknown auth type for proxy; Aborting Proxy Setup", "auth", auth, "url", proxyURL) | |
slog.ErrorContext(ctx, "Unknown auth type for proxy, unable to configure proxy for collector", "auth", auth, "url", proxyURL) |
func setProxyEnvs(ctx context.Context, proxyEnvURL, msg string) { | ||
slog.DebugContext(ctx, msg, "url", proxyEnvURL) | ||
if setenvErr := os.Setenv("HTTP_PROXY", proxyEnvURL); setenvErr != nil { | ||
slog.ErrorContext(ctx, "Failed to set Proxy", "error", setenvErr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this error be a bit more descriptive
slog.ErrorContext(ctx, "Failed to set Proxy", "error", setenvErr) | |
slog.ErrorContext(ctx, "Failed to set proxy envs", "error", setenvErr) |
slog.ErrorContext(ctx, "Failed to set Proxy", "error", setenvErr) | ||
} | ||
if setenvErr := os.Setenv("HTTPS_PROXY", proxyEnvURL); setenvErr != nil { | ||
slog.ErrorContext(ctx, "Failed to set Proxy", "error", setenvErr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
return http.ReadResponse(bufio.NewReader(conn), nil) | ||
} | ||
|
||
func wrapProxyError(ctx context.Context, msg string, err error, proxyURL string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to wrap the proxy error ?
Proposed changes
Describe the use case and detail of the change. If this PR addresses an issue on GitHub, make sure to include a link to that issue using one of the supported keywords here in this description (not in the title of the PR).
Checklist
Before creating a PR, run through this checklist and mark each as complete.
CONTRIBUTING
documentmake install-tools
and have attached any dependency changes to this pull requestREADME.md
)