You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2020/03/30 14:29:02 UTC

[karaf-decanter] branch master updated: feat(influxdb-appender):send strings values to influx as tags instead of fields

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

jbonofre pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/karaf-decanter.git


The following commit(s) were added to refs/heads/master by this push:
     new 3383c79  feat(influxdb-appender):send strings values  to influx as tags instead of fields
     new da838b1  Merge pull request #125 from YotpoLtd/influxdb-appender
3383c79 is described below

commit 3383c79873f2abeb490c5cff261b84794eaa728e
Author: Gilad Weinbach <gw...@yotpo.com>
AuthorDate: Thu Mar 5 17:24:01 2020 +0200

    feat(influxdb-appender):send strings values  to influx as tags instead of fields
---
 .../appender/influxdb/InfluxDbAppender.java        | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/appender/influxdb/src/main/java/org/apache/karaf/decanter/appender/influxdb/InfluxDbAppender.java b/appender/influxdb/src/main/java/org/apache/karaf/decanter/appender/influxdb/InfluxDbAppender.java
index b1b4aac..0a39d44 100644
--- a/appender/influxdb/src/main/java/org/apache/karaf/decanter/appender/influxdb/InfluxDbAppender.java
+++ b/appender/influxdb/src/main/java/org/apache/karaf/decanter/appender/influxdb/InfluxDbAppender.java
@@ -40,11 +40,12 @@ import java.util.concurrent.TimeUnit;
         immediate = true,
         property = EventConstants.EVENT_TOPIC + "=decanter/collect/*"
 )
+
 public class InfluxDbAppender implements EventHandler {
 
     private Dictionary<String, Object> config;
 
-    private Map<String, String> tags = new HashMap<>();
+    private Map<String, String> globalTags = new HashMap<>();
 
     private InfluxDB influxDB;
 
@@ -95,10 +96,10 @@ public class InfluxDbAppender implements EventHandler {
         String prefix = "tag.";
         for (Enumeration<String> e = config.keys(); e.hasMoreElements(); ) {
             String key = e.nextElement();
-            if (key.startsWith(prefix)) {
+            if( key.startsWith(prefix)) {
                 Object value = this.config.get(key);
                 if (value != null)
-                    tags.put(key.substring(4), value.toString());
+                    globalTags.put(key.substring(4),value.toString());
             }
         }
 
@@ -120,16 +121,23 @@ public class InfluxDbAppender implements EventHandler {
             if (event.getProperty("type") != null) {
                 type = (String) event.getProperty("type");
             }
-            Map<String, Object> data = new HashMap<>();
+
+            Map<String, Object> eventFields = new HashMap<>();
+            Map<String, String> eventTags = new HashMap<>();
+            eventTags.putAll(globalTags);
+
             for (String propertyName : event.getPropertyNames()) {
                 Object propertyValue = event.getProperty(propertyName);
                 if (propertyValue != null) {
-                    if (propertyValue instanceof Number || propertyValue instanceof String || propertyValue instanceof Boolean) {
-                        data.put(propertyName, propertyValue);
+                    if (propertyValue instanceof Number || propertyValue instanceof Boolean) {
+                        eventFields.put(propertyName, propertyValue);
+                    }
+                    else if(propertyValue instanceof String){
+                        eventTags.put(propertyName, (String) propertyValue);
                     }
                 }
             }
-            Point point = Point.measurement(type).fields(data).tag(tags).build();
+            Point point = Point.measurement(type).fields(eventFields).tag(eventTags).build();
             influxDB.write(point);
         }
     }