You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gh...@apache.org on 2020/08/12 20:25:04 UTC

[felix-dev] branch master updated: FELIX-6320 Better logging for DsComponentsCheck and ServicesCheck in case rootcause bundle is missing

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

ghenzler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git


The following commit(s) were added to refs/heads/master by this push:
     new 05dfd0d  FELIX-6320 Better logging for DsComponentsCheck and ServicesCheck in case rootcause bundle is missing
05dfd0d is described below

commit 05dfd0d970e5ac5203af2431bd1912bf71acea55
Author: georg.henzler <ge...@netcentric.biz>
AuthorDate: Wed Aug 12 22:24:31 2020 +0200

    FELIX-6320 Better logging for DsComponentsCheck and ServicesCheck in
    case rootcause bundle is missing
---
 .../felix/hc/generalchecks/DsComponentsCheck.java       | 17 +++++++----------
 .../apache/felix/hc/generalchecks/ServicesCheck.java    |  2 +-
 .../hc/generalchecks/scrutil/DsRootCauseAdapter.java    | 17 +++++++----------
 .../hc/generalchecks/scrutil/DsRootCauseAnalyzer.java   | 12 ++++++++----
 4 files changed, 23 insertions(+), 25 deletions(-)

diff --git a/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/DsComponentsCheck.java b/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/DsComponentsCheck.java
index 9fcbbd2..cc63898 100644
--- a/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/DsComponentsCheck.java
+++ b/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/DsComponentsCheck.java
@@ -29,7 +29,6 @@ import org.apache.felix.hc.api.FormattingResultLog;
 import org.apache.felix.hc.api.HealthCheck;
 import org.apache.felix.hc.api.Result;
 import org.apache.felix.hc.api.ResultLog.Entry;
-import org.apache.felix.hc.core.impl.util.lang.StringUtils;
 import org.apache.felix.hc.generalchecks.scrutil.DsRootCauseAnalyzer;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.component.annotations.Activate;
