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

Enable jib.httpTimeout system property for HTTP connection and read timeout #656

Merged
merged 9 commits into from
Jul 19, 2018

Conversation

chanseokoh
Copy link
Member

@chanseokoh chanseokoh commented Jul 18, 2018

Part of #582.

Decided to read the system property in RegistryAuthenticator and RegistryEndpointCaller.

@chanseokoh
Copy link
Member Author

Hold on. Chatted with @coollog, and I'll rework this.

@chanseokoh chanseokoh changed the title Allow propagating and applying HTTP timeout Enable jib.httpTimeout system property for HTTP connection and read timeout Jul 18, 2018
@chanseokoh
Copy link
Member Author

I think this is good for review.

The next step after this PR is to check the system property value at the frontend to print out warnings, if necessary.

@@ -69,6 +69,11 @@
}
}

private static int getHttpTimeout() {
int httpTimeout = Integer.getInteger("jib.httpTimeout", 20000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way we could reuse the default from the Google HTTP client? Or not set an HTTP timeout to allow it to use the default from the HTTP library?

Copy link
Member Author

Choose a reason for hiding this comment

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

The Google HTTP client doesn't define the public static constant, so I'll pursue the latter approach.

Copy link
Contributor

@coollog coollog left a comment

Choose a reason for hiding this comment

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

Looks good! Just a small question.

@@ -103,6 +103,15 @@ public static Initializer initializer(String serverUrl, String repository) {
return new Initializer(serverUrl, repository);
}

@Nullable
private static Integer getHttpTimeout() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is using null a common way to do this? If not, I was thinking maybe use negative to indicate absence?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's not uncommon to use null to indicate a field is unset or uninitialized, or something is absent. Using a negative value works too. However, it won't be distinguishable from the user wrongly giving a negative value. That will matter if we error out on a negative timeout value as you said.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay sounds good 👍 let's add a javadoc explicitly mentioning that null means the caller should use some default.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, you weren't talking about a field here. I see what you meant. I'll think about the API-aspect of this method.

@Nullable
private static Integer getHttpTimeout() {
Integer httpTimeout = Integer.getInteger("jib.httpTimeout");
if (httpTimeout != null && httpTimeout >= 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could do just return Integer.getInteger("jib.httpTimeout", null) since in the negative case, we probably want to error (thrown by HttpRequest#setConnectTimeout)

Copy link
Member Author

@chanseokoh chanseokoh Jul 18, 2018

Choose a reason for hiding this comment

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

I was thinking showing a warning with a negative value, instead of errorring out. Do you think it's not good?

Anyways, if we decide to error out, I'll probably detect it and fail at the frontends with better error messages, rather than just displaying up an unfriendly stack trace from Preconditions.checkArgument() with no message.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think either way is good. I lean towards the errorring since the case I could think of where negative could show up is if the user may have meant to type another timeout and accidentally put a minus sign in front - in which case, a warning may be lost in the logs to a different error when the connection fails.

Copy link
Member Author

@chanseokoh chanseokoh Jul 18, 2018

Choose a reason for hiding this comment

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

I see. I think then the same argument applies to non-parsable string values. The user could accidentally put any non-digit characters, so it also makes sense to error out on non-parsable strings. Going for errorring on both cases?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, I think in the non-parsable version, this already errors, since Integer#getInteger would throw a NumberFormatException.

Copy link
Member Author

@chanseokoh chanseokoh Jul 18, 2018

Choose a reason for hiding this comment

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

Alright, errorring on both cases. (BTW, Integer.getInteger() doesn't throw NumberFormatException. parseInt() does, OTOH.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah right, looks like the getInteger(String nm, Integer val) one catches and ignores the NumberFormatException

Copy link
Member Author

Choose a reason for hiding this comment

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

Will update the code tomorrow, but I'm thinking of doing

      Integer httpTimeout = null; // implies using the default timeout
      String timeoutValue = System.getProperty("jib.httpTimeout");
      if (timeoutValue != null) {
        httpTimeout = Integer.parseInt(timeoutValue);
        if (httpTimeout < 0) {
          throw new RegistryAuthenticationFailedException("Negative value of jib.httpTimeout");
        }
      }
      ...
      try (Connection connection = ...) {
        Request.Builder requestBuilder = Request.builder().setHttpTimeout(httpTimeout);
      ...
    } catch (NumberFormatException ex) {
      throw new RegistryAuthenticationFailedException("Non-integer value of jib.httpTimeout");
    }

Since all versions of getInteger() don't throw NumberFormatException, I guess I need to call parseInt() after System.getProperty().

Copy link
Member Author

Choose a reason for hiding this comment

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

@coollog and I agreed that we make the code simple and not care about the edge cases too much here. If something goes awry, so be it. Instead, we will guard the errors at the plugin frontends.

@coollog coollog added this to the v0.9.7 milestone Jul 19, 2018
Copy link
Contributor

@coollog coollog left a comment

Choose a reason for hiding this comment

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

Oh let's add a CHANGELOG entry for this.

@chanseokoh chanseokoh merged commit 68edcc6 into master Jul 19, 2018
@chanseokoh chanseokoh deleted the i582-http-timeout branch July 26, 2018 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants