C3 AI Documentation Home

Check if Application Nodes are Ready to Accept Traffic Using a Readiness Probe

You can configure readiness probes to make sure your application nodes are ready to accept network traffic. The readiness status of an application node determines if a load balancer should include or exclude the node when forwarding requests. For example, the Kubernetes Service does not load balance requests to a leader node that has an unready status.

You might want to use a readiness probe in the following scenarios:

  • If you have slow-starting application nodes that require warm caches or must perform other tasks before serving network requests.
  • If you want to mark certain application nodes as unready when they are overloaded with outstanding client requests.

Use the following Types to configure a readiness probe for your application:

Requirements

Have at least one of the following roles:

  • C3.AppAdmin role to configure a readiness probe for your own applications.
  • C3.EnvAdmin role to configure a readiness probe for applications in your environment.
  • C3.ClusterAdmin role to configure a readiness probe for applications in your cluster.

Create an instance of the readiness probe

In the C3 AI Console for your application, create an instance of the App.Probe Type. Specify the following parameters:

  • Probe.READINESS as the probe name
  • The App instance of your application

Here is an example of how to create an instance of the readiness probe:

JavaScript
app = C3.app()
probe = App.Probe.make({ name: Probe.READINESS, app: app })

Configure a readiness probe

  1. Prepare a configuration for a readiness probe using the App.Probe.Config Type. Specify the following code:

    • The probe action to check if the application node is ready to accept requests
    • Probe.READINESS as the configuration name
    • How often you want to run the probe action on each of the application nodes
    • The timeout period in seconds for the probe action

    If the probe does not complete the readiness check within the timeout limit, the readiness status is not ready.

    Here is an example configuration for the readiness probe:

    JavaScript
    probeAction = PartiallyAppliedAction.make({ typeName: "Echo", actionName: "echoAnyJava", args: { "msg": true }});
    probeConfig = App.Probe.Config.make({ name: Probe.READINESS, action: probeAction, periodSeconds: 10, timeout: { interruptInSec: 5 }});
  2. Call the App.Probe#configure API to configure the readiness probe, and the App.Probe#syncAll API to broadcast the change to all nodes in the application:

    JavaScript
    probe.configure(probeConfig)
    probe.syncAll()

Check if an application node is ready

Call the Server#isReady API to check if an application node is ready to accept requests:

JavaScript
myAppNode = C3.app().nodes(true)[0]
myAppNode.call("Server", "isReady")

If the response is true, then the application node is ready to accept requests. If your nodes have a load balancer, the load balancer includes the ready node when sending requests.

If the response is false, then the application node is not ready to accept requests. If your nodes have a load balancer, the load balancer excludes the unready node when sending requests.

Remove the readiness probe

To remove the readiness probe for your application, complete the following steps:

Call the App.Probe#remove API to remove the readiness probe, and the App.Probe#syncAll API to broadcast the change to all nodes in the application:

JavaScript
probe.remove()

Recover application from incorrect readiness probe

If the readiness probe is not configured correctly, it may fail and the application might become unreachable to network requests.

If your application experiences issue after you attempt to set up a readiness probe, you can reconfigure or remove the probe using the doNotRemote=true parameter.

Without the doNotRemote=true parameter, App.Probe APIs call on the application that has the readiness probe. Call App.Probe#remove or App.Probe#configure with the doNotRemote=true parameter at the environment level to ensure the following code succeeds as your application rejects network requests.

See the Type documentation App.Probe#remove and App.Probe#configure to learn more about how it takes CloudClusterOpSpec#doNotRemote as a parameter.

In the environment C3 AI Console, run the following code to recover the application.

You can reconfigure the readiness probe so that it does not call on your application:

JavaScript
probe.configure(config, {'doNotRemote': true })

Or, you can remove the readiness probe from your application:

JavaScript
probe.remove({'doNotRemote': true })

After you run either of the previous commands, run the following to broadcast the change to all nodes in the application:

JavaScript
probe.syncAll()

Seed a readiness probe configuration

If you are developing a root package, you can seed a readiness probe configuration so that your app users do not need to configure it themselves.

Create a file called readiness.json to seed the App.Probe Type at the path config/App.Probe.Config/.

Here is an example readiness.json file:

JSON
{
    "name": "readiness",
    "action": {
        "typeName": "Echo",
        "actionName": "echoAnyJava",
        "args": {
            "msg": {
                "value": true
            }
        }
    },
    "timeout": {
        "interruptInSec": 5.0
    },
    "periodSeconds": 10
}

Users with the AppAdmin role can override the seeded readiness probe by following the configuration steps at "Configure a readiness probe" in this topic.

Was this page helpful?