You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by dg...@apache.org on 2022/05/07 07:48:18 UTC

[unomi] 01/01: UNOMI-567 : filter out warnings from RestClient

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

dgriffon pushed a commit to branch filter-unomi-logs
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit 4b1d5dfa5b9cdb5c5e924a5d480a9e81601d6f72
Author: David Griffon <dg...@jahia.com>
AuthorDate: Sat May 7 09:48:09 2022 +0200

    UNOMI-567 : filter out warnings from RestClient
---
 .../elasticsearch/ElasticSearchPersistenceServiceImpl.java | 14 ++++++++++++--
 .../src/main/resources/OSGI-INF/blueprint/blueprint.xml    |  2 ++
 .../org.apache.unomi.persistence.elasticsearch.cfg         |  3 +++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
index 211ef68be..54adccbac 100644
--- a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
+++ b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
@@ -27,6 +27,7 @@ import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.CredentialsProvider;
 import org.apache.http.conn.ssl.NoopHostnameVerifier;
 import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.log4j.Level;
 import org.apache.lucene.search.TotalHits;
 import org.apache.unomi.api.*;
 import org.apache.unomi.api.conditions.Condition;
@@ -147,7 +148,6 @@ import javax.net.ssl.X509TrustManager;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
-import java.lang.reflect.Field;
 import java.net.URL;
 import java.security.KeyManagementException;
 import java.security.NoSuchAlgorithmException;
@@ -169,7 +169,6 @@ import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
 
 import static org.elasticsearch.index.query.QueryBuilders.termQuery;
 
@@ -241,6 +240,7 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
     private String itemClassesToCache;
     private boolean useBatchingForSave = false;
     private boolean useBatchingForUpdate = true;
+    private boolean errorLogLevelRestClient = true;
     private boolean alwaysOverwrite = true;
     private boolean aggQueryThrowOnMissingDocs = false;
     private Integer aggQueryMaxResponseSizeHttp = null;
@@ -435,9 +435,19 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
         this.alwaysOverwrite = alwaysOverwrite;
     }
 
+    public void setErrorLogLevelRestClient(boolean errorLogLevelRestClient) {
+        this.errorLogLevelRestClient = errorLogLevelRestClient;
+    }
 
     public void start() throws Exception {
 
+        // Work around to avoid ES Logs regarding the deprecated [ignore_throttled] parameter
+        if (errorLogLevelRestClient) {
+            org.apache.log4j.Logger.getLogger("org.elasticsearch.client.RestClient").setLevel(Level.ERROR);
+        } else {
+            org.apache.log4j.Logger.getLogger("org.elasticsearch.client.RestClient").setLevel(Level.INFO);
+        }
+
         // on startup
         new InClassLoaderExecute<Object>(null, null, this.bundleContext, this.fatalIllegalStateErrors, throwExceptions) {
             public Object execute(Object... args) throws Exception {
diff --git a/persistence-elasticsearch/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/persistence-elasticsearch/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index ca16a0116..fc44ae438 100644
--- a/persistence-elasticsearch/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/persistence-elasticsearch/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -68,6 +68,7 @@
             <cm:property name="sslTrustAllCertificates" value="false" />
             <cm:property name="throwExceptions" value="false" />
             <cm:property name="alwaysOverwrite" value="true" />
+            <cm:property name="errorLogLevelRestClient" value="true" />
 
         </cm:default-properties>
     </cm:property-placeholder>
@@ -147,6 +148,7 @@
         <property name="sslTrustAllCertificates" value="${es.sslTrustAllCertificates}" />
         <property name="throwExceptions" value="${es.throwExceptions}" />
         <property name="alwaysOverwrite" value="${es.alwaysOverwrite}" />
+        <property name="errorLogLevelRestClient" value="${es.errorLogLevelRestClient}" />
     </bean>
 
     <!-- We use a listener here because using the list directly for listening to proxies coming from the same bundle didn't seem to work -->
diff --git a/persistence-elasticsearch/core/src/main/resources/org.apache.unomi.persistence.elasticsearch.cfg b/persistence-elasticsearch/core/src/main/resources/org.apache.unomi.persistence.elasticsearch.cfg
index 71c2577b7..75d84a470 100644
--- a/persistence-elasticsearch/core/src/main/resources/org.apache.unomi.persistence.elasticsearch.cfg
+++ b/persistence-elasticsearch/core/src/main/resources/org.apache.unomi.persistence.elasticsearch.cfg
@@ -81,3 +81,6 @@ throwExceptions=${org.apache.unomi.elasticsearch.throwExceptions:-false}
 
 alwaysOverwrite=${org.apache.unomi.elasticsearch.alwaysOverwrite:-true}
 useBatchingForUpdate=${org.apache.unomi.elasticsearch.useBatchingForUpdate:-true}
+
+# ES logging
+errorLogLevelRestClient=${org.apache.unomi.elasticsearch.errorLogLevelRestClient:-true}