You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2021/03/09 00:14:38 UTC

[GitHub] [druid] himanshug opened a new pull request #10961: k8s discovery module: fix issue for druid.host being more than 63chars not permitted as k8s resource label value

himanshug opened a new pull request #10961:
URL: https://github.com/apache/druid/pull/10961


   ### Description
   
   Fixes a bug which shows up in specific deployments, that use k8s based discovery module, where `druid.host` gets set to something more than 63 characters which is the max length limit on kubernetes label values.
   
   Currently we put full `host:port` as a k8s label inside pod spec, which can be of arbitrary length. This patch changes node discovery mechanism to work with a hash of `host:port` in the label value instead.
   
   It is the (2) issue described in https://github.com/apache/druid/issues/10752#issuecomment-760547707 . Since this issue will be encountered by users quickly so hoping to have this included in 0.21.0 release.
   
   PS: Existing [unit/integration] tests cover the changes made here. It would further be exercised in a larger PR that introduces leader election improvements and integration tests similar to https://github.com/apache/druid/pull/10680 would be done later, that is blocked on a new release from kubernetes java client lib we use, that contains few leader election algorithm improvements.
   
   <hr>
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
   
   This PR has:
   - [x] been self-reviewed.
      - [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
   - [x] added documentation for new or modified features or behaviors.
   - [x] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
   - [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
   - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
   - [x] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
   - [ ] added integration tests.
   - [ ] been tested in a test Druid cluster.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] jihoonson merged pull request #10961: k8s discovery module: fix issue for druid.host being more than 63chars not permitted as k8s resource label value

Posted by GitBox <gi...@apache.org>.
jihoonson merged pull request #10961:
URL: https://github.com/apache/druid/pull/10961


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] zhangyue19921010 commented on a change in pull request #10961: k8s discovery module: fix issue for druid.host being more than 63chars not permitted as k8s resource label value

Posted by GitBox <gi...@apache.org>.
zhangyue19921010 commented on a change in pull request #10961:
URL: https://github.com/apache/druid/pull/10961#discussion_r589916239



##########
File path: extensions-core/kubernetes-extensions/src/main/java/org/apache/druid/k8s/discovery/K8sDruidNodeAnnouncer.java
##########
@@ -237,30 +236,14 @@ private String getPodDefAnnocationPath(String annotation)
     return StringUtils.format("%s/%s", POD_ANNOTATIONS_PATH_PREFIX, annotation);
   }
 
