Author: ghenzler
Date: Wed Jan  9 08:51:54 2019
New Revision: 1850827

URL: http://svn.apache.org/viewvc?rev=1850827&view=rev
Log:
FELIX-5952 improved naming for sticky results

Added:
    
felix/trunk/healthcheck/annotation/src/main/java/org/apache/felix/hc/annotation/Sticky.java
      - copied, changed from r1850747, 
felix/trunk/healthcheck/annotation/src/main/java/org/apache/felix/hc/annotation/StickyWarnings.java
Removed:
    
felix/trunk/healthcheck/annotation/src/main/java/org/apache/felix/hc/annotation/StickyWarnings.java
Modified:
    
felix/trunk/healthcheck/api/src/main/java/org/apache/felix/hc/api/HealthCheck.java
    
felix/trunk/healthcheck/api/src/main/java/org/apache/felix/hc/api/execution/HealthCheckMetadata.java
    
felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/executor/ExecutionResult.java
    
felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/executor/HealthCheckExecutorImpl.java
    
felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/executor/HealthCheckResultCache.java
    
felix/trunk/healthcheck/core/src/test/java/org/apache/felix/hc/core/impl/executor/HealthCheckResultCacheTest.java
    
felix/trunk/healthcheck/core/src/test/java/org/apache/felix/hc/core/it/AsyncHealthCheckIT.java
    felix/trunk/healthcheck/docs/felix-health-checks.md

Copied: 
felix/trunk/healthcheck/annotation/src/main/java/org/apache/felix/hc/annotation/Sticky.java
 (from r1850747, 
felix/trunk/healthcheck/annotation/src/main/java/org/apache/felix/hc/annotation/StickyWarnings.java)
URL: 
http://svn.apache.org/viewvc/felix/trunk/healthcheck/annotation/src/main/java/org/apache/felix/hc/annotation/Sticky.java?p2=felix/trunk/healthcheck/annotation/src/main/java/org/apache/felix/hc/annotation/Sticky.java&p1=felix/trunk/healthcheck/annotation/src/main/java/org/apache/felix/hc/annotation/StickyWarnings.java&r1=1850747&r2=1850827&rev=1850827&view=diff
==============================================================================
--- 
felix/trunk/healthcheck/annotation/src/main/java/org/apache/felix/hc/annotation/StickyWarnings.java
 (original)
+++ 
felix/trunk/healthcheck/annotation/src/main/java/org/apache/felix/hc/annotation/Sticky.java
 Wed Jan  9 08:51:54 2019
@@ -20,10 +20,10 @@ package org.apache.felix.hc.annotation;
 import org.osgi.service.component.annotations.ComponentPropertyType;
 
 @ComponentPropertyType
