You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by je...@apache.org on 2020/08/28 05:15:21 UTC

[pulsar] branch master updated: Add hostname to consumer/producer properties in Pulsar Functions (#7897)

This is an automated email from the ASF dual-hosted git repository.

jerrypeng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 9471ac7  Add hostname to consumer/producer properties in Pulsar Functions (#7897)
9471ac7 is described below

commit 9471ac754589cbeaf7494f5ebc2bea7113edf04d
Author: Boyang Jerry Peng <je...@gmail.com>
AuthorDate: Thu Aug 27 22:15:01 2020 -0700

    Add hostname to consumer/producer properties in Pulsar Functions (#7897)
    
    Co-authored-by: Jerry Peng <je...@splunk.com>
---
 .../java/org/apache/pulsar/functions/instance/InstanceUtils.java | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/InstanceUtils.java b/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/InstanceUtils.java
index d344364..3d4aa10 100644
--- a/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/InstanceUtils.java
+++ b/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/InstanceUtils.java
@@ -23,6 +23,7 @@ import static org.apache.commons.lang3.StringUtils.isEmpty;
 
 import lombok.experimental.UtilityClass;
 
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.pulsar.client.api.Schema;
 import org.apache.pulsar.functions.api.SerDe;
@@ -33,9 +34,12 @@ import org.apache.pulsar.common.util.Reflections;
 import net.jodah.typetools.TypeResolver;
 import org.apache.pulsar.functions.utils.FunctionCommon;
 
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.util.HashMap;
 import java.util.Map;
 
+@Slf4j
 @UtilityClass
 public class InstanceUtils {
     public static SerDe<?> initializeSerDe(String serdeClassName, ClassLoader clsLoader, Class<?> typeArg,
@@ -134,6 +138,11 @@ public class InstanceUtils {
         }
         properties.put("id", fullyQualifiedName);
         properties.put("instance_id", String.valueOf(instanceId));
+        try {
+            properties.put("instance_hostname", InetAddress.getLocalHost().getHostName());
+        } catch (UnknownHostException e) {
+            log.warn("[{}:{}] Failed to get hostname of instance", fullyQualifiedName, instanceId, e);
+        }
         return properties;
     }
 }