-  private static String encodeHostPort(String hostPort)
+  // a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and
+  // must start and end with an alphanumeric character
+  private static String hashEncodeStringForLabelValue(String str)
   {
-    //K8S requires that label values must match regex (([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?
-    //So, it is essential to replace ':' with '-'
-
-    // it is assumed that hostname does not have ':' in it except for separating host and port
-    Preconditions.checkState(
-        hostPort.indexOf(':') == hostPort.lastIndexOf(':'),
-        "hostname in host:port[%s] has ':' in it", hostPort
-    );
-
-    return hostPort.replace(':', '-');
-  }
-
-  private String replaceLast(String str, char oldChar, char newChar)
-  {
-    char[] chars = str.toCharArray();
-    for (int i = chars.length - 1; i >= 0; i--) {
-      if (chars[i] == oldChar) {
-        chars[i] = newChar;
-        break;
-      }
+    int hash = str.hashCode();
+    if (hash < 0) {
+      hash = -1 * hash;

Review comment:
       nit: Just wondering if this is a best way to solve 63chars limitation using `String.hascode()`. As we know, String.hashCode() isn't unique, but it can't be(https://sigpwned.com/2018/08/10/string-hashcode-is-plenty-unique/). And `hash = -1 * hash` will double the probability of conflict.
   In other words, what happens if there is a conflict? Does the conflict will lead to a wrong SelfDiscovery? If not, I think `String.hascode()` is good enough.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] himanshug commented on a change in pull request #10961: k8s discovery module: fix issue for druid.host being more than 63chars not permitted as k8s resource label value

Posted by GitBox <gi...@apache.org>.
himanshug commented on a change in pull request #10961:
URL: https://github.com/apache/druid/pull/10961#discussion_r589977445



##########
File path: extensions-core/kubernetes-extensions/src/main/java/org/apache/druid/k8s/discovery/K8sDruidNodeAnnouncer.java
##########
@@ -237,30 +236,14 @@ private String getPodDefAnnocationPath(String annotation)
     return StringUtils.format("%s/%s", POD_ANNOTATIONS_PATH_PREFIX, annotation);
   }
 
-  private static String encodeHostPort(String hostPort)
+  // a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and
+  // must start and end with an alphanumeric character
+  private static String hashEncodeStringForLabelValue(String str)
   {
-    //K8S requires that label values must match regex (([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?
-    //So, it is essential to replace ':' with '-'
-
-    // it is assumed that hostname does not have ':' in it except for separating host and port
-    Preconditions.checkState(
-        hostPort.indexOf(':') == hostPort.lastIndexOf(':'),
-        "hostname in host:port[%s] has ':' in it", hostPort
-    );
-
-    return hostPort.replace(':', '-');
-  }
-
-  private String replaceLast(String str, char oldChar, char newChar)
-  {
-    char[] chars = str.toCharArray();
-    for (int i = chars.length - 1; i >= 0; i--) {
-      if (chars[i] == oldChar) {
-        chars[i] = newChar;
-        break;
-      }
+    int hash = str.hashCode();
+    if (hash < 0) {
+      hash = -1 * hash;

Review comment:
       hash collision here has no impact on correctness , this is only used to get a suitable list of candidates. and, this is only used for finding a specific node by host:port for the health check.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] zhangyue19921010 commented on a change in pull request #10961: k8s discovery module: fix issue for druid.host being more than 63chars not permitted as k8s resource label value

Posted by GitBox <gi...@apache.org>.
zhangyue19921010 commented on a change in pull request #10961:
URL: https://github.com/apache/druid/pull/10961#discussion_r589916239



##########
File path: extensions-core/kubernetes-extensions/src/main/java/org/apache/druid/k8s/discovery/K8sDruidNodeAnnouncer.java
##########
@@ -237,30 +236,14 @@ private String getPodDefAnnocationPath(String annotation)
     return StringUtils.format("%s/%s", POD_ANNOTATIONS_PATH_PREFIX, annotation);
   }
 
-  private static String encodeHostPort(String hostPort)
+  // a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and
+  // must start and end with an alphanumeric character
+  private static String hashEncodeStringForLabelValue(String str)
   {
-    //K8S requires that label values must match regex (([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?
-    //So, it is essential to replace ':' with '-'
-
-    // it is assumed that hostname does not have ':' in it except for separating host and port
-    Preconditions.checkState(
-        hostPort.indexOf(':') == hostPort.lastIndexOf(':'),
-        "hostname in host:port[%s] has ':' in it", hostPort
-    );
-
-    return hostPort.replace(':', '-');
-  }
-
-  private String replaceLast(String str, char oldChar, char newChar)
-  {
-    char[] chars = str.toCharArray();
-    for (int i = chars.length - 1; i >= 0; i--) {
-      if (chars[i] == oldChar) {
-        chars[i] = newChar;
-        break;
-      }
+    int hash = str.hashCode();
+    if (hash < 0) {
+      hash = -1 * hash;

Review comment:
       nit: Just wondering if this is a best way to solve 63chars limitation using `String.hascode()`. As we know, String.hashCode() isn't unique, but it can't be(https://sigpwned.com/2018/08/10/string-hashcode-is-plenty-unique/). And `hash = -1 * hash` will double the probability of conflict.
   In other words, what will happen if there is a conflict? Does the conflict will lead to a wrong SelfDiscovery? If not, I think `String.hascode()` is good enough.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] zhangyue19921010 commented on a change in pull request #10961: k8s discovery module: fix issue for druid.host being more than 63chars not permitted as k8s resource label value

Posted by GitBox <gi...@apache.org>.
zhangyue19921010 commented on a change in pull request #10961:
URL: https://github.com/apache/druid/pull/10961#discussion_r589981198



##########
File path: extensions-core/kubernetes-extensions/src/main/java/org/apache/druid/k8s/discovery/K8sDruidNodeAnnouncer.java
##########
@@ -237,30 +236,14 @@ private String getPodDefAnnocationPath(String annotation)
     return StringUtils.format("%s/%s", POD_ANNOTATIONS_PATH_PREFIX, annotation);
   }
 
-  private static String encodeHostPort(String hostPort)
+  // a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and
+  // must start and end with an alphanumeric character
+  private static String hashEncodeStringForLabelValue(String str)
   {
-    //K8S requires that label values must match regex (([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?
-    //So, it is essential to replace ':' with '-'
-
-    // it is assumed that hostname does not have ':' in it except for separating host and port
-    Preconditions.checkState(
-        hostPort.indexOf(':') == hostPort.lastIndexOf(':'),
-        "hostname in host:port[%s] has ':' in it", hostPort
-    );
-
-    return hostPort.replace(':', '-');
-  }
-
-  private String replaceLast(String str, char oldChar, char newChar)
-  {
-    char[] chars = str.toCharArray();
-    for (int i = chars.length - 1; i >= 0; i--) {
-      if (chars[i] == oldChar) {
-        chars[i] = newChar;
-        break;
-      }
+    int hash = str.hashCode();
+    if (hash < 0) {
+      hash = -1 * hash;

Review comment:
       Thanks for your explanation :)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org