Version: v1.2

Health Check

This documentation will introduce how to use health policy to apply periodical health checking to an application.

Background

After an application is deployed, users usually want to monitor or observe the health condition of the running application as well as each components. Health policy decouples health checking procedure from application workflow execution.

It allows to set independent health inspection cycle, such as check every 30s. That helps users to notice as soon as applications turn out unhealthy and follow the diagnosis message to troubleshot.

Health Policy

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: app-healthscope-unhealthy
  5. spec:
  6. components:
  7. - name: my-server
  8. type: webservice
  9. properties:
  10. cmd:
  11. - node
  12. - server.js
  13. image: oamdev/testapp:v1
  14. port: 8080
  15. traits:
  16. - type: ingress
  17. properties:
  18. domain: test.my.domain
  19. http:
  20. "/": 8080
  21. - name: my-server-unhealthy
  22. type: webservice
  23. properties:
  24. cmd:
  25. - node
  26. - server.js
  27. image: oamdev/testapp:boom # make it unhealthy
  28. port: 8080
  29. policies:
  30. - name: health-policy-demo
  31. type: health
  32. properties:
  33. probeInterval: 5
  34. probeTimeout: 10

We apply the sample application including two components, my-server is supposed to be healthy while my-server-unhealthy is supposed to be unhealthy (because of invalid image).

As shown in the sample, a Health policy is specified. Health policy accepts two optional properties, probeInterval indicating time duration between checking (default is 30s) and probeTimeout indicating time duration before checking timeout (default is 10s).

  1. ...
  2. policies:
  3. - name: health-policy-demo
  4. type: health
  5. properties:
  6. probeInterval: 5
  7. probeTimeout: 10
  8. ...

To learn about defining health checking rules, please refer to Status Write Back.

Finally we can observe application health status from its status.services. Here is a snippet of health status.

  1. ...
  2. services:
  3. - healthy: true
  4. message: 'Ready:1/1 '
  5. name: my-server
  6. scopes:
  7. - apiVersion: core.oam.dev/v1alpha2
  8. kind: HealthScope
  9. name: health-policy-demo
  10. namespace: default
  11. uid: 1d54b5a0-d951-4f20-9541-c2d76c412a94
  12. traits:
  13. - healthy: true
  14. message: |
  15. No loadBalancer found, visiting by using 'vela port-forward app-healthscope-unhealthy'
  16. type: ingress
  17. workloadDefinition:
  18. apiVersion: apps/v1
  19. kind: Deployment
  20. - healthy: false
  21. message: 'Ready:0/1 '
  22. name: my-server-unhealthy
  23. scopes:
  24. - apiVersion: core.oam.dev/v1alpha2
  25. kind: HealthScope
  26. name: health-policy-demo
  27. namespace: default
  28. uid: 1d54b5a0-d951-4f20-9541-c2d76c412a94
  29. workloadDefinition:
  30. apiVersion: apps/v1
  31. kind: Deployment
  32. status: running
  33. ...

Appendix: Parameter List

NameDescTypeRequiredDefault Value
probeIntervaltime duration between checking (in units of seconds)intfalse30
probeTimeouttime duration before checking timeout (in units of seconds)intfalse10