zentol commented on a change in pull request #16265: URL: https://github.com/apache/flink/pull/16265#discussion_r660559696
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/rpc/RpcSystem.java ########## @@ -0,0 +1,185 @@ +/* + * 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.runtime.rpc; + +import org.apache.flink.configuration.Configuration; +import org.apache.flink.runtime.rpc.akka.AkkaRpcSystem; + +import javax.annotation.Nullable; + +import java.net.InetSocketAddress; +import java.net.UnknownHostException; + +/** + * This interface serves as a factory interface for RPC services, with some additional utilities + * that are reliant on implementation details of the RPC service. + */ +public interface RpcSystem { + + /** + * Returns a builder for an {@link RpcService} that is only reachable from the local machine. + * + * @param configuration Flink configuration + * @return rpc service builder + */ + RpcServiceBuilder localServiceBuilder(Configuration configuration); + + /** + * Returns a builder for an {@link RpcService} that is reachable from other machines. + * + * @param configuration Flink configuration + * @param externalAddress optional address under which the RpcService should be reachable + * @param externalPortRange port range from which 1 port will be chosen under which the + * RpcService should be reachable + * @return rpc service builder + */ + RpcServiceBuilder remoteServiceBuilder( + Configuration configuration, + @Nullable String externalAddress, + String externalPortRange); + + /** + * Constructs an RPC URL for the given parameters, that can be used to connect to the targeted + * RpcService. + * + * @param hostname The hostname or address where the target RPC service is listening. + * @param port The port where the target RPC service is listening. + * @param endpointName The name of the RPC endpoint. + * @param addressResolution Whether to try address resolution of the given hostname or not. This + * allows to fail fast in case that the hostname cannot be resolved. + * @param config The configuration from which to deduce further settings. + * @return The RPC URL of the specified RPC endpoint. + */ + String getRpcUrl( + String hostname, + int port, + String endpointName, + AddressResolution addressResolution, + Configuration config) + throws UnknownHostException; + + /** + * Returns an {@link InetSocketAddress} corresponding to the given RPC url. + * + * @see #getRpcUrl + * @param url RPC url + * @return inet socket address + * @throws Exception if the URL is invalid + */ + InetSocketAddress getInetSocketAddressFromRpcUrl(String url) throws Exception; + + /** + * Returns the maximum number of bytes that an RPC message may carry according to the given + * configuration. If no limit exists then {@link Long#MAX_VALUE} should be returned. + * + * @param config Flink configuration + * @return maximum number of bytes that an RPC message may carry + */ + long getMaximumMessageSizeInBytes(Configuration config); Review comment: 👍 ########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/rpc/akka/AkkaRpcSystem.java ########## @@ -0,0 +1,68 @@ +/* + * 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.runtime.rpc.akka; + +import org.apache.flink.configuration.Configuration; +import org.apache.flink.runtime.akka.AkkaUtils; +import org.apache.flink.runtime.rpc.AddressResolution; +import org.apache.flink.runtime.rpc.RpcSystem; + +import javax.annotation.Nullable; + +import java.net.InetSocketAddress; +import java.net.UnknownHostException; + +/** {@link RpcSystem} implementation based on Akka. */ +public class AkkaRpcSystem implements RpcSystem { + + @Override + public RpcServiceBuilder localServiceBuilder(Configuration configuration) { + return AkkaRpcServiceUtils.localServiceBuilder(configuration); + } + + @Override + public RpcServiceBuilder remoteServiceBuilder( + Configuration configuration, + @Nullable String externalAddress, + String externalPortRange) { + return AkkaRpcServiceUtils.remoteServiceBuilder( + configuration, externalAddress, externalPortRange); + } + + @Override + public InetSocketAddress getInetSocketAddressFromRpcUrl(String url) throws Exception { + return AkkaUtils.getInetSocketAddressFromAkkaURL(url); Review comment: I think it would make sense because as is I couldn't tell why something goes into one or the other. But I would do that in a follow-up after this feature is completed to safe some time on rebasing. ########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/rpc/RpcSystemUtils.java ########## @@ -0,0 +1,55 @@ +/* + * 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.runtime.rpc; + +import org.apache.flink.configuration.Configuration; + +import javax.annotation.Nullable; + +import java.util.Optional; + +/** Utils related to the {@link RpcSystem}. */ +public final class RpcSystemUtils { + + /** + * Convenient shortcut for constructing a remote RPC Service that takes care of checking for + * null and empty optionals. + * + * @see RpcSystem#remoteServiceBuilder(Configuration, String, String) + */ + public static RpcService createRemoteRpcService( Review comment: yes that would make sense; this separation doesn't really provide a benefit. ########## File path: flink-metrics/flink-metrics-prometheus/src/test/java/org/apache/flink/metrics/prometheus/PrometheusReporterTest.java ########## @@ -85,7 +85,7 @@ public void setupReporter() { registry = new MetricRegistryImpl( - MetricRegistryConfiguration.defaultMetricRegistryConfiguration(), + MetricRegistryTestUtils.defaultMetricRegistryConfiguration(), Review comment: The main issue I think is that we don't have a good MetricGroup for testing, so we have to rely on the runtime implementations which unfortunately rely on the registry. Overall the metric components are too reliant on each other. I should have one such implementation somewhere, which should allow us to simplify quite a lot of metric-related tests, but I would do that as a follow-up because it implies bigger changes to all reporter tests. -- 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]
