suneet-s commented on code in PR #16510: URL: https://github.com/apache/druid/pull/16510#discussion_r1630653731
########## extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/execution/DynamicTaskPodTemplateSelectStrategy.java: ########## @@ -0,0 +1,103 @@ +/* + * 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.execution; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.fabric8.kubernetes.api.model.PodTemplate; +import org.apache.druid.indexing.common.task.Task; +import org.apache.druid.java.util.common.Pair; + +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * Implements {@link PodTemplateSelectStrategy} by dynamically evaluating a series of selectors. + * Each selector corresponds to a potential task template key. + */ +public class DynamicTaskPodTemplateSelectStrategy implements PodTemplateSelectStrategy Review Comment: ```suggestion public class TaskPropertiesPodTemplateSelectStrategy implements PodTemplateSelectStrategy ``` ########## extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/KubernetesPeonClient.java: ########## @@ -270,10 +270,16 @@ Pod getPeonPodWithRetries(KubernetesClient client, String jobName, int quietTrie } } - private void emitK8sPodMetrics(Task task, String metric, long durationMs) + private void emitK8sPodMetrics(Task task, Job job, String metric, long durationMs) { ServiceMetricEvent.Builder metricBuilder = new ServiceMetricEvent.Builder(); IndexTaskUtils.setTaskDimensions(metricBuilder, task); + if (job.getMetadata() != null && job.getMetadata().getAnnotations() != null) { + metricBuilder.setDimensionIfNotNull( + "podTemplate", + job.getMetadata().getAnnotations().get(DruidK8sConstants.POD_TEMPLATE_KEY) + ); + } Review Comment: What is the use case for knowing the template name in the annotations / peon startup time metric? ########## extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/execution/DynamicTaskPodTemplateSelectStrategy.java: ########## @@ -0,0 +1,103 @@ +/* + * 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.execution; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.fabric8.kubernetes.api.model.PodTemplate; +import org.apache.druid.indexing.common.task.Task; +import org.apache.druid.java.util.common.Pair; + +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * Implements {@link PodTemplateSelectStrategy} by dynamically evaluating a series of selectors. + * Each selector corresponds to a potential task template key. + */ +public class DynamicTaskPodTemplateSelectStrategy implements PodTemplateSelectStrategy +{ + private List<Selector> templateSelectors; + + @JsonCreator + public DynamicTaskPodTemplateSelectStrategy( + @JsonProperty("templateSelectors") List<Selector> templateSelectors + ) + { + this.templateSelectors = templateSelectors; + } + + /** + * Evaluates the provided task against the set selectors to determine its template. + * + * @param task the task to be checked + * @return the template if a selector matches, otherwise fallback to base template + */ + @Override + public Pair<String, PodTemplate> getPodTemplateForTask(Task task, Map<String, PodTemplate> templates) + { + String templateKey; + if (templateSelectors == null) { + templateKey = null; + } else { + templateKey = templateSelectors.stream() + .filter(selector -> selector.evaluate(task)) + .findFirst() + .map(Selector::getSelectionKey) Review Comment: ```suggestion .map(Selector::getTemplateKey) ``` ########## extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/execution/DynamicTaskPodTemplateSelectStrategy.java: ########## @@ -0,0 +1,103 @@ +/* + * 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.execution; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.fabric8.kubernetes.api.model.PodTemplate; +import org.apache.druid.indexing.common.task.Task; +import org.apache.druid.java.util.common.Pair; + +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * Implements {@link PodTemplateSelectStrategy} by dynamically evaluating a series of selectors. + * Each selector corresponds to a potential task template key. + */ +public class DynamicTaskPodTemplateSelectStrategy implements PodTemplateSelectStrategy +{ + private List<Selector> templateSelectors; Review Comment: ```suggestion @NonNull private final List<Selector> templateSelectors; ``` ########## extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/execution/PodTemplateSelectStrategy.java: ########## @@ -0,0 +1,63 @@ +/* + * 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.execution; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import io.fabric8.kubernetes.api.model.PodTemplate; +import org.apache.druid.indexing.common.task.Task; +import org.apache.druid.java.util.common.Pair; + +import java.util.Map; + +/** + * Defines a strategy for selecting the Pod template of tasks based on specific conditions. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", defaultImpl = TaskTypePodTemplateSelectStrategy.class) +@JsonSubTypes(value = { + @JsonSubTypes.Type(name = "default", value = TaskTypePodTemplateSelectStrategy.class), + @JsonSubTypes.Type(name = "dynamicTask", value = DynamicTaskPodTemplateSelectStrategy.class), +}) +public interface PodTemplateSelectStrategy +{ + /** + * Determines the appropriate Pod template for a task by evaluating its properties. This selection + * allows for customized resource allocation and management tailored to the task's specific requirements. + * + * @param task The task for which the Pod template is determined. + * @return A key-value pair representing the selected Pod template. If no matching template is found, + * the method falls back to a base template. Review Comment: What if no base template is found? I think the interface should probably throw an exception if it can not find a template for the task. ########## extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/execution/PodTemplateSelectStrategy.java: ########## @@ -0,0 +1,63 @@ +/* + * 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.execution; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import io.fabric8.kubernetes.api.model.PodTemplate; +import org.apache.druid.indexing.common.task.Task; +import org.apache.druid.java.util.common.Pair; + +import java.util.Map; + +/** + * Defines a strategy for selecting the Pod template of tasks based on specific conditions. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", defaultImpl = TaskTypePodTemplateSelectStrategy.class) +@JsonSubTypes(value = { + @JsonSubTypes.Type(name = "default", value = TaskTypePodTemplateSelectStrategy.class), + @JsonSubTypes.Type(name = "dynamicTask", value = DynamicTaskPodTemplateSelectStrategy.class), +}) +public interface PodTemplateSelectStrategy +{ + /** + * Determines the appropriate Pod template for a task by evaluating its properties. This selection + * allows for customized resource allocation and management tailored to the task's specific requirements. + * + * @param task The task for which the Pod template is determined. + * @return A key-value pair representing the selected Pod template. If no matching template is found, + * the method falls back to a base template. + */ + Pair<String, PodTemplate> getPodTemplateForTask(Task task, Map<String, PodTemplate> templates); + + default Pair<String, PodTemplate> getTemplateOrDefault(String templateKey, Map<String, PodTemplate> templates) + { + if (templates == null) { + return null; + } + + PodTemplate podTemplate = templates.get(templateKey); + if (podTemplate != null) { + return Pair.of(templateKey, podTemplate); + } else { + return Pair.of("base", templates.get("base")); Review Comment: This used to throw an ISE if `base` did not exist ########## extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/execution/DynamicTaskPodTemplateSelectStrategy.java: ########## @@ -0,0 +1,103 @@ +/* + * 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.execution; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.fabric8.kubernetes.api.model.PodTemplate; +import org.apache.druid.indexing.common.task.Task; +import org.apache.druid.java.util.common.Pair; + +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * Implements {@link PodTemplateSelectStrategy} by dynamically evaluating a series of selectors. + * Each selector corresponds to a potential task template key. + */ +public class DynamicTaskPodTemplateSelectStrategy implements PodTemplateSelectStrategy +{ + private List<Selector> templateSelectors; + + @JsonCreator + public DynamicTaskPodTemplateSelectStrategy( + @JsonProperty("templateSelectors") List<Selector> templateSelectors + ) + { + this.templateSelectors = templateSelectors; + } + + /** + * Evaluates the provided task against the set selectors to determine its template. + * + * @param task the task to be checked + * @return the template if a selector matches, otherwise fallback to base template + */ + @Override + public Pair<String, PodTemplate> getPodTemplateForTask(Task task, Map<String, PodTemplate> templates) + { + String templateKey; + if (templateSelectors == null) { + templateKey = null; + } else { + templateKey = templateSelectors.stream() + .filter(selector -> selector.evaluate(task)) + .findFirst() + .map(Selector::getSelectionKey) + .orElse(null); Review Comment: Return an expected default so we don't need to deal with null handling elsewhere ```suggestion .orElse("base"); ``` ########## extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/KubernetesOverlordModule.java: ########## @@ -75,6 +79,7 @@ public void configure(Binder binder) JsonConfigProvider.bind(binder, IndexingServiceModuleHelper.INDEXER_RUNNER_PROPERTY_PREFIX, KubernetesTaskRunnerConfig.class); JsonConfigProvider.bind(binder, K8SANDWORKER_PROPERTIES_PREFIX, KubernetesAndWorkerTaskRunnerConfig.class); JsonConfigProvider.bind(binder, "druid.indexer.queue", TaskQueueConfig.class); + JacksonConfigProvider.bind(binder, KubernetesTaskRunnerDynamicConfig.CONFIG_KEY, KubernetesTaskRunnerDynamicConfig.class, null); Review Comment: ```suggestion JacksonConfigProvider.bind(binder, KubernetesTaskRunnerDynamicConfig.CONFIG_KEY, KubernetesTaskRunnerDynamicConfig.class, DEFAULT_DYNAMIC_CONFIG); ``` bind a default implementation so that we do not need to deal with nulls elsewhere in the code ########## extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/execution/DynamicTaskPodTemplateSelectStrategy.java: ########## @@ -0,0 +1,103 @@ +/* + * 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.execution; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.fabric8.kubernetes.api.model.PodTemplate; +import org.apache.druid.indexing.common.task.Task; +import org.apache.druid.java.util.common.Pair; + +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * Implements {@link PodTemplateSelectStrategy} by dynamically evaluating a series of selectors. + * Each selector corresponds to a potential task template key. + */ +public class DynamicTaskPodTemplateSelectStrategy implements PodTemplateSelectStrategy +{ + private List<Selector> templateSelectors; + + @JsonCreator + public DynamicTaskPodTemplateSelectStrategy( + @JsonProperty("templateSelectors") List<Selector> templateSelectors + ) + { + this.templateSelectors = templateSelectors; + } + + /** + * Evaluates the provided task against the set selectors to determine its template. + * + * @param task the task to be checked + * @return the template if a selector matches, otherwise fallback to base template + */ + @Override + public Pair<String, PodTemplate> getPodTemplateForTask(Task task, Map<String, PodTemplate> templates) + { + String templateKey; + if (templateSelectors == null) { + templateKey = null; Review Comment: ```suggestion templateKey = "base"; ``` ########## extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/execution/PodTemplateSelectStrategy.java: ########## @@ -0,0 +1,63 @@ +/* + * 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.execution; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import io.fabric8.kubernetes.api.model.PodTemplate; +import org.apache.druid.indexing.common.task.Task; +import org.apache.druid.java.util.common.Pair; + +import java.util.Map; + +/** + * Defines a strategy for selecting the Pod template of tasks based on specific conditions. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", defaultImpl = TaskTypePodTemplateSelectStrategy.class) +@JsonSubTypes(value = { + @JsonSubTypes.Type(name = "default", value = TaskTypePodTemplateSelectStrategy.class), + @JsonSubTypes.Type(name = "dynamicTask", value = DynamicTaskPodTemplateSelectStrategy.class), +}) +public interface PodTemplateSelectStrategy +{ + /** + * Determines the appropriate Pod template for a task by evaluating its properties. This selection + * allows for customized resource allocation and management tailored to the task's specific requirements. + * + * @param task The task for which the Pod template is determined. + * @return A key-value pair representing the selected Pod template. If no matching template is found, + * the method falls back to a base template. + */ + Pair<String, PodTemplate> getPodTemplateForTask(Task task, Map<String, PodTemplate> templates); + + default Pair<String, PodTemplate> getTemplateOrDefault(String templateKey, Map<String, PodTemplate> templates) Review Comment: I do not think this should be part of the interface definition. To a caller, it is not clear whether to call `getPodTemplateForTask` or `getTemplateOrDefault` ########## extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/execution/DynamicTaskPodTemplateSelectStrategy.java: ########## @@ -0,0 +1,103 @@ +/* + * 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.execution; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.fabric8.kubernetes.api.model.PodTemplate; +import org.apache.druid.indexing.common.task.Task; +import org.apache.druid.java.util.common.Pair; + +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * Implements {@link PodTemplateSelectStrategy} by dynamically evaluating a series of selectors. + * Each selector corresponds to a potential task template key. + */ +public class DynamicTaskPodTemplateSelectStrategy implements PodTemplateSelectStrategy +{ + private List<Selector> templateSelectors; + + @JsonCreator + public DynamicTaskPodTemplateSelectStrategy( + @JsonProperty("templateSelectors") List<Selector> templateSelectors + ) + { + this.templateSelectors = templateSelectors; Review Comment: Can we add a null check here, so we don't need special null handling elsewhere ########## extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/execution/KubernetesTaskExecutionConfigResource.java: ########## @@ -0,0 +1,159 @@ +/* + * 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.execution; + +import com.google.common.collect.ImmutableMap; +import com.sun.jersey.spi.container.ResourceFilters; +import org.apache.druid.audit.AuditEntry; +import org.apache.druid.audit.AuditManager; +import org.apache.druid.common.config.ConfigManager; +import org.apache.druid.common.config.JacksonConfigManager; +import org.apache.druid.java.util.common.Intervals; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.server.http.security.ConfigResourceFilter; +import org.apache.druid.server.security.AuthorizationUtils; +import org.joda.time.Interval; + +import javax.inject.Inject; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.List; +import java.util.concurrent.atomic.AtomicReference; + +/** + * Resource that manages Kubernetes-specific execution configurations for running tasks. + * + * <p>This class handles the CRUD operations for execution configurations and provides + * endpoints to update, retrieve, and manage the history of these configurations.</p> + */ +@Path("/druid/indexer/v1/k8s/taskRunner") +public class KubernetesTaskExecutionConfigResource Review Comment: ```suggestion @Path("/druid/indexer/v1/k8s/taskRunner/executionConfig") public class KubernetesTaskExecutionConfigResource ``` So that the class name matches the URL, then the functions should only specify the `@Path` annotation if they need a path under `.../executionConfig` -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
