karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject karaf-decanter git commit: [KARAF-5060] Allow user to define the elasticsearch index name
Date Mon, 19 Jun 2017 09:07:26 GMT
Repository: karaf-decanter
Updated Branches:
  refs/heads/master f5266e8ac -> 29277266c


[KARAF-5060] Allow user to define the elasticsearch index name


Project: http://git-wip-us.apache.org/repos/asf/karaf-decanter/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf-decanter/commit/29277266
Tree: http://git-wip-us.apache.org/repos/asf/karaf-decanter/tree/29277266
Diff: http://git-wip-us.apache.org/repos/asf/karaf-decanter/diff/29277266

Branch: refs/heads/master
Commit: 29277266c70782fa1b1d52cc66625cdb7b05a0be
Parents: f5266e8
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Mon Jun 19 11:07:00 2017 +0200
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Mon Jun 19 11:07:00 2017 +0200

----------------------------------------------------------------------
 ...rg.apache.karaf.decanter.appender.elasticsearch.cfg |  8 +++++++-
 .../appender/elasticsearch/ElasticsearchAppender.java  | 13 +++++++++++--
 .../appender/elasticsearch/ElasticsearchAppender.java  | 13 +++++++++++--
 ...ache.karaf.decanter.appender.elasticsearch.rest.cfg |  8 +++++++-
 .../elasticsearch/rest/ElasticsearchAppender.java      | 13 +++++++++++--
 5 files changed, 47 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/29277266/appender/elasticsearch-native-1.x/src/main/cfg/org.apache.karaf.decanter.appender.elasticsearch.cfg
----------------------------------------------------------------------
diff --git a/appender/elasticsearch-native-1.x/src/main/cfg/org.apache.karaf.decanter.appender.elasticsearch.cfg
b/appender/elasticsearch-native-1.x/src/main/cfg/org.apache.karaf.decanter.appender.elasticsearch.cfg
index f7cad36..1bae222 100644
--- a/appender/elasticsearch-native-1.x/src/main/cfg/org.apache.karaf.decanter.appender.elasticsearch.cfg
+++ b/appender/elasticsearch-native-1.x/src/main/cfg/org.apache.karaf.decanter.appender.elasticsearch.cfg
@@ -7,4 +7,10 @@ host=localhost
 # Port number of the elasticsearch instance
 port=9300
 # Name of the elasticsearch cluster
