[GitHub] [flink-kubernetes-operator] darenwkt commented on a diff in pull request #409: [FLINK-29708] Convert CR Error field to JSON with enriched exception …

2022-10-24 Thread GitBox


darenwkt commented on code in PR #409:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/409#discussion_r1003776097


##
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/utils/FlinkResourceExceptionUtils.java:
##
@@ -0,0 +1,118 @@
+/*
+ * 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.flink.kubernetes.operator.utils;
+
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.apache.flink.kubernetes.operator.crd.AbstractFlinkResource;
+import org.apache.flink.kubernetes.operator.crd.spec.AbstractFlinkSpec;
+import 
org.apache.flink.kubernetes.operator.exception.DeploymentFailedException;
+import org.apache.flink.kubernetes.operator.exception.FlinkResourceException;
+import org.apache.flink.kubernetes.operator.exception.ReconciliationException;
+import org.apache.flink.runtime.rest.util.RestClientException;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/** Flink Resource Exception utilities. */
+public final class FlinkResourceExceptionUtils {
+
+public static  void 
updateFlinkResourceException(
+Throwable throwable, R resource) {
+
+FlinkResourceException flinkResourceException =
+getFlinkResourceException(throwable, 
getStackTraceEnabled(resource));
+
+try {
+((AbstractFlinkResource) resource)
+.getStatus()
+.setError(convertToJson(flinkResourceException));
+} catch (Exception e) {
+// Rollback to setting error string/message to CRD
+((AbstractFlinkResource) resource)
+.getStatus()
+.setError(
+(e instanceof ReconciliationException)
+? e.getCause().toString()
+: e.toString());
+}
+}
+
+private static  boolean 
getStackTraceEnabled(R resource) {
+return Optional.ofNullable((AbstractFlinkSpec) resource.getSpec())
+.map(AbstractFlinkSpec::isStackTraceEnabled)
+.orElse(false);
+}
+
+private static FlinkResourceException getFlinkResourceException(
+Throwable throwable, boolean isStackTraceEnabled) {
+FlinkResourceException flinkResourceException =
+convertToFlinkResourceException(throwable, 
isStackTraceEnabled);
+
+flinkResourceException.setThrowableList(
+ExceptionUtils.getThrowableList(
+throwable.getCause())
+.stream()
+.map((t) -> convertToFlinkResourceException(t, false))
+.collect(Collectors.toList()));
+
+return flinkResourceException;
+}
+
+private static FlinkResourceException convertToFlinkResourceException(
+Throwable throwable, boolean isStackTraceEnabled) {
+FlinkResourceException flinkResourceException =
+FlinkResourceException.builder()
+.type(throwable.getClass().getName())
+.message(throwable.getMessage())
+.build();
+
+if (isStackTraceEnabled) {
+
flinkResourceException.setStackTraceElements(throwable.getStackTrace());
+}
+
+enrichMetadata(throwable, flinkResourceException);
+
+return flinkResourceException;
+}
+
+private static void enrichMetadata(
+Throwable throwable, FlinkResourceException 
flinkResourceException) {
+if (throwable instanceof RestClientException) {
+flinkResourceException.setAdditionalMetadata(
+Map.of(
+"httpResponseCode",
+((RestClientException) 
throwable).getHttpResponseStatus().code()));
+}
+
+if (throwable instanceof DeploymentFailedException) {
+flinkResourceException.setAdditionalMetadata(
+Map.of("reason", ((DeploymentFailedException) 

[GitHub] [flink-kubernetes-operator] darenwkt commented on a diff in pull request #409: [FLINK-29708] Convert CR Error field to JSON with enriched exception …

2022-10-24 Thread GitBox


darenwkt commented on code in PR #409:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/409#discussion_r1003775892


##
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/utils/FlinkResourceExceptionUtils.java:
##
@@ -0,0 +1,118 @@
+/*
+ * 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.flink.kubernetes.operator.utils;
+
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.apache.flink.kubernetes.operator.crd.AbstractFlinkResource;
+import org.apache.flink.kubernetes.operator.crd.spec.AbstractFlinkSpec;
+import 
org.apache.flink.kubernetes.operator.exception.DeploymentFailedException;
+import org.apache.flink.kubernetes.operator.exception.FlinkResourceException;
+import org.apache.flink.kubernetes.operator.exception.ReconciliationException;
+import org.apache.flink.runtime.rest.util.RestClientException;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/** Flink Resource Exception utilities. */
+public final class FlinkResourceExceptionUtils {
+
+public static  void 
updateFlinkResourceException(
+Throwable throwable, R resource) {
+
+FlinkResourceException flinkResourceException =
+getFlinkResourceException(throwable, 
getStackTraceEnabled(resource));
+
+try {
+((AbstractFlinkResource) resource)
+.getStatus()
+.setError(convertToJson(flinkResourceException));
+} catch (Exception e) {
+// Rollback to setting error string/message to CRD
+((AbstractFlinkResource) resource)
+.getStatus()
+.setError(
+(e instanceof ReconciliationException)
+? e.getCause().toString()
+: e.toString());
+}
+}
+
+private static  boolean 
getStackTraceEnabled(R resource) {
+return Optional.ofNullable((AbstractFlinkSpec) resource.getSpec())
+.map(AbstractFlinkSpec::isStackTraceEnabled)
+.orElse(false);
+}
+
+private static FlinkResourceException getFlinkResourceException(
+Throwable throwable, boolean isStackTraceEnabled) {
+FlinkResourceException flinkResourceException =
+convertToFlinkResourceException(throwable, 
isStackTraceEnabled);
+
+flinkResourceException.setThrowableList(
+ExceptionUtils.getThrowableList(
+throwable.getCause())
+.stream()
+.map((t) -> convertToFlinkResourceException(t, false))
+.collect(Collectors.toList()));
+
+return flinkResourceException;
+}
+
+private static FlinkResourceException convertToFlinkResourceException(
+Throwable throwable, boolean isStackTraceEnabled) {
+FlinkResourceException flinkResourceException =
+FlinkResourceException.builder()
+.type(throwable.getClass().getName())
+.message(throwable.getMessage())
+.build();
+
+if (isStackTraceEnabled) {
+
flinkResourceException.setStackTraceElements(throwable.getStackTrace());

Review Comment:
   Added ConfigOption to limit stackTrace list size



-- 
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: issues-unsubscr...@flink.apache.org

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



[GitHub] [flink-kubernetes-operator] darenwkt commented on a diff in pull request #409: [FLINK-29708] Convert CR Error field to JSON with enriched exception …

2022-10-24 Thread GitBox


darenwkt commented on code in PR #409:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/409#discussion_r1003775450


##
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/utils/FlinkResourceExceptionUtils.java:
##
@@ -0,0 +1,118 @@
+/*
+ * 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.flink.kubernetes.operator.utils;
+
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.apache.flink.kubernetes.operator.crd.AbstractFlinkResource;
+import org.apache.flink.kubernetes.operator.crd.spec.AbstractFlinkSpec;
+import 
org.apache.flink.kubernetes.operator.exception.DeploymentFailedException;
+import org.apache.flink.kubernetes.operator.exception.FlinkResourceException;
+import org.apache.flink.kubernetes.operator.exception.ReconciliationException;
+import org.apache.flink.runtime.rest.util.RestClientException;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/** Flink Resource Exception utilities. */
+public final class FlinkResourceExceptionUtils {
+
+public static  void 
updateFlinkResourceException(
+Throwable throwable, R resource) {
+
+FlinkResourceException flinkResourceException =
+getFlinkResourceException(throwable, 
getStackTraceEnabled(resource));
+
+try {
+((AbstractFlinkResource) resource)
+.getStatus()
+.setError(convertToJson(flinkResourceException));
+} catch (Exception e) {
+// Rollback to setting error string/message to CRD
+((AbstractFlinkResource) resource)
+.getStatus()
+.setError(
+(e instanceof ReconciliationException)
+? e.getCause().toString()
+: e.toString());
+}
+}
+
+private static  boolean 
getStackTraceEnabled(R resource) {
+return Optional.ofNullable((AbstractFlinkSpec) resource.getSpec())
+.map(AbstractFlinkSpec::isStackTraceEnabled)
+.orElse(false);
+}
+
+private static FlinkResourceException getFlinkResourceException(
+Throwable throwable, boolean isStackTraceEnabled) {
+FlinkResourceException flinkResourceException =
+convertToFlinkResourceException(throwable, 
isStackTraceEnabled);
+
+flinkResourceException.setThrowableList(
+ExceptionUtils.getThrowableList(
+throwable.getCause())
+.stream()
+.map((t) -> convertToFlinkResourceException(t, false))
+.collect(Collectors.toList()));

Review Comment:
   I have added the default limit as ConfigOption and set it to 2



-- 
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: issues-unsubscr...@flink.apache.org

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



[GitHub] [flink-kubernetes-operator] darenwkt commented on a diff in pull request #409: [FLINK-29708] Convert CR Error field to JSON with enriched exception …

2022-10-24 Thread GitBox


darenwkt commented on code in PR #409:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/409#discussion_r1003775090


##
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/utils/FlinkResourceExceptionUtils.java:
##
@@ -0,0 +1,118 @@
+/*
+ * 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.flink.kubernetes.operator.utils;
+
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.apache.flink.kubernetes.operator.crd.AbstractFlinkResource;
+import org.apache.flink.kubernetes.operator.crd.spec.AbstractFlinkSpec;
+import 
org.apache.flink.kubernetes.operator.exception.DeploymentFailedException;
+import org.apache.flink.kubernetes.operator.exception.FlinkResourceException;
+import org.apache.flink.kubernetes.operator.exception.ReconciliationException;
+import org.apache.flink.runtime.rest.util.RestClientException;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/** Flink Resource Exception utilities. */
+public final class FlinkResourceExceptionUtils {
+
+public static  void 
updateFlinkResourceException(
+Throwable throwable, R resource) {
+
+FlinkResourceException flinkResourceException =
+getFlinkResourceException(throwable, 
getStackTraceEnabled(resource));
+
+try {
+((AbstractFlinkResource) resource)
+.getStatus()
+.setError(convertToJson(flinkResourceException));
+} catch (Exception e) {
+// Rollback to setting error string/message to CRD
+((AbstractFlinkResource) resource)
+.getStatus()
+.setError(
+(e instanceof ReconciliationException)
+? e.getCause().toString()
+: e.toString());
+}
+}
+
+private static  boolean 
getStackTraceEnabled(R resource) {
+return Optional.ofNullable((AbstractFlinkSpec) resource.getSpec())
+.map(AbstractFlinkSpec::isStackTraceEnabled)
+.orElse(false);
+}
+
+private static FlinkResourceException getFlinkResourceException(
+Throwable throwable, boolean isStackTraceEnabled) {
+FlinkResourceException flinkResourceException =
+convertToFlinkResourceException(throwable, 
isStackTraceEnabled);
+
+flinkResourceException.setThrowableList(
+ExceptionUtils.getThrowableList(
+throwable.getCause())
+.stream()
+.map((t) -> convertToFlinkResourceException(t, false))
+.collect(Collectors.toList()));
+
+return flinkResourceException;
+}
+
+private static FlinkResourceException convertToFlinkResourceException(
+Throwable throwable, boolean isStackTraceEnabled) {
+FlinkResourceException flinkResourceException =
+FlinkResourceException.builder()
+.type(throwable.getClass().getName())
+.message(throwable.getMessage())
+.build();
+
+if (isStackTraceEnabled) {
+
flinkResourceException.setStackTraceElements(throwable.getStackTrace());
+}
+
+enrichMetadata(throwable, flinkResourceException);
+
+return flinkResourceException;
+}
+
+private static void enrichMetadata(
+Throwable throwable, FlinkResourceException 
flinkResourceException) {
+if (throwable instanceof RestClientException) {
+flinkResourceException.setAdditionalMetadata(
+Map.of(
+"httpResponseCode",
+((RestClientException) 
throwable).getHttpResponseStatus().code()));
+}
+
+if (throwable instanceof DeploymentFailedException) {
+flinkResourceException.setAdditionalMetadata(
+Map.of("reason", ((DeploymentFailedException) 

[GitHub] [flink-kubernetes-operator] darenwkt commented on a diff in pull request #409: [FLINK-29708] Convert CR Error field to JSON with enriched exception …

2022-10-24 Thread GitBox


darenwkt commented on code in PR #409:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/409#discussion_r1003773876


##
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/crd/spec/AbstractFlinkSpec.java:
##
@@ -57,6 +57,9 @@ public abstract class AbstractFlinkSpec implements 
Diffable {
 })
 private Map flinkConfiguration;
 
+/** Exception specification to include stack trace in CRD. */
+private boolean stackTraceEnabled;

Review Comment:
   Thanks for the suggestion, I have moved them to ConfigOption along with new 
config to limit the stacktrace, throwable size etc...



-- 
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: issues-unsubscr...@flink.apache.org

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