You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/04/13 05:33:53 UTC

[GitHub] [pulsar] jerrypeng opened a new pull request #10208: Fix Pulsar Function localrun with multiple instances and metrics server is enabled

jerrypeng opened a new pull request #10208:
URL: https://github.com/apache/pulsar/pull/10208


   
   ### Motivation
   
   Due to the recent change to Pulsar Function local run in threaded mode that exposed metrics via a metrics server:
   
   https://github.com/apache/pulsar/pull/10156
   
   running multiple instances in threaded mode with metrics server turned on created a situation where instances attempted to register the same metric multiple times causing an exception with text
   
   ```Collector already registered that provides name ...```
   
   The above PR also started up a metrics server per threaded instance on a different port which is also not ideal.  Ideally, all metrics for all instances are exposed via single port and metrics server.
   
   ### Modifications
   
   Change the metrics code in functions/sources/sinks to allow registering metrics that already been registered. When that occurs, the existing metric will be returned from the register method.
   
   


-- 
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.

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



[GitHub] [pulsar] jerrypeng commented on a change in pull request #10208: Fix Pulsar Function localrun with multiple instances and metrics server is enabled

Posted by GitBox <gi...@apache.org>.
jerrypeng commented on a change in pull request #10208:
URL: https://github.com/apache/pulsar/pull/10208#discussion_r612827359