-public @interface StickyWarnings {
+public @interface Sticky {
 
     public static final String PREFIX_ = "hc.";
 
-    long warningsStickForMinutes();
+    long keepNonOkResultsStickyForSec();
 
 }
\ No newline at end of file

Modified: 
felix/trunk/healthcheck/api/src/main/java/org/apache/felix/hc/api/HealthCheck.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/healthcheck/api/src/main/java/org/apache/felix/hc/api/HealthCheck.java?rev=1850827&r1=1850826&r2=1850827&view=diff
==============================================================================
--- 
felix/trunk/healthcheck/api/src/main/java/org/apache/felix/hc/api/HealthCheck.java
 (original)
+++ 
felix/trunk/healthcheck/api/src/main/java/org/apache/felix/hc/api/HealthCheck.java
 Wed Jan  9 08:51:54 2019
@@ -35,15 +35,15 @@ public interface HealthCheck {
      * service with the same value for this property. The value of this 
property must be of type String. */
     String NAME = "hc.name";
 
+    /** Optional service property: tags for categorizing the health check 
services. The value of this property must be of type String or
+     * String array. */
+    String TAGS = "hc.tags";
+    
     /** Optional service property: the name of the MBean for registering the 
health check as an MBean. If this property is missing the
      * health check is not registered as a JMX MBean. If there is more than 
one service with the same value for this property, the one with
      * the highest service ranking is registered only. The value of this 
property must be of type String. */
     String MBEAN_NAME = "hc.mbean.name";
 
-    /** Optional service property: tags for categorizing the health check 
services. The value of this property must be of type String or
-     * String array. */
-    String TAGS = "hc.tags";
-
     /** Optional service property: If this property is set the health check 
will be executed asynchronously using the cron expression
      * provided. */
     String ASYNC_CRON_EXPRESSION = "hc.async.cronExpression";
@@ -55,11 +55,12 @@ public interface HealthCheck {
      * specified in ms. */
     String RESULT_CACHE_TTL_IN_MS = "hc.resultCacheTtlInMs";
 
-    /** Optional service property: If given, warning results (that is WARN, 
CRITICAL or HEALTH_CHECK_ERROR) from the past executions will be
-     * taken into account as well for the given minutes (use Integer.MAX_VALUE 
for indefinitely). Useful for unhealthy system states that
-     * disappear but might leave the system at an inconsistent state (e.g. an 
event queue overflow). */
-    String WARNINGS_STICK_FOR_MINUTES = "hc.warningsStickForMinutes";
-
+    /** Optional service property: If given, non-ok results from past 
executions will be taken into account as well for the given seconds 
+     * (use Long.MAX_VALUE for indefinitely). Useful for unhealthy system 
states that disappear but might leave the system at an 
+     * inconsistent state (e.g. an event queue overflow where somebody needs 
to intervene manually) or for checks that should only go back 
+     * to OK with a delay (can be useful for load balancers). */
+    String KEEP_NON_OK_RESULTS_STICKY_FOR_SEC = 
"hc.keepNonOkResultsStickyForSec";
+    
     /** Execute this health check and return a {@link Result}.*/
     Result execute();
 }

Modified: 
felix/trunk/healthcheck/api/src/main/java/org/apache/felix/hc/api/execution/HealthCheckMetadata.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/healthcheck/api/src/main/java/org/apache/felix/hc/api/execution/HealthCheckMetadata.java?rev=1850827&r1=1850826&r2=1850827&view=diff
==============================================================================
--- 
felix/trunk/healthcheck/api/src/main/java/org/apache/felix/hc/api/execution/HealthCheckMetadata.java
 (original)
+++ 
felix/trunk/healthcheck/api/src/main/java/org/apache/felix/hc/api/execution/HealthCheckMetadata.java
 Wed Jan  9 08:51:54 2019
@@ -48,9 +48,15 @@ public class HealthCheckMetadata {
     private final ServiceReference serviceReference;
 
     private final Long resultCacheTtlInMs;
+    
+    private final Long keepNonOkResultsStickyForSec;
 
+    @Deprecated
     private final Long warningsStickForMinutes;
+    @Deprecated
+    private final String WARNINGS_STICK_FOR_MINUTES = 
"hc.warningsStickForMinutes";
 
+    
     public HealthCheckMetadata(final ServiceReference ref) {
         this.serviceId = (Long) ref.getProperty(Constants.SERVICE_ID);
         this.name = (String) ref.getProperty(HealthCheck.NAME);
@@ -62,7 +68,10 @@ public class HealthCheckMetadata {
         this.asyncIntervalInSec = 
toLong(ref.getProperty(HealthCheck.ASYNC_INTERVAL_IN_SEC));
 
         this.resultCacheTtlInMs = (Long) 
ref.getProperty(HealthCheck.RESULT_CACHE_TTL_IN_MS);
-        this.warningsStickForMinutes = 
toLong(ref.getProperty(HealthCheck.WARNINGS_STICK_FOR_MINUTES));
+        
+        this.keepNonOkResultsStickyForSec = 
toLong(ref.getProperty(HealthCheck.KEEP_NON_OK_RESULTS_STICKY_FOR_SEC));
+        this.warningsStickForMinutes = 
toLong(ref.getProperty(WARNINGS_STICK_FOR_MINUTES));
+        
         this.serviceReference = ref;
     }
 
@@ -130,11 +139,14 @@ public class HealthCheckMetadata {
         return resultCacheTtlInMs;
     }
 
-    /** Make warnings stick for the given amount of time.
-     *
-     * @return Time to make warn results sticky in minutes. */
-    public Long getWarningsStickForMinutes() {
-        return warningsStickForMinutes;
+    /** Makes non-ok results stick for the given amount of time.
+    *
+    * @return Time to make non-ok results sticky in seconds. */
+    public Long getKeepNonOkResultsStickyForSec() {
+        if(keepNonOkResultsStickyForSec==null && 
warningsStickForMinutes!=null) {
+            return warningsStickForMinutes * 60;
+        }
+        return keepNonOkResultsStickyForSec;
     }
 
     @Override

Modified: 
felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/executor/ExecutionResult.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/executor/ExecutionResult.java?rev=1850827&r1=1850826&r2=1850827&view=diff
==============================================================================
--- 
felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/executor/ExecutionResult.java
 (original)
+++ 
felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/executor/ExecutionResult.java
 Wed Jan  9 08:51:54 2019
@@ -38,16 +38,24 @@ public class ExecutionResult implements
 
     private final boolean timedOut;
 
+    public ExecutionResult(final HealthCheckMetadata metadata,
+            final Result simpleResult,
+            final long elapsedTimeInMs,
+            final boolean timedout) {
+        this(metadata, simpleResult, new Date(), elapsedTimeInMs, timedout);
+    }
+    
     /** Full constructor */
     public ExecutionResult(final HealthCheckMetadata metadata,
             final Result simpleResult,
+            final Date finishedAt,
             final long elapsedTimeInMs,
             final boolean timedout) {
         this.metaData = metadata;
         this.resultFromHC = simpleResult;
-        this.finishedAt = new Date();
-        this.timedOut = timedout;
+        this.finishedAt = finishedAt;
         this.elapsedTimeInMs = elapsedTimeInMs;
+        this.timedOut = timedout;
     }
 
     /** Shortcut constructor for a result */

Modified: 
felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/executor/HealthCheckExecutorImpl.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/executor/HealthCheckExecutorImpl.java?rev=1850827&r1=1850826&r2=1850827&view=diff
==============================================================================
--- 
felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/executor/HealthCheckExecutorImpl.java
 (original)
+++ 
felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/executor/HealthCheckExecutorImpl.java
 Wed Jan  9 08:51:54 2019
@@ -236,7 +236,7 @@ public class HealthCheckExecutorImpl imp
         waitForFuturesRespectingTimeout(futures, options);
         collectResultsFromFutures(futures, results);
 
-        // respect sticky results if configured via 
HealthCheck.WARNINGS_STICK_FOR_MINUTES
+        // respect sticky results if configured via 
HealthCheck.KEEP_NON_OK_RESULTS_STICKY_FOR_SEC
         appendStickyResultLogIfConfigured(results);
 
     }
@@ -245,7 +245,7 @@ public class HealthCheckExecutorImpl imp
         ListIterator<HealthCheckExecutionResult> resultsIt = 
results.listIterator();
         while (resultsIt.hasNext()) {
             HealthCheckExecutionResult result = resultsIt.next();
-            Long warningsStickForMinutes = 
result.getHealthCheckMetadata().getWarningsStickForMinutes();
+            Long warningsStickForMinutes = 
result.getHealthCheckMetadata().getKeepNonOkResultsStickyForSec();
             if (warningsStickForMinutes != null && warningsStickForMinutes > 
0) {
                 result = 
healthCheckResultCache.createExecutionResultWithStickyResults(result);
                 resultsIt.set(result);

Modified: 
felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/executor/HealthCheckResultCache.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/executor/HealthCheckResultCache.java?rev=1850827&r1=1850826&r2=1850827&view=diff
==============================================================================
--- 
felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/executor/HealthCheckResultCache.java
 (original)
+++ 
felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/executor/HealthCheckResultCache.java
 Wed Jan  9 08:51:54 2019
@@ -145,12 +145,12 @@ public class HealthCheckResultCache {
         HealthCheckExecutionResult result = origResult;
 
         HealthCheckMetadata healthCheckMetadata = 
origResult.getHealthCheckMetadata();
-        Long warningsStickForMinutes = 
healthCheckMetadata.getWarningsStickForMinutes();
-        if (warningsStickForMinutes != null && warningsStickForMinutes > 0) {
-            logger.debug("Taking into account sticky results (up to {} min 
old) for health check {}", warningsStickForMinutes,
+        Long keepNonOkResultsStickyForSec = 
healthCheckMetadata.getKeepNonOkResultsStickyForSec();
+        if (keepNonOkResultsStickyForSec != null && 
keepNonOkResultsStickyForSec > 0) {
+            logger.debug("Taking into account sticky results (up to {} sec 
old) for health check {}", keepNonOkResultsStickyForSec,
                     healthCheckMetadata.getName());
             List<HealthCheckExecutionResult> nonOkResultsFromPast = new 
ArrayList<HealthCheckExecutionResult>();
-            long cutOffTime = System.currentTimeMillis() - 
(warningsStickForMinutes * 60 * 1000);
+            long cutOffTime = System.currentTimeMillis() - 
(keepNonOkResultsStickyForSec * 1000);
             for (Status status : cacheOfNotOkResults.keySet()) {
                 long hcServiceId = ((ExecutionResult) 
origResult).getServiceId();
                 HealthCheckExecutionResult nonOkResultFromPast = 
cacheOfNotOkResults.get(status).get(hcServiceId);
@@ -187,7 +187,7 @@ public class HealthCheckResultCache {
                         resultLog.add(entry);
                     }
                 }
-                result = new ExecutionResult(healthCheckMetadata, new 
Result(resultLog), origResult.getElapsedTimeInMs());
+                result = new ExecutionResult(healthCheckMetadata, new 
Result(resultLog), origResult.getFinishedAt(), origResult.getElapsedTimeInMs(), 
false);
             }
         }
 

Modified: 
felix/trunk/healthcheck/core/src/test/java/org/apache/felix/hc/core/impl/executor/HealthCheckResultCacheTest.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/healthcheck/core/src/test/java/org/apache/felix/hc/core/impl/executor/HealthCheckResultCacheTest.java?rev=1850827&r1=1850826&r2=1850827&view=diff
==============================================================================
--- 
felix/trunk/healthcheck/core/src/test/java/org/apache/felix/hc/core/impl/executor/HealthCheckResultCacheTest.java
 (original)
+++ 
felix/trunk/healthcheck/core/src/test/java/org/apache/felix/hc/core/impl/executor/HealthCheckResultCacheTest.java
 Wed Jan  9 08:51:54 2019
@@ -140,10 +140,10 @@ public class HealthCheckResultCacheTest
 
     }
 
-    private HealthCheckMetadata setupHealthCheckMetadataWithStickyResults(long 
id, long warningsStickForMinutes) {
+    private HealthCheckMetadata setupHealthCheckMetadataWithStickyResults(long 
id, long nonOkStickyForSec) {
         reset(serviceRef);
         doReturn(id).when(serviceRef).getProperty(Constants.SERVICE_ID);
-        
doReturn(warningsStickForMinutes).when(serviceRef).getProperty(HealthCheck.WARNINGS_STICK_FOR_MINUTES);
+        
doReturn(nonOkStickyForSec).when(serviceRef).getProperty(HealthCheck.KEEP_NON_OK_RESULTS_STICKY_FOR_SEC);
         doReturn("HC id=" + id).when(serviceRef).getProperty(HealthCheck.NAME);
         return new HealthCheckMetadata(serviceRef);
     }
@@ -151,7 +151,7 @@ public class HealthCheckResultCacheTest
     @Test
     public void testCreateExecutionResultWithStickyResults() {
 
-        HealthCheckMetadata hcWithStickyResultsSet = 
setupHealthCheckMetadataWithStickyResults(1, 2 /* 2 minutes */);
+        HealthCheckMetadata hcWithStickyResultsSet = 
setupHealthCheckMetadataWithStickyResults(1, 120 /* 2 minutes */);
         ExecutionResult currentResult = spy(new 
ExecutionResult(hcWithStickyResultsSet, new Result(Result.Status.OK, "result 
for hc"), 1));
         HealthCheckExecutionResult overallResultWithStickyResults = 
healthCheckResultCache
                 .createExecutionResultWithStickyResults(currentResult);

Modified: 
felix/trunk/healthcheck/core/src/test/java/org/apache/felix/hc/core/it/AsyncHealthCheckIT.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/healthcheck/core/src/test/java/org/apache/felix/hc/core/it/AsyncHealthCheckIT.java?rev=1850827&r1=1850826&r2=1850827&view=diff
==============================================================================
--- 
felix/trunk/healthcheck/core/src/test/java/org/apache/felix/hc/core/it/AsyncHealthCheckIT.java
 (original)
+++ 
felix/trunk/healthcheck/core/src/test/java/org/apache/felix/hc/core/it/AsyncHealthCheckIT.java
 Wed Jan  9 08:51:54 2019
@@ -65,7 +65,7 @@ public class AsyncHealthCheckIT {
         }
     }
 
-    private ServiceRegistration registerAsyncHc(HealthCheck hc, String id, 
Object async, int stickyMinutes) {
+    private ServiceRegistration registerAsyncHc(HealthCheck hc, String id, 
Object async, int stickySec) {
         final Dictionary<String, Object> props = new Hashtable<String, 
Object>();
         props.put(HealthCheck.NAME, "async_HC_" + id);
         props.put(HealthCheck.TAGS, id);
@@ -75,8 +75,8 @@ public class AsyncHealthCheckIT {
             props.put(HealthCheck.ASYNC_INTERVAL_IN_SEC, async);
         }
 
-        if (stickyMinutes > 0) {
-            props.put(HealthCheck.WARNINGS_STICK_FOR_MINUTES, stickyMinutes);
+        if (stickySec > 0) {
+            props.put(HealthCheck.KEEP_NON_OK_RESULTS_STICKY_FOR_SEC, 
stickySec);
         }
 
         final ServiceRegistration result = 
bundleContext.registerService(HealthCheck.class.getName(), hc, props);
@@ -185,8 +185,8 @@ public class AsyncHealthCheckIT {
         final String id = UUID.randomUUID().toString();
         final HealthCheck hc = new TestHC();
         final long maxMsec = 5000L;
-        final int stickyMinutes = 1;
-        final ServiceRegistration reg = registerAsyncHc(hc, id, "*/1 * * * * 
?", stickyMinutes);
+        final int stickySeconds = 60;
+        final ServiceRegistration reg = registerAsyncHc(hc, id, "*/1 * * * * 
?", stickySeconds);
 
         try {
             assertStatus(id, Result.Status.OK, maxMsec, "before WARN");

Modified: felix/trunk/healthcheck/docs/felix-health-checks.md
URL: 
http://svn.apache.org/viewvc/felix/trunk/healthcheck/docs/felix-health-checks.md?rev=1850827&r1=1850826&r2=1850827&view=diff
==============================================================================
--- felix/trunk/healthcheck/docs/felix-health-checks.md (original)
+++ felix/trunk/healthcheck/docs/felix-health-checks.md Wed Jan  9 08:51:54 2019
@@ -108,7 +108,7 @@ hc.mbean.name | String | Makes the HC re
 hc.async.cronExpression | String | Used to schedule the execution of a 
`HealthCheck` at regular intervals, using a cron expression as supported by the 
[Quartz Cron 
Trigger](http://www.quartz-scheduler.org/api/previous_versions/1.8.5/org/quartz/CronTrigger.html)
 module. 
 hc.async.intervalInSec | Long | Used to schedule the execution of a 
`HealthCheck` at regular intervals, specifying a period in seconds
 hc.resultCacheTtlInMs | Long | Overrides the global default TTL as configured 
in health check executor for health check responses (since v1.2.6 of core)
-hc.warningsStickForMinutes | Long | This property will make WARN/CRITICAL 
results stay visible for future executions, even if the current state has 
returned to status OK. It is useful to keep attention on issues that might 
still require action after the state went back to OK, e.g. if an event pool has 
overflown and some events might have been lost (since v1.2.10 of core)
+hc.keepNonOkResultsStickyForSec | Long | If given, non-ok results from past 
executions will be taken into account as well for the given seconds (use 
Long.MAX_VALUE for indefinitely). Useful for unhealthy system states that 
disappear but might leave the system at an inconsistent state (e.g. an event 
queue overflow where somebody needs to intervene manually) or for checks that 
should only go back to OK with a delay (can be useful for load balancers).
 
 All service properties are optional.
 


Reply via email to