private static void enrichMetadata()

in flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/utils/FlinkResourceExceptionUtils.java [144:193]


    private static void enrichMetadata(
            Throwable throwable,
            FlinkResourceException flinkResourceException,
            int lengthThreshold,
            Map<String, String> labelMapper) {
        if (flinkResourceException.getAdditionalMetadata() == null) {
            flinkResourceException.setAdditionalMetadata(new HashMap<>());
        }

        if (throwable instanceof RestClientException) {
            flinkResourceException
                    .getAdditionalMetadata()
                    .put(
                            "httpResponseCode",
                            ((RestClientException) throwable).getHttpResponseStatus().code());
        }

        if (throwable instanceof DeploymentFailedException) {
            getSubstringWithMaxLength(
                            ((DeploymentFailedException) throwable).getReason(), lengthThreshold)
                    .ifPresent(
                            reason ->
                                    flinkResourceException
                                            .getAdditionalMetadata()
                                            .put("reason", reason));
        }

        labelMapper
                .entrySet()
                .forEach(
                        (entry) -> {
                            Pattern pattern = Pattern.compile(entry.getKey());

                            org.apache.flink.util.ExceptionUtils.findThrowable(
                                            throwable,
                                            t ->
                                                    pattern.matcher(
                                                                    Optional.ofNullable(
                                                                                    t.getMessage())
                                                                            .orElse(""))
                                                            .find())
                                    .ifPresent(
                                            (t) -> {
                                                enrichMetadataWithLabelMapper(
                                                        flinkResourceException, entry.getValue());
                                            });
                        });

        // This section can be extended to enrich more metadata in the future.
    }