You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "georgew5656 (via GitHub)" <gi...@apache.org> on 2023/05/15 18:05:09 UTC

[GitHub] [druid] georgew5656 opened a new pull request, #14282: Fix labels

georgew5656 opened a new pull request, #14282:
URL: https://github.com/apache/druid/pull/14282

   Fixes a issue with launching jobs introduced in https://github.com/apache/druid/commit/eed5f4f2916a0b7458b3c2b819afb370d72f610e
   
   ### Description
   Realized when testing the recent changes to the kubernetes task runner that task id and task group id can't be directly passed as kubernetes labels the way they can be passed as kubernetes annotations.
   
   #### Release note
   Fixes issue with launching k8s jobs.
   
   ##### Key changed/added classes in this PR
   Update pod template task adapter to parse labels properly.
   
   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.)
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] a release note entry in the PR description.
   - [ ] 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.
   - [X] 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.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

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] kfaraz commented on a diff in pull request #14282: Fix labels

Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #14282:
URL: https://github.com/apache/druid/pull/14282#discussion_r1194586315


##########
extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/KubernetesStringUtils.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.k8s.overlord.common;
+
+import org.apache.commons.lang3.RegExUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Locale;
+
+public class KubernetesStringUtils
+{
+  public static String parseStringToK8sLabel(String rawString)

Review Comment:
   Seems like more of a conversion operation than parsing. Maybe rename to `convertToK8sLabel` or something.



##########
extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/KubernetesStringUtils.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.k8s.overlord.common;
+
+import org.apache.commons.lang3.RegExUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Locale;
+
+public class KubernetesStringUtils

Review Comment:
   I suppose it can have other utility methods too in the future. Might as well just call it `K8sUtils`.



##########
extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/K8sTaskId.java:
##########
@@ -41,8 +38,7 @@ public K8sTaskId(String taskId)
   {
     this.originalTaskId = taskId;
     // replace all the ": - . _" to "", try to reduce the length of pod name and meet pod naming specifications 64 characters.

Review Comment:
   Move this comment to the javadoc of the new method.



##########
extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/K8sTaskId.java:
##########
@@ -41,8 +38,7 @@ public K8sTaskId(String taskId)
   {
     this.originalTaskId = taskId;
     // replace all the ": - . _" to "", try to reduce the length of pod name and meet pod naming specifications 64 characters.
-    this.k8sTaskId = StringUtils.left(RegExUtils.replaceAll(taskId, "[^a-zA-Z0-9\\\\s]", "")
-                                                .toLowerCase(Locale.ENGLISH), 63);
+    this.k8sTaskId = KubernetesStringUtils.parseStringToK8sLabel(taskId);

Review Comment:
   I know the existing code has this too but this truncation could cause loss of uniqueness. Is that not a concern? I assume it should be okay if they are just to be used as labels.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

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] kfaraz commented on a diff in pull request #14282: Fix labels

Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #14282:
URL: https://github.com/apache/druid/pull/14282#discussion_r1197983010


##########
extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/KubernetesOverlordUtils.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.k8s.overlord.common;
+
+import org.apache.commons.lang3.RegExUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Locale;
+import java.util.regex.Pattern;
+
+public class KubernetesOverlordUtils
+{
+  private static final Pattern K8S_LABEL_PATTERN = Pattern.compile("[^A-Za-z0-9_.-]");
+  // replace all the ": - . _" to "", try to reduce the length of pod name and meet pod naming specifications 64 characters.
+  private static final Pattern K8S_TASK_ID_PATTERN = Pattern.compile("[^a-zA-Z0-9\\\\s]");
+
+  public static String convertStringToK8sLabel(String rawString)

Review Comment:
   Javadoc for these methods would be nice to have but not a blocker for this PR.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

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] suneet-s commented on a diff in pull request #14282: Fix labels

Posted by "suneet-s (via GitHub)" <gi...@apache.org>.
suneet-s commented on code in PR #14282:
URL: https://github.com/apache/druid/pull/14282#discussion_r1195787192


##########
extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/taskadapter/PodTemplateTaskAdapter.java:
##########
@@ -243,16 +244,16 @@ private Map<String, String> getPodTemplateAnnotations(Task task) throws IOExcept
         .put(DruidK8sConstants.TASK_DATASOURCE, task.getDataSource())
         .build();
   }
-
+  
   private Map<String, String> getJobLabels(KubernetesTaskRunnerConfig config, Task task)
   {
     return ImmutableMap.<String, String>builder()
         .putAll(config.getLabels())
         .put(DruidK8sConstants.LABEL_KEY, "true")
-        .put(getDruidLabel(DruidK8sConstants.TASK_ID), task.getId())
-        .put(getDruidLabel(DruidK8sConstants.TASK_TYPE), task.getType())
-        .put(getDruidLabel(DruidK8sConstants.TASK_GROUP_ID), task.getGroupId())
-        .put(getDruidLabel(DruidK8sConstants.TASK_DATASOURCE), task.getDataSource())
+        .put(getDruidLabel(DruidK8sConstants.TASK_ID), KubernetesStringUtils.parseStringToK8sLabel(task.getId()))
+        .put(getDruidLabel(DruidK8sConstants.TASK_TYPE), KubernetesStringUtils.parseStringToK8sLabel(task.getType()))
+        .put(getDruidLabel(DruidK8sConstants.TASK_GROUP_ID), KubernetesStringUtils.parseStringToK8sLabel(task.getGroupId()))
+        .put(getDruidLabel(DruidK8sConstants.TASK_DATASOURCE), KubernetesStringUtils.parseStringToK8sLabel(task.getDataSource()))

Review Comment:
   I think it is quite common for datasources to include `_` or `-`. The parseStringToK8sLabel function replaces these characters, even though they are valida characters in a k8s label because a task id can be very long in an attempt to fit more relevant information into the task_id label.
   
   I think you should split `parseStringToK8sLabel` into 2 functions - one that just takes a string and makes it a k8s label value compliant string. And another function to deal with the task_ids



##########
extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/KubernetesStringUtils.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.k8s.overlord.common;
+
+import org.apache.commons.lang3.RegExUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Locale;
+
+public class KubernetesStringUtils
+{
+  public static String parseStringToK8sLabel(String rawString)
+  {
+    return rawString == null ? "" : StringUtils.left(RegExUtils.replaceAll(rawString, "[^a-zA-Z0-9\\\\s]", "")

Review Comment:
   I see this is not part of your change, but since we are adding this to a utility function, it would be better to move `"[^a-zA-Z0-9\\\\s]"` to a pattern so that the string does not need to be compiled to a Pattern everytime this function is called.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

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] georgew5656 commented on a diff in pull request #14282: Fix labels

Posted by "georgew5656 (via GitHub)" <gi...@apache.org>.
georgew5656 commented on code in PR #14282:
URL: https://github.com/apache/druid/pull/14282#discussion_r1196952135


##########
extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/KubernetesStringUtils.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.k8s.overlord.common;
+
+import org.apache.commons.lang3.RegExUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Locale;
+
+public class KubernetesStringUtils

Review Comment:
   called it KubernetesOverlordUtils to match the extension



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

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] suneet-s merged pull request #14282: Fix labels

Posted by "suneet-s (via GitHub)" <gi...@apache.org>.
suneet-s merged PR #14282:
URL: https://github.com/apache/druid/pull/14282


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

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] georgew5656 commented on a diff in pull request #14282: Fix labels

Posted by "georgew5656 (via GitHub)" <gi...@apache.org>.
georgew5656 commented on code in PR #14282:
URL: https://github.com/apache/druid/pull/14282#discussion_r1196636898


##########
extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/K8sTaskId.java:
##########
@@ -41,8 +38,7 @@ public K8sTaskId(String taskId)
   {
     this.originalTaskId = taskId;
     // replace all the ": - . _" to "", try to reduce the length of pod name and meet pod naming specifications 64 characters.
-    this.k8sTaskId = StringUtils.left(RegExUtils.replaceAll(taskId, "[^a-zA-Z0-9\\\\s]", "")
-                                                .toLowerCase(Locale.ENGLISH), 63);
+    this.k8sTaskId = KubernetesStringUtils.parseStringToK8sLabel(taskId);

Review Comment:
   it wouldn't be a concern with labels, but this is also what we name the job so there may be some concern there



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

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