|
| 1 | +:toc: |
| 2 | + |
| 3 | +# Configuring CF App Health Checks with MTA |
| 4 | + |
| 5 | +This example shows how to configure Cloud Foundry application health checks through the MTA `health-check-*` parameters. Health checks determine when Cloud Foundry considers an app instance healthy after start and while it is running; misconfiguring them is a common cause of "app crashed" or "app never became healthy" failures on deploy. |
| 6 | + |
| 7 | +## Official Documentation |
| 8 | + |
| 9 | +For general information about module parameters, see: |
| 10 | +link:https://help.sap.com/docs/btp/sap-business-technology-platform/modules?locale=en-US#module-specific-parameters[SAP BTP Documentation - Module-Specific Parameters] |
| 11 | + |
| 12 | +For the underlying Cloud Foundry concept, see: |
| 13 | +link:https://docs.cloudfoundry.org/devguide/deploy-apps/healthchecks.html[Cloud Foundry Docs - Using Application Health Checks] |
| 14 | + |
| 15 | +## Overview |
| 16 | + |
| 17 | +Four MTA parameters cover the full health-check surface of a CF application: |
| 18 | + |
| 19 | +[cols="1,3", options="header"] |
| 20 | +|=== |
| 21 | +| Parameter | Purpose |
| 22 | +| `health-check-type` | How CF probes the app: `http`, `port`, or `process` |
| 23 | +| `health-check-http-endpoint` | HTTP path CF requests when `health-check-type: http` |
| 24 | +| `health-check-timeout` | Seconds CF waits for the app to become healthy after start |
| 25 | +| `health-check-interval` | Seconds between successive health checks while the app runs |
| 26 | +|=== |
| 27 | + |
| 28 | +### Picking a `health-check-type` |
| 29 | + |
| 30 | +[cols="1,3", options="header"] |
| 31 | +|=== |
| 32 | +| Type | When to use it |
| 33 | +| `http` | The app serves HTTP and can respond with `2xx` on a known path. Pair with `health-check-http-endpoint`. |
| 34 | +| `port` | The app listens on the port CF assigns (`$PORT`) but does not serve HTTP, or you don't want to expose a health endpoint. |
| 35 | +| `process` | The app is not network-facing (worker, one-off task). CF only checks that the process is alive. |
| 36 | +|=== |
| 37 | + |
| 38 | +### About `health-check-interval` |
| 39 | + |
| 40 | +`health-check-interval` is a newer MTA parameter, added in link:https://github.com/cloudfoundry/multiapps-controller/pull/1853[cloudfoundry/multiapps-controller#1853]. It maps to CF's v3 process `health_check.data.interval` field and controls how often the liveness check runs after the app is up. If you deploy this example against an older SAP Cloud Deployment service that predates that change, the parameter will be ignored (or reported as unknown). Omit the line in that case; the other three parameters have been supported for much longer. |
| 41 | + |
| 42 | +## Try it out |
| 43 | + |
| 44 | +### Deploy from directory |
| 45 | +This approach uses deployment descriptor `mtad.yaml` and ready application binaries `appBits.zip`: |
| 46 | +``` bash |
| 47 | +$ cf deploy ./ -f ; |
| 48 | +``` |
| 49 | + |
| 50 | +### Build and deploy |
| 51 | +This approach uses development descriptor `mta.yaml` and application binaries `appBits.zip` to build an MTAR archive: |
| 52 | + |
| 53 | +``` bash |
| 54 | +$ mbt build -p cf -t . ; |
| 55 | +``` |
| 56 | + |
| 57 | +The built MTAR is then deployed: |
| 58 | + |
| 59 | +``` bash |
| 60 | +$ cf deploy cf.app.health.check_0.0.0.mtar -f ; |
| 61 | +``` |
| 62 | + |
| 63 | +NOTE: See link:mta.yaml[mta.yaml] or link:mtad.yaml[mtad.yaml] for the full parameter set. |
| 64 | + |
| 65 | +### Examine the result |
| 66 | + |
| 67 | +#### List the deployed MTA |
| 68 | +```bash |
| 69 | +$ cf mta cf.app.health.check ; |
| 70 | +Showing health and status for multi-target app cf.app.health.check in org **** / space **** as ****... |
| 71 | +OK |
| 72 | +Version: 0.0.0 |
| 73 | +Namespace: |
| 74 | + |
| 75 | +Apps: |
| 76 | +name requested state instances memory disk urls |
| 77 | +my-health-checked-app-module STARTED 1/1 19.6M 5.3M orgname-spacename-my-health-checked-app-module.example.com |
| 78 | +``` |
| 79 | + |
| 80 | +#### Verify the health check landed on the CF process |
| 81 | +Inspect the `health_check` block on the app's web process. All four values from the MTA descriptor should be reflected here: |
| 82 | + |
| 83 | +``` bash |
| 84 | +$ cf curl "/v3/apps/$(cf app my-health-checked-app-module --guid)/processes" ; |
| 85 | +{ |
| 86 | + "resources": [ |
| 87 | + { |
| 88 | + "type": "web", |
| 89 | + "instances": 1, |
| 90 | + "health_check": { |
| 91 | + "type": "http", |
| 92 | + "data": { |
| 93 | + "timeout": 180, |
| 94 | + "invocation_timeout": null, |
| 95 | + "interval": 15, |
| 96 | + "endpoint": "/index" |
| 97 | + } |
| 98 | + }, |
| 99 | + ... |
| 100 | + } |
| 101 | + ] |
| 102 | +} |
| 103 | +``` |
| 104 | + |
| 105 | +If `interval` is `null` in the output despite being set in the descriptor, the deploy service is older than link:https://github.com/cloudfoundry/multiapps-controller/pull/1853[multiapps-controller#1853]. |
| 106 | + |
| 107 | +### Use Cases |
| 108 | + |
| 109 | +Fast-recovering web app (frequent checks, short grace period): |
| 110 | +```yaml |
| 111 | +health-check-type: http |
| 112 | +health-check-http-endpoint: "/health" |
| 113 | +health-check-timeout: 30 |
| 114 | +health-check-interval: 5 |
| 115 | +``` |
| 116 | + |
| 117 | +Slow-starting app that only needs to open a port: |
| 118 | +```yaml |
| 119 | +health-check-type: port |
| 120 | +health-check-timeout: 300 |
| 121 | +health-check-interval: 30 |
| 122 | +``` |
| 123 | + |
| 124 | +Background worker with no listening port: |
| 125 | +```yaml |
| 126 | +health-check-type: process |
| 127 | +health-check-timeout: 60 |
| 128 | +``` |
| 129 | + |
| 130 | +### Related Examples |
| 131 | + |
| 132 | +* link:../cf-app[Simple CF app example, managing app attributes & deploy parameters] |
| 133 | +* link:../cf-app-features[Managing CF app features with app-features parameter] |
0 commit comments