jiangzho commented on code in PR #23:
URL: 
https://github.com/apache/spark-kubernetes-operator/pull/23#discussion_r1690622504


##########
spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/MetricsSystem.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.spark.k8s.operator.metrics;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import com.codahale.metrics.MetricFilter;
+import com.codahale.metrics.MetricRegistry;
+import lombok.Data;
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.spark.k8s.operator.metrics.source.OperatorJvmSource;
+import org.apache.spark.metrics.sink.Sink;
+import org.apache.spark.metrics.source.Source;
+
+@Slf4j
+public class MetricsSystem {
+  private final AtomicBoolean running = new AtomicBoolean(false);
+  @Getter private final Set<Sink> sinks;
+  @Getter private final Set<Source> sources;
+  @Getter private final MetricRegistry registry;
+  @Getter private final Properties properties;
+  // PrometheusPullModelHandler is registered by default, metrics exposed via 
http port
+  @Getter private final PrometheusPullModelHandler prometheusPullModelHandler;
+  private final Map<String, SinkProps> sinkPropertiesMap;
+
+  public MetricsSystem() {
+    this(new Properties());
+  }
+
+  public MetricsSystem(Properties properties) {
+    this.sources = new HashSet<>();
+    this.sinks = new HashSet<>();
+    this.registry = new MetricRegistry();
+    this.properties = properties;
+    this.sinkPropertiesMap = 
MetricsSystemFactory.parseSinkProperties(this.properties);
+    // Add default sinks
+    this.prometheusPullModelHandler = new PrometheusPullModelHandler(new 
Properties(), registry);
+    this.sinks.add(prometheusPullModelHandler);
+  }
+
+  public void start() {
+    if (running.get()) {
+      throw new IllegalStateException(
+          "Attempting to start a MetricsSystem that is already running");
+    }
+    running.set(true);
+    registerDefaultSources();
+    registerSinks();
+    sinks.forEach(Sink::start);
+  }
+
+  public void stop() {
+    if (running.get()) {
+      sinks.forEach(Sink::stop);
+      registry.removeMatching(MetricFilter.ALL);
+    } else {
+      log.error("Stopping a MetricsSystem that is not running");

Review Comment:
   As recommended by PMD, we enabled according gradle task to [enforce guard 
log 
statement](https://pmd.github.io/pmd/pmd_rules_java_bestpractices.html#guardlogstatement)
 when associate String creation and manipulation. I think this is not reported 
for no string manipulation



##########
spark-operator/src/main/java/org/apache/spark/k8s/operator/utils/SparkExceptionUtils.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.spark.k8s.operator.utils;
+
+import io.fabric8.kubernetes.client.KubernetesClientException;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.exception.ExceptionUtils;
+
+public class SparkExceptionUtils {
+  public static boolean 
isConflictForExistingResource(KubernetesClientException e) {
+    return e != null
+        && e.getCode() == 409
+        && e.getStatus() != null
+        && StringUtils.isNotEmpty(e.getStatus().toString())
+        && e.getStatus().toString().toLowerCase().contains("alreadyexists");

Review Comment:
   This is used to handle only specific 409 cases (e.g. request timed out but 
the resource was actually created, then this help  the reconciler to proceed). 
   
   For other 409 conflicts - quota or status patch .etc, they are handled 
separately in according reconcile logic.



##########
spark-operator/src/main/java/org/apache/spark/k8s/operator/config/SparkOperatorConf.java:
##########
@@ -0,0 +1,463 @@
+/*
+ * 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.spark.k8s.operator.config;
+
+import java.time.Duration;
+
+import io.javaoperatorsdk.operator.api.config.LeaderElectionConfiguration;
+import io.javaoperatorsdk.operator.processing.event.rate.LinearRateLimiter;
+import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter;
+import io.javaoperatorsdk.operator.processing.retry.GenericRetry;
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.spark.k8s.operator.utils.Utils;
+
+/** Spark Operator Configuration options. */
+@Slf4j
+public class SparkOperatorConf {
+  public static final ConfigOption<String> OPERATOR_APP_NAME =
+      ConfigOption.<String>builder()
+          .key("spark.kubernetes.operator.name")
+          .enableDynamicOverride(false)
+          .description("Name of the operator.")
+          .typeParameterClass(String.class)
+          .defaultValue("spark-kubernetes-operator")
+          .build();
+
+  public static final ConfigOption<String> OPERATOR_NAMESPACE =
+      ConfigOption.<String>builder()
+          .key("spark.kubernetes.operator.namespace")
+          .enableDynamicOverride(false)
+          .description("Namespace that operator is deployed within.")
+          .typeParameterClass(String.class)
+          .defaultValue("default")
+          .build();
+
+  public static final ConfigOption<String> OPERATOR_WATCHED_NAMESPACES =
+      ConfigOption.<String>builder()
+          .key("spark.kubernetes.operator.watchedNamespaces")
+          .enableDynamicOverride(true)
+          .description(
+              "Comma-separated list of namespaces that the operator would be 
watching for "
+                  + "Spark resources. If set to '*' or unset, operator would 
watch all namespaces.")

Review Comment:
   Yep! I was hesitating about the 'unset' (which is under the hood can be 
considered as not setting namespaces),  but indeed it can be quite confusing at 
properties level. I'd update this to advice user use `*` only instead of unset.



-- 
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: reviews-unsubscr...@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to