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/04/08 09:21:19 UTC

[felix-dev] branch master updated (f51a4a8 -> d6f2e22)

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

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


    from f51a4a8  Merge pull request #12 from apache/feature/FELIX-6245-condition-service-interfaces-FELIX-6250-healthcheck-monitor
     new 51a3fd6  FELIX-6250 Use semantically correct event topic with 'component'
     new d6f2e22  FELIX-6250 Documentation for Health Check Monitor

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 healthcheck/README.md                              | 52 ++++++++++++++++++++++
 .../hc/core/impl/monitor/HealthCheckMonitor.java   |  6 +--
 .../core/impl/monitor/HealthCheckMonitorTest.java  |  4 +-
 3 files changed, 57 insertions(+), 5 deletions(-)


[felix-dev] 02/02: FELIX-6250 Documentation for Health Check Monitor

Posted by gh...@apache.org.
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

commit d6f2e223316c5591d92d82f02b60b820183420be
Author: georg.henzler <ge...@netcentric.biz>
AuthorDate: Wed Apr 8 11:15:05 2020 +0200

    FELIX-6250 Documentation for Health Check Monitor
---
 healthcheck/README.md | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/healthcheck/README.md b/healthcheck/README.md
index 24c0b18..ac5695b 100644
--- a/healthcheck/README.md
+++ b/healthcheck/README.md
@@ -257,6 +257,58 @@ based on their tags (positive and negative selection, see the `HealthCheckFilter
 
 The DEBUG logs of health checks can optionally be displayed, and an option allows for showing only health checks that have a non-OK status.
 
+## Monitoring Health Checks
+
+### Setting up a monitor configuration
+
+By default, health checks are only executed if explicitly triggered via one of the mechanisms as described in [Executing Health Checks](#executing-health-checks) (servlet, web console plugin, JMX, executor API). With the `HealthCheckMonitor`, Health checks can be regularly monitored by configuring the the **factory PID** `org.apache.felix.hc.core.impl.monitor.HealthCheckMonitor` with the following properties:
+
+Property    | Type     | Default | Description  
+----------- | -------- | ------ | ------------
+`tags` and/or `names` | String[] | none, at least one of the two is required | **Will regularly call all given tags and/or names**. All given tags/names are executed in parallel. If the set of tags/names include some checks multiple times it does not matter, the `HealthCheckExecutor` will always ensure checks are executed once at a time only.
+`intervalInSec` or `cronExpression` | Long or String (cron) | none, one of the two is required | The interval in which the given tags/names will be executed
+`registerHealthyMarkerService` | boolean | true | For the case a given tag/name is healthy, will register a service `org.apache.felix.hc.api.condition.Healthy` with property tag=<tagname> (or name=<hc.name>) that other services can depend on. For the special case of the tag `systemready`, the marker service `org.apache.felix.hc.api.condition.SystemReady` is registered
+`registerUnhealthyMarkerService` | boolean | false | For the case a given tag/name is **un**healthy, will register a service `org.apache.felix.hc.api.condition.Unhealthy` with property tag=<tagname> (or name=<hc.name>) that other services can depend on
+`treatWarnAsHealthy` | boolean | true | `WARN` usually means [the system is usable](#semantic-meaning-of-health-check-results), hence WARN is treated as healthy by default. When set to false `WARN` is treated as `Unhealthy`
+`sendEvents` | boolean | false | Whether to send events for health check status changes. See [below](#osgi-events-for-health-check-status-changes) for details.
+
+### Marker Service to depend on a health status in SCR Components
+
+It is possible to use OSGi service references to depend on the health status of a certain  
+tag or name. For that to work, a `HealthCheckMonitor` needs to be configured for the relevant tag or name. To depend on a health status in a component, use a `@Reference` to one of the marker services `Healthy`, `Unhealthy` and `SystemReady` - this will then automatically activate/deactivate the component based on the certain health status. To activate a component only upon healthiness of a certain tag/name use the following code:
+
+```
+   @Reference(target="(tag=dbavail)")
+   Healthy healthy;
+ 
+   @Reference(target="(name=My Health Check)")
+   Healthy healthy;
+```
+For the special tag `systemready`, there is a convenience marker interface available:
+
+```
+   @Reference
+   SystemReady systemReady;
+```
+It is also possible to depend on a unhealthy state (e.g. for fallback functionality or self-healing):
+
+``` 
+   @Reference(target="(tag=dbavail)")
+   Unhealthy unhealthy;
+```
+
+NOTE: This does not support the [RFC 242 Condition Service](https://github.com/osgi/design/blob/master/rfcs/rfc0242/rfc-0242-Condition-Service.pdf) yet - however once final the marker services will also be able to implement the `Condition` interface.
+
+### OSGi events for Health Check status changes
+
+For tags/names that a `HealthCheckMonitor` is configured for and `sendEvents` is set to true, events are sent whenever a result status for any of the given tags/names has changed. The events are sent for the topic `org/apache/felix/healthchange/*`. The following events are sent:
+
+Topic Prefix | Example | Description  
+------ | ------- | -----
+`org/apache/felix/healthchange/tag/`  | `org/apache/felix/healthchange/tag/mytag` | Sent whenever the aggregate status for any of the tags as configured in `HealthCheckMonitor` changed
+`org/apache/felix/healthchange/name/`  | `org/apache/felix/healthchange/tag/My_Tag_Name ` (spaces are replaced with underscores to ensure valid topic names) | Sent whenever the status for any of the names as configured in `HealthCheckMonitor` changed
+`org/apache/felix/healthchange/component/`  | `org/apache/felix/healthchange/component/com/mycomp/myproj/MyHealthCheck` (`.` are replaced with slashes to produce valid topic names) | Sent for health checks that are based on SCR components (in addition to the name event)
+
 ## Servlet Filters
 
 ### Service Unavailable Filter


[felix-dev] 01/02: FELIX-6250 Use semantically correct event topic with 'component'

Posted by gh...@apache.org.
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

commit 51a3fd62fb9ee635d557984e3479dc590921886c
Author: georg.henzler <ge...@netcentric.biz>
AuthorDate: Wed Apr 8 11:14:21 2020 +0200

    FELIX-6250 Use semantically correct event topic with 'component'
    
    instead of 'class' (it's only the class by default but can be any name)
---
 .../org/apache/felix/hc/core/impl/monitor/HealthCheckMonitor.java   | 6 +++---
 .../apache/felix/hc/core/impl/monitor/HealthCheckMonitorTest.java   | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/monitor/HealthCheckMonitor.java b/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/monitor/HealthCheckMonitor.java
index 81a3e96..f687d68 100644
--- a/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/monitor/HealthCheckMonitor.java
+++ b/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/monitor/HealthCheckMonitor.java
@@ -341,10 +341,10 @@ public class HealthCheckMonitor implements Runnable {
                 LOG.debug("HealthCheckMonitor: Posted event for topic '{}': Status change from {} to {}", topic,
                         previousStatus, status);
                 if (!(executionResult instanceof CombinedExecutionResult)) {
-                    String componentClass = (String) executionResult.getHealthCheckMetadata().getServiceReference()
+                    String componentName = (String) executionResult.getHealthCheckMetadata().getServiceReference()
                             .getProperty(ComponentConstants.COMPONENT_NAME);
-                    if (StringUtils.isNotBlank(componentClass)) {
-                        String topicClass = EVENT_TOPIC_PREFIX + "/class/" + componentClass.replace(".", "/");
+                    if (StringUtils.isNotBlank(componentName)) {
+                        String topicClass = EVENT_TOPIC_PREFIX + "/component/" + componentName.replace(".", "/");
                         eventAdmin.postEvent(new Event(topicClass, properties));
                         LOG.debug("HealthCheckMonitor: Posted event for topic '{}': Status change from {} to {}",
                                 topicClass, previousStatus, status);
diff --git a/healthcheck/core/src/test/java/org/apache/felix/hc/core/impl/monitor/HealthCheckMonitorTest.java b/healthcheck/core/src/test/java/org/apache/felix/hc/core/impl/monitor/HealthCheckMonitorTest.java
index 70c3cd4..dfc770f 100644
--- a/healthcheck/core/src/test/java/org/apache/felix/hc/core/impl/monitor/HealthCheckMonitorTest.java
+++ b/healthcheck/core/src/test/java/org/apache/felix/hc/core/impl/monitor/HealthCheckMonitorTest.java
@@ -204,7 +204,7 @@ public class HealthCheckMonitorTest {
         assertEquals(2, postedEvents.size());
         assertEquals("org/apache/felix/healthchange/tag/test-tag", postedEvents.get(0).getTopic());
         assertEquals(Result.Status.OK, postedEvents.get(0).getProperty(HealthCheckMonitor.EVENT_PROP_STATUS));
-        assertEquals("org/apache/felix/healthchange/class/org/apache/felix/TestHealthCheck", postedEvents.get(1).getTopic());
+        assertEquals("org/apache/felix/healthchange/component/org/apache/felix/TestHealthCheck", postedEvents.get(1).getTopic());
 
         reset(eventAdmin);
         // without status change
@@ -222,7 +222,7 @@ public class HealthCheckMonitorTest {
         assertEquals("org/apache/felix/healthchange/tag/test-tag", postedEvents.get(0).getTopic());
         assertEquals(Result.Status.CRITICAL, postedEvents.get(0).getProperty(HealthCheckMonitor.EVENT_PROP_STATUS));
         assertEquals(Result.Status.OK, postedEvents.get(0).getProperty(HealthCheckMonitor.EVENT_PROP_PREVIOUS_STATUS));
-        assertEquals("org/apache/felix/healthchange/class/org/apache/felix/TestHealthCheck", postedEvents.get(1).getTopic());
+        assertEquals("org/apache/felix/healthchange/component/org/apache/felix/TestHealthCheck", postedEvents.get(1).getTopic());
         
         reset(eventAdmin);
         // without status change