Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new parameters to monitor health of node
couchbase.healthCheckInterval determines how often we check the health of the node couchbase.healthCheckThreshold determines how long the health check operation can take if it takes longer than this, the service will be marked unavailable until it returns to a value below the threshold current the healthcheck operation is retreiving the bucket map aka :9091/pools/default/buckets
- Loading branch information
Showing
4 changed files
with
95 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/org/elasticsearch/transport/couchbase/capi/HealthChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.elasticsearch.transport.couchbase.capi; | ||
|
||
import org.elasticsearch.common.logging.ESLogger; | ||
|
||
|
||
public class HealthChecker implements Runnable { | ||
|
||
private boolean running = true; | ||
private ESLogger logger; | ||
private ElasticSearchCAPIBehavior capiBehavior; | ||
private ElasticSearchCouchbaseBehavior couchbaseBehavior; | ||
private long checkInterval; | ||
private long threshold; | ||
|
||
public HealthChecker(long checkInterval, long threshold, ESLogger logger, ElasticSearchCouchbaseBehavior couchbaseBehavior, ElasticSearchCAPIBehavior capiBehavior) { | ||
this.couchbaseBehavior = couchbaseBehavior; | ||
this.capiBehavior = capiBehavior; | ||
this.checkInterval = checkInterval; | ||
this.threshold = threshold; | ||
this.logger = logger; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
while(running) { | ||
try { | ||
Thread.sleep(checkInterval); | ||
|
||
long start = System.currentTimeMillis(); | ||
couchbaseBehavior.getBucketsInPool("default"); | ||
long end = System.currentTimeMillis(); | ||
|
||
long took = end - start; | ||
if(took > threshold) { | ||
logger.info("Health check took {} exceeding threshold {}, marking service unavailable.", took, threshold); | ||
couchbaseBehavior.setAvailable(false); | ||
capiBehavior.setAvailable(false); | ||
} else { | ||
logger.info("Health check passed, took {}", took); | ||
couchbaseBehavior.setAvailable(true); | ||
capiBehavior.setAvailable(true); | ||
} | ||
|
||
|
||
} catch (InterruptedException e) { | ||
continue; | ||
} | ||
} | ||
} | ||
|
||
public void stop() { | ||
running = false; | ||
} | ||
|
||
} |