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

SNOW-926008 observability enhancement for proxy use-cases #697

Closed
wants to merge 8 commits into from

Conversation

sfc-gh-dszmolka
Copy link
Collaborator

  • detecting if HTTP_PROXY/HTTPS_PROXY environmental variable is set, log them on DEBUG loglevel
  • added logging for proxy port and proxy user (if set), had only proxy host
  • if both HTTPS_PROXY and proxyHost is set, can lead to not-so-trivial-to-debug situations ; log this on DEBUG loglevel for more intuitive troubleshooting
  • generic observability: instead of swallowing the underlying error upon connectivity issue and emit a hard-to-debug generic error message, log that underlying error stack on DEBUG loglevel

* detecting if HTTP_PROXY/HTTPS_PROXY environmental variable is set, log them on DEBUG loglevel
* added logging for proxy port and proxy user (if set), had only proxy host
* if both HTTPS_PROXY and proxyHost is set, can lead to not-so-trivial-to-debug situations ; log this on DEBUG loglevel for more intuitive troubleshooting
* generic observability: instead of swallowing the underlying error upon connectivity issue and emit a hard-to-debug generic error message, log that underlying error stack on DEBUG loglevel
@sfc-gh-dszmolka sfc-gh-dszmolka marked this pull request as ready for review November 10, 2023 11:07
@sfc-gh-dszmolka sfc-gh-dszmolka requested a review from a team as a code owner November 10, 2023 11:07
Copy link

codecov bot commented Nov 10, 2023

Codecov Report

Attention: 12 lines in your changes are missing coverage. Please review.

Comparison is base (49c7b13) 87.35% compared to head (ba751f4) 87.22%.

Files Patch % Lines
lib/agent/https_proxy_ocsp_agent.js 8.33% 11 Missing ⚠️
lib/services/sf.js 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #697      +/-   ##
==========================================
- Coverage   87.35%   87.22%   -0.14%     
==========================================
  Files          61       61              
  Lines        5759     5785      +26     
==========================================
+ Hits         5031     5046      +15     
- Misses        728      739      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

lib/agent/https_proxy_ocsp_agent.js Outdated Show resolved Hide resolved
lib/agent/https_proxy_ocsp_agent.js Outdated Show resolved Hide resolved
@@ -98,7 +98,25 @@ function connect(req, opts, fn)
{
var proxy = this.proxy;
var agent = this;
Logger.getInstance().debug("Using proxy=%s for host %s", proxy.host, opts.host);

// try and detect if there's proxy envvar set, currently it's not logged anywhere
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we support env variables for proxy in NodeJs driver?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do not, to my knowledge.
that does not keep users from trying to still use it (most of the times inadvertently, e.g. it's already set in the env for other application. or trying to use it since our other drivers support it), then get in all sorts of trouble, ending up with Snowflake Support who now doesn't have a really easy way of confirming this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we do anything more than only reading it? eomeone who reads logs will see that maybe there is some difference between those options and will it be enough?

Here we are using agent that is aware of proxy so we can see only differences between driver and env configuration - maybe checking proxy env variables should also be done when we don't have proxy configuration on connection?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you - i'll work on this per our discussion

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: the env variables: even though it is not documented yet, my tests show that we do support it. I mean the connection breaks as soon as I point HTTP_PROXY / HTTPS_PROXY to a non-existing proxy. It can be confirmed it does go through the proxy as soon as I set up a proxy and set HTTPS_PROXY to point the driver towards it.

Even without proxyHost/proxyPort.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PROXY envvar now also should be detected outside of the agent

@sfc-gh-dszmolka sfc-gh-dszmolka marked this pull request as draft November 13, 2023 11:25
* detect and log PROXY envvar even outside of agent (if proxyHost not used)
* detect and log if both the envvar and proxyHost/proxyPort set up
* test for the 2 new functions
@sfc-gh-dszmolka sfc-gh-dszmolka marked this pull request as ready for review November 14, 2023 06:05
// using both the envvar and the proxyHost/proxyPort settings for proxy, this might conflict
if (envProxy.httpProxy &&
Util.removeScheme(envProxy.httpProxy).toLowerCase() != prxHostWithPort.toLowerCase()) {
Logger.getInstance().debug('Using both the HTTP_PROXY (%s) and the proxyHost:proxyPort (%s) settings to connect, '
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when it's different maybe let's log it with WARN, also in other added logs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ended up moving this check to somewhere else instead, where we create the agent

also logging the agent-specific proxy details where we create the agent

@@ -615,6 +615,9 @@ function StateAbstract(options)
// if we got an error, wrap it into a network error
if (err)
{
// if we're running in DEBUG loglevel, probably we want to see the full error instead
Logger.getInstance().debug(JSON.stringify(err, Util.getCircularReplacer()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we add a prefixing message at the begining of this log? to not only log the reasult error as json

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -1264,6 +1267,13 @@ StateConnecting.prototype.continue = function ()
// issue a login request
const sendRequest = function ()
{
// try to detext PROXY envvar even outside of agent
Copy link
Collaborator

@sfc-gh-dprzybysz sfc-gh-dprzybysz Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can detect it once when agent is created (agents are reused now) - proxy env variables should not change during application work and it's not necessary to have it on each request?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good hint, thank you! moved it to where we create the agent

@sfc-gh-dszmolka sfc-gh-dszmolka marked this pull request as draft November 14, 2023 12:06
@sfc-gh-dszmolka
Copy link
Collaborator Author

closing this PR for now until i clear some test locally

@sfc-gh-dszmolka sfc-gh-dszmolka deleted the SNOW-926008-more-proxy-logging branch November 14, 2023 12:18
@github-actions github-actions bot locked and limited conversation to collaborators Nov 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants