You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "chenyuzhi459 (via GitHub)" <gi...@apache.org> on 2025/03/13 09:49:17 UTC

[PR] Draft PR [FLINK-36876] Add proxy for restClient [flink-kubernetes-operator]

chenyuzhi459 opened a new pull request, #956:
URL: https://github.com/apache/flink-kubernetes-operator/pull/956

   <!--
   *Thank you very much for contributing to the Apache Flink Kubernetes Operator - we are happy that you want to help us improve the project. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix][docs] Fix typo in event time introduction` or `[hotfix][javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can read more on how we use GitHub Actions for CI [here](https://nightlies.apache.org/flink/flink-kubernetes-operator-docs-main/docs/development/guide/#cicd).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   Add proxy for restClient, which supports to use shared `EventLoopGroup`
   
   
   ## Brief change log
   
   - *Introduce a new class `RestClientProxy` as the proxy of restClient*
   - *Introduce a new configuration: `kubernetes.operator.flink.client.io.threads` to specify the total thread of sharded eventLoopGroup*
   - *RestClientProxy supports to use sharded eventLoopGroup*
   
   
   
   ## Verifying this change
   Unit tests + manual verification
   
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (no)
     - The public API, i.e., is any changes to the `CustomResourceDescriptors`: (no)
     - Core observer or reconciler logic that is regularly executed: (yes)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (no)
     - If yes, how is the feature documented? (docs)
   


-- 
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-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-36876] Add proxy for restClient [flink-kubernetes-operator]

Posted by "gyfora (via GitHub)" <gi...@apache.org>.
gyfora commented on PR #956:
URL: https://github.com/apache/flink-kubernetes-operator/pull/956#issuecomment-2900402656

   Seems to be consistently broken, did you manage to build/test locally?


-- 
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-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-36876] Add proxy for restClient [flink-kubernetes-operator]

Posted by "chenyuzhi459 (via GitHub)" <gi...@apache.org>.
chenyuzhi459 commented on PR #956:
URL: https://github.com/apache/flink-kubernetes-operator/pull/956#issuecomment-2921169602

   Because `flink.client.io.threads=60` specifies the number of EventExecutors that handle event in NioEventLoopGroup, when creating NioEventLoopGroup, a corresponding number of EventExecutors will be created in the construction method of the parent class MultithreadEventExecutorGroup.
   
   In MultithreadEventExecutorGroup class, the implementation of EventExecutor is NioEventLoop.  When NioEventLoop is created, temporary files will be created through openSelector method.
   
   ![image](https://github.com/user-attachments/assets/964eea12-e022-48de-9a20-4f5cfb810f44)
   
   


-- 
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-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-36876] Add proxy for restClient [flink-kubernetes-operator]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #956:
URL: https://github.com/apache/flink-kubernetes-operator/pull/956#discussion_r2179916851


##########
docs/layouts/shortcodes/generated/kubernetes_operator_config_configuration.html:
##########
@@ -152,6 +152,12 @@
             <td>Duration</td>
             <td>The timeout for the observer to wait the flink rest client to return.</td>
         </tr>
+        <tr>
+            <td><h5>kubernetes.operator.flink.client.io.threads</h5></td>
+            <td style="word-wrap: break-word;">10</td>
+            <td>Integer</td>
+            <td>The maximum number of io threads used by the flink rest client.</td>

Review Comment:
   it would be worth detailing what the default is. I assume there is no maximum, is this a value of  -1 here?  



-- 
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-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-36876] Add proxy for restClient [flink-kubernetes-operator]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #956:
URL: https://github.com/apache/flink-kubernetes-operator/pull/956#discussion_r2179916851


##########
docs/layouts/shortcodes/generated/kubernetes_operator_config_configuration.html:
##########
@@ -152,6 +152,12 @@
             <td>Duration</td>
             <td>The timeout for the observer to wait the flink rest client to return.</td>
         </tr>
+        <tr>
+            <td><h5>kubernetes.operator.flink.client.io.threads</h5></td>
+            <td style="word-wrap: break-word;">10</td>
+            <td>Integer</td>
+            <td>The maximum number of io threads used by the flink rest client.</td>

Review Comment:
   it would be worth detailing what the default is. Can we say there is no maximum number of io thread?



-- 
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-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-36876] Add proxy for restClient [flink-kubernetes-operator]

Posted by "chenyuzhi459 (via GitHub)" <gi...@apache.org>.
chenyuzhi459 commented on PR #956:
URL: https://github.com/apache/flink-kubernetes-operator/pull/956#issuecomment-2899712189

   Could you help take a look at the latest CI failure issue, which doesn't seem to be related to this code commit?


-- 
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-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-36876] Add proxy for restClient [flink-kubernetes-operator]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #956:
URL: https://github.com/apache/flink-kubernetes-operator/pull/956#discussion_r2179921531


##########
docs/layouts/shortcodes/generated/kubernetes_operator_config_configuration.html:
##########
@@ -152,6 +152,12 @@
             <td>Duration</td>
             <td>The timeout for the observer to wait the flink rest client to return.</td>
         </tr>
+        <tr>
+            <td><h5>kubernetes.operator.flink.client.io.threads</h5></td>
+            <td style="word-wrap: break-word;">10</td>
+            <td>Integer</td>
+            <td>The maximum number of io threads used by the flink rest client.</td>

Review Comment:
   nit: io -> I/O



-- 
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-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-36876] Add proxy for restClient [flink-kubernetes-operator]

Posted by "chenyuzhi459 (via GitHub)" <gi...@apache.org>.
chenyuzhi459 commented on code in PR #956:
URL: https://github.com/apache/flink-kubernetes-operator/pull/956#discussion_r2099912200


##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/service/RestClientProxy.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.service;
+
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.rest.RestClient;
+import org.apache.flink.util.ConfigurationException;
+import org.apache.flink.util.Preconditions;
+
+import org.apache.flink.shaded.netty4.io.netty.bootstrap.AbstractBootstrap;
+import org.apache.flink.shaded.netty4.io.netty.bootstrap.Bootstrap;
+import org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Field;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+
+/** Proxy for the {@link RestClient}. */
+public class RestClientProxy extends RestClient {
+    private static final Logger LOG = LoggerFactory.getLogger(RestClientProxy.class);
+
+    private final boolean useSharedEventLoopGroup;
+    private Field groupField;
+    private Bootstrap bootstrap;
+    private CompletableFuture<Void> terminationFuture;
+
+    public RestClientProxy(
+            Configuration configuration,
+            ExecutorService executor,
+            String host,
+            int port,
+            EventLoopGroup sharedGroup)
+            throws ConfigurationException, NoSuchFieldException, IllegalAccessException {
+        super(configuration, executor, host, port);
+
+        if (sharedGroup != null) {
+            Preconditions.checkArgument(
+                    !sharedGroup.isShuttingDown() && !sharedGroup.isShutdown(),
+                    "provided eventLoopGroup is shut/shutting down");
+
+            // get private field
+            Field bootstrapField = RestClient.class.getDeclaredField("bootstrap");
+            Field terminationFutureField = RestClient.class.getDeclaredField("terminationFuture");
+            Field groupField = AbstractBootstrap.class.getDeclaredField("group");
+
+            bootstrapField.setAccessible(true);
+            terminationFutureField.setAccessible(true);
+            groupField.setAccessible(true);
+
+            this.terminationFuture = (CompletableFuture<Void>) terminationFutureField.get(this);
+            this.bootstrap = (Bootstrap) bootstrapField.get(this);
+            this.groupField = groupField;
+
+            // close previous group
+            bootstrap.config().group().shutdown();

Review Comment:
   Because PoolThreadCache is a request-thread-related cache, it is created and initialized when a request is made using the NioEventLoopGroup; 
   
   here it is created and closed immediately, with no requests in between, so there is no PoolThreadCache leakage issue.



-- 
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-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-36876] Add proxy for restClient [flink-kubernetes-operator]

Posted by "chenyuzhi459 (via GitHub)" <gi...@apache.org>.
chenyuzhi459 commented on PR #956:
URL: https://github.com/apache/flink-kubernetes-operator/pull/956#issuecomment-2958555002

   I have changed the default value of new param `flink.client.io.threads` to 10.


-- 
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-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-36876] Add proxy for restClient [flink-kubernetes-operator]

Posted by "chenyuzhi459 (via GitHub)" <gi...@apache.org>.
chenyuzhi459 commented on PR #956:
URL: https://github.com/apache/flink-kubernetes-operator/pull/956#issuecomment-2904106838

   I think the default value of `flink.client.io.threads=60`  new parameter  is too big in the test environment, because multiple FlinkResourceContextFactory and flinkClientEventLoopGroup will be created simultaneously in parallel tests, which leads to too many files; but there is only one FlinkResourceContextFactory/flinkClientEventLoopGroup in production environment; 
   
   Is there any way to differentiate between the test and the production environment for this param, casue I am not very familiar with the test of operator, I hope it can be helped


-- 
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-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-36876] Add proxy for restClient [flink-kubernetes-operator]

Posted by "chenyuzhi459 (via GitHub)" <gi...@apache.org>.
chenyuzhi459 commented on PR #956:
URL: https://github.com/apache/flink-kubernetes-operator/pull/956#issuecomment-2837981756

   It depends on when will the pr https://github.com/apache/flink/pull/25788 could be merged. 
   
   If necessary, I can submit the pr fix in both 1.20 and 2.x versions of Flink.
   
   @gyfora 


-- 
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-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-36876] Add proxy for restClient [flink-kubernetes-operator]

Posted by "gyfora (via GitHub)" <gi...@apache.org>.
gyfora commented on PR #956:
URL: https://github.com/apache/flink-kubernetes-operator/pull/956#issuecomment-5191317181

   closing stale work / 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: issues-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-36876] Add proxy for restClient [flink-kubernetes-operator]

Posted by "gyfora (via GitHub)" <gi...@apache.org>.
gyfora commented on code in PR #956:
URL: https://github.com/apache/flink-kubernetes-operator/pull/956#discussion_r2083854374


##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/service/RestClientProxy.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.service;
+
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.rest.RestClient;
+import org.apache.flink.util.ConfigurationException;
+import org.apache.flink.util.Preconditions;
+
+import org.apache.flink.shaded.netty4.io.netty.bootstrap.AbstractBootstrap;
+import org.apache.flink.shaded.netty4.io.netty.bootstrap.Bootstrap;
+import org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Field;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+
+/** Proxy for the {@link RestClient}. */
+public class RestClientProxy extends RestClient {
+    private static final Logger LOG = LoggerFactory.getLogger(RestClientProxy.class);
+
+    private final boolean useSharedEventLoopGroup;
+    private Field groupField;
+    private Bootstrap bootstrap;
+    private CompletableFuture<Void> terminationFuture;
+
+    public RestClientProxy(
+            Configuration configuration,
+            ExecutorService executor,
+            String host,
+            int port,
+            EventLoopGroup sharedGroup)
+            throws ConfigurationException, NoSuchFieldException, IllegalAccessException {
+        super(configuration, executor, host, port);
+
+        if (sharedGroup != null) {
+            Preconditions.checkArgument(
+                    !sharedGroup.isShuttingDown() && !sharedGroup.isShutdown(),
+                    "provided eventLoopGroup is shut/shutting down");
+
+            // get private field
+            Field bootstrapField = RestClient.class.getDeclaredField("bootstrap");
+            Field terminationFutureField = RestClient.class.getDeclaredField("terminationFuture");
+            Field groupField = AbstractBootstrap.class.getDeclaredField("group");
+
+            bootstrapField.setAccessible(true);
+            terminationFutureField.setAccessible(true);
+            groupField.setAccessible(true);
+
+            this.terminationFuture = (CompletableFuture<Void>) terminationFutureField.get(this);
+            this.bootstrap = (Bootstrap) bootstrapField.get(this);
+            this.groupField = groupField;
+
+            // close previous group
+            bootstrap.config().group().shutdown();

Review Comment:
   How will this actually solve the original problem? The rest client still creates an individual group (that we close here) won't that cause the same issue anyways?



-- 
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-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-36876] Add proxy for restClient [flink-kubernetes-operator]

Posted by "gaborgsomogyi (via GitHub)" <gi...@apache.org>.
gaborgsomogyi commented on PR #956:
URL: https://github.com/apache/flink-kubernetes-operator/pull/956#issuecomment-2903599779

   This feature looks promising. Can you plz answer because we're intended to do a release soon?


-- 
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-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-36876] Add proxy for restClient [flink-kubernetes-operator]

Posted by "chenyuzhi459 (via GitHub)" <gi...@apache.org>.
chenyuzhi459 commented on PR #956:
URL: https://github.com/apache/flink-kubernetes-operator/pull/956#issuecomment-2904094832

   I have reproduced the `Too many open files` issue of CI at local compile env,  I will resolved it as soon as possible


-- 
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-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-36876] Add proxy for restClient [flink-kubernetes-operator]

Posted by "gyfora (via GitHub)" <gi...@apache.org>.
gyfora commented on PR #956:
URL: https://github.com/apache/flink-kubernetes-operator/pull/956#issuecomment-2908716749

   Why does `flink.client.io.threads=60` affect how many threads are created in the tests? Wouldn't threads be created lazily?


-- 
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-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-36876] Add proxy for restClient [flink-kubernetes-operator]

Posted by "gyfora (via GitHub)" <gi...@apache.org>.
gyfora closed pull request #956: [FLINK-36876] Add proxy for restClient
URL: https://github.com/apache/flink-kubernetes-operator/pull/956


-- 
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-unsubscribe@flink.apache.org

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