The document discusses Apache Sling health checks, which allow testing the health and status of an AEM instance. Health checks are implemented as OSGi services that execute code and return a result. They can be run from the web console or monitored via JMX. The document provides examples of out-of-the-box health checks and how to write custom health checks as OSGi services. Health checks help ensure the reliability and availability of AEM instances.
2. Sling health checks -‐ Bertrand Delacretaz
picture: anitapeppers on
morguefile.com
How can you trust your
current (fragile?)
combina?on of OSGi
bundles and configs?
!
It needs live
TESTING.
3. Sling health checks -‐ Bertrand Delacretaz
Test code in my produc?on instance?
picture: melschmitz on morguefile.com
5. Sling health checks -‐ Bertrand Delacretaz
Health Checks?
public interface HealthCheck {
Result execute();
}
public class Result {
public boolean isOk() ...
public Status getStatus() ...
public Iterator<ResultLog.Entry> iterator() ...
}
HealthCheck
OSGi services
Serviceprops:
name,MBean,tags
7. Sling health checks -‐ Bertrand Delacretaz
Webconsole /system/console/healthcheck
8. Sling health checks -‐ Bertrand Delacretaz
Health Check MBeans (auto-‐created)
Serviceprops
:
name,MBean,tags
9. Sling health checks -‐ Bertrand Delacretaz
Health Checks as JMX Processors
MBean
MBean
MBean
HC
HC
HC
using expressions like
jmx.attribute('java.lang:type=ClassLoading', 'LoadedClassCount') > 10
&&
jmx.attribute('java.lang:type=Runtime', 'ManagementSpecVersion') > 1
13. Sling health checks -‐ Bertrand Delacretaz
Typical Use Cases
System status
Allbundlesup?
Initialcontentready?
Diskspaceok?
Externalservicesok?
Loadwithinbounds?(forjobs)
Performance
Requestspersecondok?
Requestdurationok?
Freememoryok?
Replicationqueuesok?
Configuration
Securitychecklistok?
Defaultaccountsdisabled?
Democontentremoved?
Self-test
Startupsmoketests?
Keephistoryofresults?
ReporttoHTTPfront-end
http://bit.ly/Qjxh93
TalktoJustinEdelson!
14. Sling health checks -‐ Bertrand Delacretaz
Sling devops experiments
https://github.com/bdelacretaz/
sling-devops-vol1
Health checks tell the
cluster controller when a
Sling instance is ready to
be injected in the cluster.
16. Sling health checks -‐ Bertrand Delacretaz
Out of the Box -‐ core
JmxAttributeHealthCheck
ScriptableHealthCheck
CompositeHealthCheck
Single JMX attributes
Script(let)s in any language
using BindingValuesProviders
Run other Health Checks
based on their tags
17. Sling health checks -‐ Bertrand Delacretaz
Out of the box -‐ support bundle
SlingRequestStatusHC
DefaultLoginsHealthCheck
Is my resource there?
Including its scripts?
admin:admin -> fail?
current HC bundles:
org.apache.sling.hc.core
org.apache.sling.hc.support
org.apache.sling.hc.webconsole
org.apache.sling.hc.samples
JUnitHealthCheck
And also:
From the junit.healthcheck bundle
18. Sling health checks -‐ Bertrand Delacretaz
howdoyouwrite
YourownHealth
Checks?
19. Sling health checks -‐ Bertrand Delacretaz
BYOHC -‐ Bring Your Own HCs !
@Component(...policy=ConfigurationPolicy.REQUIRE, metatype=true)
@Service(value=HealthCheck.class)
!
@Property(name=HealthCheck.NAME),
@Property(name=HealthCheck.TAGS,unbounded=PropertyUnbounded.ARRAY),
@Property(name=HealthCheck.MBEAN_NAME)
!
public class MyHealthCheck {
public Result execute() {
FormattingResultLog f = new FormattingResultLog();
...
if(badThings) f.warn(“Something happened with {}”, foo);
return new Result(f);
}
}
21. Sling health checks -‐ Bertrand Delacretaz
Health Check Executor Service
public interface HealthCheckExecutor {
!
List<HealthCheckExecutionResult>
execute(String... tags);
!
}
ExecutesHCsselectedbytags,withcaching.
Resultincludesexecutionmetadata,timeoutinfoetc.
22. Sling health checks -‐ Bertrand Delacretaz
docs at sling.apache.org : bundles : health check.
discuss on the Apache Sling dev list.
I’m @bdelacretaz - thanks!
JMX processors
Webconsole
JmxAttributeHealthCheck
ScriptableHealthCheck
CompositeHealthCheck
SlingRequestStatusHC
DefaultLoginsHealthCheck
JUnitHealthCheck
That’s it! Have fun.
@Service(HealthCheck.class)
public class MyHealthCheck {
....generate a Result here…
}