@@ -94,10 +93,10 @@ public class DsComponentsCheck implements HealthCheck {
 
     @Override
     public Result execute() {
+        FormattingResultLog log = new FormattingResultLog();
 
         Collection<ComponentDescriptionDTO> componentDescriptionDTOs = scr.getComponentDescriptionDTOs();
         List<ComponentDescriptionDTO> watchedComps = new LinkedList<ComponentDescriptionDTO>();
-        FormattingResultLog log = new FormattingResultLog();
         List<String> missingComponents = new LinkedList<String>(componentsList);
         for (ComponentDescriptionDTO desc : componentDescriptionDTOs) {
             if (componentsList.contains(desc.name)) {
@@ -106,7 +105,7 @@ public class DsComponentsCheck implements HealthCheck {
             }
         }
         for (String missingComp : missingComponents) {
-            log.temporarilyUnavailable("Not found {}", missingComp);
+            log.info("No component with name {} is registered in SCR runtime", missingComp);
         }
 
         int countEnabled = 0;
@@ -143,17 +142,15 @@ public class DsComponentsCheck implements HealthCheck {
             }
 
             if (!isActive) {
-                if (analyzer != null) {
-                    analyzer.logNotEnabledComponent(log, dsComp, statusForMissing);
-                } else {
-                    log.add(new Entry(statusForMissing, "Not active: " + dsComp.name));
-                }
+                analyzer.logNotEnabledComponent(log, dsComp);
             }
-
         }
 
+        if (!missingComponents.isEmpty()) {
+            log.add(new Entry(statusForMissing, missingComponents.size() + " required components are missing in SCR runtime"));
+        }
         if (countDisabled > 0) {
-            log.temporarilyUnavailable("{} required components are not active", countDisabled);
+            log.add(new Entry(statusForMissing, countDisabled + " required components are not active"));
         }
         log.info("{} required components are active", countEnabled);
 
diff --git a/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/ServicesCheck.java b/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/ServicesCheck.java
index 01e88c6..fefe8c7 100644
--- a/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/ServicesCheck.java
+++ b/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/ServicesCheck.java
@@ -116,7 +116,7 @@ public class ServicesCheck implements HealthCheck {
 
         for (String missingServiceName : missingServiceNames) {
             if (!missingServiceName.startsWith("(")) {
-                analyzer.logMissingService(log, missingServiceName, statusForMissing);
+                analyzer.logMissingService(log, missingServiceName);
             } else {
                 log.info("Service '{}' is missing", missingServiceName);
             }
diff --git a/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/scrutil/DsRootCauseAdapter.java b/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/scrutil/DsRootCauseAdapter.java
index 75a80db..c81d373 100644
--- a/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/scrutil/DsRootCauseAdapter.java
+++ b/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/scrutil/DsRootCauseAdapter.java
@@ -39,28 +39,25 @@ public class DsRootCauseAdapter {
         this.analyzer = new DSRootCause(scr);
     }
 
-    public void logMissingService(FormattingResultLog log, String missingServiceName, Status status) {
+    public void logMissingService(FormattingResultLog log, String missingServiceName) {
         Optional<DSComp> rootCauseOptional = analyzer.getRootCause(missingServiceName);
         if (rootCauseOptional.isPresent()) {
-            logRootCause(log, rootCauseOptional.get(), status);
+            logRootCause(log, rootCauseOptional.get());
         } else {
-            log.add(new Entry(status, "Missing service without matching DS component: " + missingServiceName));
+            log.info("Missing service without matching DS component: " + missingServiceName);
         }
     }
 
-    public void logNotEnabledComponent(FormattingResultLog log, ComponentDescriptionDTO desc, Status status) {
+    public void logNotEnabledComponent(FormattingResultLog log, ComponentDescriptionDTO desc) {
         DSComp component = analyzer.getRootCause(desc);
-        logRootCause(log, component, status);
+        logRootCause(log, component);
     }
 
-    private void logRootCause(FormattingResultLog log, DSComp component, Status status) {
+    private void logRootCause(FormattingResultLog log, DSComp component) {
         new RootCausePrinter(new Consumer<String>() {
-            private boolean firstLineLogged = false;
-
             @Override
             public void accept(String str) {
-                log.add(new Entry(!firstLineLogged ? status : Status.OK, str.replaceFirst("    ", "-- ").replaceFirst("  ", "- ")));
-                firstLineLogged = true;
+                log.add(new Entry(Status.OK, str.replaceFirst("    ", "-- ").replaceFirst("  ", "- ")));
             }
         }).print(component);
     }
diff --git a/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/scrutil/DsRootCauseAnalyzer.java b/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/scrutil/DsRootCauseAnalyzer.java
index c130945..51a2839 100644
--- a/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/scrutil/DsRootCauseAnalyzer.java
+++ b/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/scrutil/DsRootCauseAnalyzer.java
@@ -53,15 +53,19 @@ public class DsRootCauseAnalyzer {
         }
     }
 
-    public void logMissingService(FormattingResultLog log, String missingServiceName, Status status) {
+    public void logMissingService(FormattingResultLog log, String missingServiceName) {
         if (dsRootCauseAdapter != null) {
-            dsRootCauseAdapter.logMissingService(log, missingServiceName, status);
+            dsRootCauseAdapter.logMissingService(log, missingServiceName);
+        } else {
+            log.info("Service '{}' is missing", missingServiceName);
         }
     }
 
-    public void logNotEnabledComponent(FormattingResultLog log, ComponentDescriptionDTO desc, Status status) {
+    public void logNotEnabledComponent(FormattingResultLog log, ComponentDescriptionDTO desc) {
         if (dsRootCauseAdapter != null) {
-            dsRootCauseAdapter.logNotEnabledComponent(log, desc, status);
+            dsRootCauseAdapter.logNotEnabledComponent(log, desc);
+        } else {
+            log.info("Component '{}' is missing", desc.name);
         }
     }
 }