-clusterName=elasticsearch
\ No newline at end of file
+clusterName=elasticsearch
+
+# The index name.
+# The index prefix is a static string used to construct the index
+# index.prefix=karaf
+# If true, it creates an index per Decanter event day
+# index.event.timestamped=true
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/29277266/appender/elasticsearch-native-1.x/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/ElasticsearchAppender.java
----------------------------------------------------------------------
diff --git a/appender/elasticsearch-native-1.x/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/ElasticsearchAppender.java
b/appender/elasticsearch-native-1.x/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/ElasticsearchAppender.java
index 736f743..cb826b5 100644
--- a/appender/elasticsearch-native-1.x/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/ElasticsearchAppender.java
+++ b/appender/elasticsearch-native-1.x/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/ElasticsearchAppender.java
@@ -64,6 +64,9 @@ public class ElasticsearchAppender implements EventHandler {
     private Marshaller marshaller;
     private WorkFinishedListener listener;
 
+    private String indexPrefix;
+    private boolean indexTimestamped;
+
     @SuppressWarnings("unchecked")
     @Activate
     public void activate(ComponentContext context) {
@@ -75,6 +78,8 @@ public class ElasticsearchAppender implements EventHandler {
             String host = getValue(config, "host", "localhost");
             int port = Integer.parseInt(getValue(config, "port", "9300"));
             String cluster = getValue(config, "clusterName", "elasticsearch");
+            indexPrefix = getValue(config, "index.prefix", "karaf");
+            indexTimestamped = Boolean.parseBoolean(getValue(config, "index.event.timestamped",
"true"));
             TimeZone tz = TimeZone.getTimeZone( "UTC" );
             tsFormat.setTimeZone(tz);
             indexDateFormat.setTimeZone(tz);
@@ -131,7 +136,7 @@ public class ElasticsearchAppender implements EventHandler {
     }
 
     private void send(Event event) {
-        String indexName = getIndexName("karaf", getDate(event));
+        String indexName = getIndexName(indexPrefix, getDate(event));
         String jsonSt = marshaller.marshal(event);
         LOGGER.debug("Sending event to elastic search with content: {}", jsonSt);
         bulkProcessor.add(new IndexRequest(indexName, getType(event)).source(jsonSt));
@@ -149,7 +154,11 @@ public class ElasticsearchAppender implements EventHandler {
     }
 
     private String getIndexName(String prefix, Date date) {
-        return prefix + "-" + indexDateFormat.format(date);
+        if (indexTimestamped) {
+            return prefix + "-" + indexDateFormat.format(date);
+        } else {
+            return prefix;
+        }
     }
 
     @Reference

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/29277266/appender/elasticsearch-native-2.x/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/ElasticsearchAppender.java
----------------------------------------------------------------------
diff --git a/appender/elasticsearch-native-2.x/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/ElasticsearchAppender.java
b/appender/elasticsearch-native-2.x/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/ElasticsearchAppender.java
index cd40c67..53a7cef 100644
--- a/appender/elasticsearch-native-2.x/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/ElasticsearchAppender.java
+++ b/appender/elasticsearch-native-2.x/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/ElasticsearchAppender.java
@@ -62,6 +62,9 @@ public class ElasticsearchAppender implements EventHandler {
     private Marshaller marshaller;
     private WorkFinishedListener listener;
 
+    private String indexPrefix;
+    private boolean indexTimestamped;
+
     @SuppressWarnings("unchecked")
     @Activate
     public void activate(ComponentContext context) {
@@ -73,6 +76,8 @@ public class ElasticsearchAppender implements EventHandler {
             String host = getValue(config, "host", "localhost");
             int port = Integer.parseInt(getValue(config, "port", "9300"));
             String cluster = getValue(config, "clusterName", "elasticsearch");
+            indexPrefix = getValue(config, "index.prefix", "karaf");
+            indexTimestamped = Boolean.parseBoolean(getValue(config, "index.event.timestamped",
"true"));
             TimeZone tz = TimeZone.getTimeZone( "UTC" );
             tsFormat.setTimeZone(tz);
             indexDateFormat.setTimeZone(tz);
@@ -124,7 +129,7 @@ public class ElasticsearchAppender implements EventHandler {
     }
 
     private void send(Event event) {
-        String indexName = getIndexName("karaf", getDate(event));
+        String indexName = getIndexName(indexPrefix, getDate(event));
         String jsonSt = marshaller.marshal(event);
         LOGGER.debug("Sending event to elastic search with content: {}", jsonSt);
         bulkProcessor.add(new IndexRequest(indexName, getType(event)).source(jsonSt));
@@ -142,7 +147,11 @@ public class ElasticsearchAppender implements EventHandler {
     }
 
     private String getIndexName(String prefix, Date date) {
-        return prefix + "-" + indexDateFormat.format(date);
+        if (indexTimestamped) {
+            return prefix + "-" + indexDateFormat.format(date);
+        } else {
+            return prefix;
+        }
     }
 
     @Reference

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/29277266/appender/elasticsearch-rest/src/main/cfg/org.apache.karaf.decanter.appender.elasticsearch.rest.cfg
----------------------------------------------------------------------
diff --git a/appender/elasticsearch-rest/src/main/cfg/org.apache.karaf.decanter.appender.elasticsearch.rest.cfg
b/appender/elasticsearch-rest/src/main/cfg/org.apache.karaf.decanter.appender.elasticsearch.rest.cfg
index 86c0d24..ec7caf1 100644
--- a/appender/elasticsearch-rest/src/main/cfg/org.apache.karaf.decanter.appender.elasticsearch.rest.cfg
+++ b/appender/elasticsearch-rest/src/main/cfg/org.apache.karaf.decanter.appender.elasticsearch.rest.cfg
@@ -8,4 +8,10 @@ address=http://localhost:9200
 
 # Basic username and password authentication
 # username=user
-# password=password
\ No newline at end of file
+# password=password
+
+# The index name.
+# The index prefix is a static string used to construct the index
+# index.prefix=karaf
+# If true, it creates an index per Decanter event day
+# index.event.timestamped=true
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/29277266/appender/elasticsearch-rest/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/rest/ElasticsearchAppender.java
----------------------------------------------------------------------
diff --git a/appender/elasticsearch-rest/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/rest/ElasticsearchAppender.java
b/appender/elasticsearch-rest/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/rest/ElasticsearchAppender.java
index 8e8e851..4e2d1a2 100644
--- a/appender/elasticsearch-rest/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/rest/ElasticsearchAppender.java
+++ b/appender/elasticsearch-rest/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/rest/ElasticsearchAppender.java
@@ -55,6 +55,8 @@ public class ElasticsearchAppender implements EventHandler {
 
     private JestClient client;
     private Marshaller marshaller;
+    private String indexPrefix;
+    private boolean indexTimestamped;
 
     private final SimpleDateFormat tsFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss,SSS'Z'");
     private final SimpleDateFormat indexDateFormat = new SimpleDateFormat("yyyy.MM.dd");
@@ -92,6 +94,9 @@ public class ElasticsearchAppender implements EventHandler {
         TimeZone tz = TimeZone.getTimeZone( "UTC" );
         tsFormat.setTimeZone(tz);
         indexDateFormat.setTimeZone(tz);
+
+        indexPrefix = getValue(config, "index.prefix", "karaf");
+        indexTimestamped = Boolean.parseBoolean(getValue(config, "index.event.timestamped",
"true"));
     }
     
     private String getValue(Dictionary<String, Object> config, String key, String defaultValue)
{
@@ -114,7 +119,7 @@ public class ElasticsearchAppender implements EventHandler {
     }
 
     private void send(Event event) throws Exception {
-        String indexName = getIndexName("karaf", getDate(event));
+        String indexName = getIndexName(indexPrefix, getDate(event));
         String jsonSt = marshaller.marshal(event);
 
         JestResult result = client.execute(new Index.Builder(jsonSt).index(indexName).type(getType(event)).build());
@@ -136,7 +141,11 @@ public class ElasticsearchAppender implements EventHandler {
     }
 
     private String getIndexName(String prefix, Date date) {
-        return prefix + "-" + indexDateFormat.format(date);
+        if (indexTimestamped) {
+            return prefix + "-" + indexDateFormat.format(date);
+        } else {
+            return prefix;
+        }
     }
 
     @Reference


Mime
View raw message