Manage Eventing Functions and Settings

You can manage Eventing functions through the Couchbase Cloud UI.

Access the Cluster Eventing View

If a cluster is running the Eventing Service, Functions and settings can be managed under the cluster’s Advanced > Eventing tab.

  1. Go to the Clusters tab.

    The 'Clusters' view.
  2. Find and click on your cluster.

    This opens the cluster’s Overview tab:

    The cluster’s 'Overview' tab.
  3. Go to the Advanced > Eventing tab.

    The cluster’s 'Advanced > Eventing' tab.

Functions Summary

If there are any Functions saved on the cluster, they are displayed in the Functions summary in the cluster’s Advanced > Eventing tab.

The Functions summary.

The Functions summary lists all deployed and undeployed Functions, and displays the following information:

Function Name

The name of the Function.

Status

The status of the Function.

The status can be Deploying, Deployed, Undeploying, and Undeployed.

Add a Function

  1. From the cluster’s Advanced > Eventing tab, click Add Function.

    This opens the New Function fly-out menu:

    The 'New Function' fly-out menu.
  2. Configure the details in the Info tab.

    The 'Info' tab of the 'New Function' fly-out menu.
    1. In the Name field, enter a name for the Function you are creating.

      The Function name can only start with characters in range A-Z, a-z, 0-9 and can only contain characters in range A-Z, a-z, 0-9, underscore, and hyphen.

    2. Click the Source Bucket drop-down menu and select a bucket currently defined on the cluster.

      For more information on creating buckets, refer to Manage Buckets.

    3. Click the Metadata Bucket drop-down menu and select the Eventing metadata bucket currently defined on the cluster.

      Refer to the Couchbase Server documentation for more information about creating and using a metadata bucket for the Eventing Service.

    4. (Optional) In the Description field, enter a description of the Function you are creating.

  3. Add your JavaScript code to the Function tab.

    The 'Function' tab of the 'New Function' fly-out menu.

    The Function tab contains valid placeholder code that you can leave unchanged if it fits your needs.

  4. (Optional) Configure details in the Settings tab.

    The 'Settings' tab of the 'New Function' fly-out menu.
    • System Log Level: The granularity at which messages are logged. The options in the drop-down menu are Info (the default), Error, Warning, Debug, and Trace. This logging attribute is function-specific and is not applicable for the Eventing Service in general.

    • N1QL Consistency: The default consistency level of N1QL statements in the handler. The options in the drop-down menu are None (the default) and Request.

    • Language compatibility: The language version of the handler for backward compatibility. The options are 6.0.0 or 6.5.0.

      This is primarily to allow older handlers to continue to see the runtime behavior that existed at the time they were authored.

    • Workers: The number of worker threads per node to be allocated to the Function to process events. The default is 3 (the minimum is 1 maximum is 64).

    • Script Timeout: The number of seconds that should elapse before the script times out and is terminated. The default is 60.

  5. Once you’re satisfied with the Function’s configuration, you can click Save to save the Function in an undeployed state, or you can deploy it right away by clicking Deploy.

The Logs tab won’t display anything until the Function is deployed. Refer to Eventing Logs for more information.

After saving or deploying the Function, the fly-out menu closes and the new Function is added to the Function summary list on the Advanced > Eventing tab. If you chose to deploy the Function, it will be listed with a status of Deploying until it is fully deployed. If you chose to just save the Function, then it will be listed with a status of Undeployed until you choose to deploy it.

Deploying and Undeploying a Function

When you create an Eventing Function, it can be deployed right away, or saved in an undeployed state for later deployment. The Functions summary shows all functions on the cluster, along with their respective deployment status.

To either deploy or undeploy an an existing Function, start by finding the specific Function in the Functions summary list, and then clicking on its row to open the Function’s fly-out menu. At the bottom of the fly-out menu, there will be a button labeled Deploy or Undeploy, depending on the current status of the Function. Click Deploy to deploy the Function, or Undeploy to undeploy the Function.

At this time, Couchbase Cloud automatically sets the Function’s Feed Boundary to Everything upon deployment. The Feed Boundary determines whether documents previously in existence need to be included in the Function’s activities. When the Feed Boundary is set to Everything, the Function is invoked on all mutations available in the cluster. This is opposed to setting the Feed Boundary to From Now, where the Function is only invoked on future instances of data mutation post Function deployment).

Modify a Function

To modify a specific Function, start by finding the Function in the Functions summary list, and then clicking on its row to open the Function’s fly-out menu.

Only a subset of the Function’s settings are available for modification after the Function is created.

  • Info tab:

    • Name: Cannot be modified

    • Source Bucket: Cannot be modified

    • Metadata Bucket: Cannot be modified

    • Description: Can be modified at any time

  • Function tab:

    • The Function’s JavaScript code can only be modified when the Function is undeployed.

  • Settings tab:

    • System Log Level: Can be modified at any time

    • N1QL Consistency: Can only be modified when the Function is undeployed

    • Language Compatibility: Can only be modified when the Function is undeployed

    • Workers: Can only be modified when the Function is undeployed

    • Script Timeout: Can only be modified when the Function is undeployed

To modify any of the above settings that require the Function to be in an undeployed state, you will first need to undeploy the Function by clicking the Undeploy button at the bottom of the fly-out menu.

Once you’re satisfied with the modifications you’ve made to the function, make sure to click Save to commit the changes.

Eventing Logs

The Eventing Service creates two different types of logs:

  • System log

  • Application logs

System Log

The Eventing Service creates a system log file — eventing.log — that captures information related to general management and supervision of the Eventing Service. In addition, this log file also captures life cycle and housekeeping information for individual Functions according to each Function’s System Log Level setting. (Refer to the Add a Function or Modify a Function sections above for how to access this setting.)

Application Logs

Each deployed Function has its own application log. Application logs allow you to identify and capture various business logic related activities and errors via user-defined messages specific to each Function.

The information that goes to these log files is solely dependent on the logic of the Function via log(…) statements put inside the individual Function handler’s JavaScript code. As such, there is no logging level for application logs (unlike the Eventing system log, who’s logging level can be modified in the Settings tab of the Function’s fly-out menu). Application logs are primarily used for the development and debugging of business logic.

To view the application log of a specific Function, start by finding the Function in the Functions summary list, and then clicking on its row to open the Function’s fly-out menu. The Function’s application log is displayed in the Logs tab.

The 'Logs' of deployed Function’s fly-out menu.

Only the most recent application log information is displayed (in reverse order with the most recent lines first). After deploying a Function, you can review this log to ensure that the Function deployed as you expected.

Delete a Function

Before you can delete a specific Function, you must first ensure that it is undeployed. Only Functions that are in an undeployed state can be deleted.

Once the Function is undeployed, find it in the Functions summary list and click the Trash icon next to its row.

The list of Functions in the 'Advanced > Eventing' tab, with the cursor hovering over the Trash icon of one of the Functions.

When prompted to confirm the deletion, click Confirm.

The prompt to confirm Function deletion.

Eventing Settings

The Settings area contains a list of settings for configuring the Eventing Service.

The 'Settings' area of the 'Advanced > Eventing' tab.

Debugger

The Eventing Service includes a powerful full-function online real-time Javascript Debugger. Debug is a special flag on a Function. The Debug option integrates seamlessly with the Google Chrome Debugger engine for running the JavaScript code of any handler.

Enabling the Debugger should be avoided in production environments, as it affects the in-order processing of the document mutations as well as introducing timing related issues. Debugging is a convenience-feature intended to help during Function development.