##########
File path: pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/stats/FunctionCollectorRegistryImpl.java
##########
@@ -0,0 +1,42 @@
+/**
+ * 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.pulsar.functions.instance.stats;
+
+import io.prometheus.client.Collector;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class FunctionCollectorRegistryImpl extends FunctionCollectorRegistry {
+
+    private final Map<String, Collector> namesToCollectors = new HashMap<String, Collector>();

Review comment:
       Sure, I didn't utilize ConcurrentHashMap because I don't expect that many instances will be started up in a local run process.




-- 
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.

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



[GitHub] [pulsar] michaeljmarshall commented on a change in pull request #10208: Fix Pulsar Function localrun with multiple instances and metrics server is enabled

Posted by GitBox <gi...@apache.org>.
michaeljmarshall commented on a change in pull request #10208:
URL: https://github.com/apache/pulsar/pull/10208#discussion_r612586794



##########
File path: pulsar-functions/localrun/src/main/java/org/apache/pulsar/functions/LocalRunner.java
##########
@@ -171,7 +172,7 @@ public RuntimeEnv convert(String value) {
     protected String secretsProviderClassName;
     @Parameter(names = "--secretsProviderConfig", description = "Whats the config for the secrets provider", hidden = true)
     protected String secretsProviderConfig;
-    @Parameter(names = "--metricsPortStart", description = "The starting port range for metrics server", hidden = true)
+    @Parameter(names = "--metricsPortStart", description = "The starting port range for metrics server. When running instances as threads, one metrics server is used to host the stats for all instances.", hidden = true)

Review comment:
       Thanks for that explanation. I hadn't realized both options were possible. Makes sense.




-- 
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.

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



[GitHub] [pulsar] jerrypeng merged pull request #10208: Fix Pulsar Function localrun with multiple instances and metrics server is enabled

Posted by GitBox <gi...@apache.org>.
jerrypeng merged pull request #10208:
URL: https://github.com/apache/pulsar/pull/10208


   


-- 
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.

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



[GitHub] [pulsar] michaeljmarshall commented on a change in pull request #10208: Fix Pulsar Function localrun with multiple instances and metrics server is enabled

Posted by GitBox <gi...@apache.org>.
michaeljmarshall commented on a change in pull request #10208:
URL: https://github.com/apache/pulsar/pull/10208#discussion_r612166953



##########
File path: pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/stats/FunctionCollectorRegistryImpl.java
##########
@@ -0,0 +1,42 @@
+/**
+ * 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.pulsar.functions.instance.stats;
+
+import io.prometheus.client.Collector;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class FunctionCollectorRegistryImpl extends FunctionCollectorRegistry {
+
+    private final Map<String, Collector> namesToCollectors = new HashMap<String, Collector>();

Review comment:
       Nit. I think it might be more efficient to use a `ConcurrentHashMap` for this map, given that the map is accessed from several threads. Then, use `computeIfAbsent` in the `registerIfNotExist` method instead of using `synchronized`.

##########
File path: pulsar-functions/localrun/src/main/java/org/apache/pulsar/functions/LocalRunner.java
##########
@@ -171,7 +172,7 @@ public RuntimeEnv convert(String value) {
     protected String secretsProviderClassName;
     @Parameter(names = "--secretsProviderConfig", description = "Whats the config for the secrets provider", hidden = true)
     protected String secretsProviderConfig;
-    @Parameter(names = "--metricsPortStart", description = "The starting port range for metrics server", hidden = true)
+    @Parameter(names = "--metricsPortStart", description = "The starting port range for metrics server. When running instances as threads, one metrics server is used to host the stats for all instances.", hidden = true)

Review comment:
       Does this need to be a range because every instance thread expects a `metricsPort`? I see that in `startProcessMode` we use a range but in `startThreadedMode` we use a single value. Further, I see that we're only using `metricsPortStart` when starting the metrics server.




-- 
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.

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



[GitHub] [pulsar] michaeljmarshall commented on pull request #10208: Fix Pulsar Function localrun with multiple instances and metrics server is enabled

Posted by GitBox <gi...@apache.org>.
michaeljmarshall commented on pull request #10208:
URL: https://github.com/apache/pulsar/pull/10208#issuecomment-820725925


   Once this is merged, it'd be great to get this in `branch-2.7`, if 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.

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



[GitHub] [pulsar] jerrypeng commented on pull request #10208: Fix Pulsar Function localrun with multiple instances and metrics server is enabled

Posted by GitBox <gi...@apache.org>.
jerrypeng commented on pull request #10208:
URL: https://github.com/apache/pulsar/pull/10208#issuecomment-822838200


   @michaeljmarshall sounds good to me.  Can you volunteer to do the backport :) ?


-- 
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.

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



[GitHub] [pulsar] michaeljmarshall commented on a change in pull request #10208: Fix Pulsar Function localrun with multiple instances and metrics server is enabled

Posted by GitBox <gi...@apache.org>.
michaeljmarshall commented on a change in pull request #10208:
URL: https://github.com/apache/pulsar/pull/10208#discussion_r612833559



##########
File path: pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/stats/FunctionCollectorRegistryImpl.java
##########
@@ -0,0 +1,42 @@
+/**
+ * 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.pulsar.functions.instance.stats;
+
+import io.prometheus.client.Collector;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class FunctionCollectorRegistryImpl extends FunctionCollectorRegistry {
+
+    private final Map<String, Collector> namesToCollectors = new HashMap<String, Collector>();

Review comment:
       That's fair. I see that this won't be used much and likely won't encounter much contention after metrics are initialized.




-- 
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.

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



[GitHub] [pulsar] jerrypeng commented on a change in pull request #10208: Fix Pulsar Function localrun with multiple instances and metrics server is enabled

Posted by GitBox <gi...@apache.org>.
jerrypeng commented on a change in pull request #10208:
URL: https://github.com/apache/pulsar/pull/10208#discussion_r612581530



##########
File path: pulsar-functions/localrun/src/main/java/org/apache/pulsar/functions/LocalRunner.java
##########
@@ -171,7 +172,7 @@ public RuntimeEnv convert(String value) {
     protected String secretsProviderClassName;
     @Parameter(names = "--secretsProviderConfig", description = "Whats the config for the secrets provider", hidden = true)
     protected String secretsProviderConfig;
-    @Parameter(names = "--metricsPortStart", description = "The starting port range for metrics server", hidden = true)
+    @Parameter(names = "--metricsPortStart", description = "The starting port range for metrics server. When running instances as threads, one metrics server is used to host the stats for all instances.", hidden = true)

Review comment:
       For running instances in process mode i.e. each instance is a separate JVM processes, the port range is needed as each instance will run its own metrics server on the specified port in its own respective process




-- 
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.

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



[GitHub] [pulsar] jerrypeng commented on pull request #10208: Fix Pulsar Function localrun with multiple instances and metrics server is enabled

Posted by GitBox <gi...@apache.org>.
jerrypeng commented on pull request #10208:
URL: https://github.com/apache/pulsar/pull/10208#issuecomment-818451858


   @michaeljmarshall please also take a look


-- 
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.

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