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

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


The following commit(s) were added to refs/heads/master by this push:
     new 537ee3bb6c [INLONG-8520][Agent] Makeup the code to figure out whether 
it is kvm、k8s or not (#8521)
537ee3bb6c is described below

commit 537ee3bb6cd1b93998c56b98828c0f5a100f3933
Author: justinwwhuang <[email protected]>
AuthorDate: Thu Jul 13 11:50:17 2023 +0800

    [INLONG-8520][Agent] Makeup the code to figure out whether it is kvm、k8s or 
not (#8521)
---
 .../inlong/agent/plugin/sources/reader/file/FileReaderOperator.java | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git 
a/inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/sources/reader/file/FileReaderOperator.java
 
b/inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/sources/reader/file/FileReaderOperator.java
index bcd4b59272..24db072eed 100644
--- 
a/inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/sources/reader/file/FileReaderOperator.java
+++ 
b/inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/sources/reader/file/FileReaderOperator.java
@@ -113,6 +113,7 @@ public class FileReaderOperator extends AbstractReader {
     private final long monitorActiveInterval = 60 * 1000;
     private final BlockingQueue<String> queue = new 
LinkedBlockingQueue<>(CACHE_QUEUE_SIZE);
     private final StringBuffer sb = new StringBuffer();
+    private boolean needMetadata = false;
 
     public FileReaderOperator(File file, int position) {
         this(file, position, "");
@@ -371,6 +372,9 @@ public class FileReaderOperator extends AbstractReader {
     }
 
     public String fillMetaData(String message) {
+        if (!needMetadata) {
+            return message;
+        }
         long timestamp = System.currentTimeMillis();
         boolean isJson = FileDataUtils.isJSON(message);
         Map<String, String> mergeData = new HashMap<>(metadata);
@@ -390,8 +394,10 @@ public class FileReaderOperator extends AbstractReader {
         String[] env = jobConf.get(JOB_FILE_META_ENV_LIST).split(COMMA);
         Arrays.stream(env).forEach(data -> {
             if (data.equalsIgnoreCase(KUBERNETES)) {
+                needMetadata = true;
                 new KubernetesMetadataProvider(this).getData();
             } else if (data.equalsIgnoreCase(ENV_CVM)) {
+                needMetadata = true;
                 metadata.put(METADATA_HOST_NAME, AgentUtils.getLocalHost());
                 metadata.put(METADATA_SOURCE_IP, AgentUtils.fetchLocalIp());
                 metadata.put(METADATA_FILE_NAME, file.getName());

Reply via email to