Updated on 2024-11-12 GMT+08:00

Creating a Flow

This section describes how to create and orchestrate a flow. You can create a standard or express flow for your service requirements.

  • Standard flow: better for common services that take a long time to execute. Standard flows can only be invoked asynchronously, and their execution records are persisted for query.
  • Express flow: better for services that take less than 5 minutes to execute and require ultimate performance. Express flows can be invoked synchronously or asynchronously, but their execution records (such as execution node history) are not persisted. The synchronous execution interface returns results, and the execution logs reported to LTS are displayed on the logs page.

    Express flows are available for free trial as a time-limited offer.

Prerequisites

Procedure

  1. Log in to the FunctionGraph console, and choose Flows in the navigation pane.
  2. On the Function Flows page, click Create next to Standard Flow or Express Flow.

    Function flows created on OBS DWR cannot be edited or deleted on the FunctionGraph console. If you need to do so, go to OBS DWR.

  3. Orchestrate a flow for your application.

    1. Orchestrate the flow by dragging components.
      Take the flow in Figure 1 as an example. Drag a start node, function, and stop node to the edit box, and connect them using lines.
      Figure 1 Orchestrating a flow
    2. Click the function node to edit it. For details about the function parameters, see Table 1. Parameters marked with an asterisk (*) are mandatory.

      For the function node, select function 2, and configure this node by referring to Figure 2. The result will be the value of the event input plus 2.

      Figure 2 Configuring a function node
      Table 1 Function parameters

      Parameter

      Description

      * App

      App to which the desired function belongs. You can create multiple functions under an app.

      * Function

      Function you want to use.

      NOTE:
      • The data returned by the configured function must be in JSON format. Otherwise, it cannot be parsed.
      • Go functions can return stream data. To enable this feature, choose Configuration > Advanced Settings on the function details page, and select Streaming Response.

      * Version

      Function version you want to use.

      * CallMode

      By default, function nodes in a flow are invoked synchronously.

      NOTE:
      • Synchronous invocation does not support long-term running functions and is max. 15 minutes.
      • Asynchronous invocation supports long-term running functions. The max. duration of a function node is the same as that supported by FunctionGraph.

      Function Parameters

      Parameters that will be passed in JSON format in the body.

      Key: parameter name

      Value: parameter value

      DefaultValue: used if no value is specified for the parameter

      Operation: Edit or delete the parameter.

      Input Filter Expression

      Selects part of the JSON output of the previous step to use it as the input of the current step.

      Output Filter Expression

      Selects part of the JSON output of the current step to pass it to the next step.

    3. Click the EG node to edit it. For details about the EG parameters, see Table 2. Parameters marked with an asterisk (*) are mandatory.

      Before configuring an EG node, ensure that you have created an event source and channel on EG. For details, see Figure 3.

      Figure 3 Configuring an EG node
      Table 2 EG node parameters

      Parameter

      Description

      * Event Channel

      Event channels receive events from event sources. Function flows support only custom event channels, which you create to receive events from custom sources. For details, see the event channel description in the EG documentation.

      * Source

      Event sources are applications that produce events. Function flows support only custom application event sources, which publish events to EG through a custom channel.

      For details, see the event source description in the EG documentation.

      DataContentType

      The format of Data, that is, event payload.

      NOTE:

      Only application/json is supported.

      Data

      Event content.

      Subject

      A subject or object on which an event occurs.

      Input Filter Expression

      Selects part of the JSON output of the previous step to use it as the input of the current step.

      Output Filter Expression

      Selects part of the JSON output of the current step to pass it to the next step.

    4. Configure processors by referring to Table 3. Parameters marked with an asterisk (*) are mandatory.
      Table 3 Processor parameters

      Category

      Parameter

      Description

      Callback

      * Callback timeout (min)

      If no response is returned within the specified timeout, the node fails.

      * Callback Type

      Type of the service node that can be called back by a function flow.

      NOTE:

      Only function nodes are supported.

      * App

      App to which the desired function belongs. You can create multiple functions under an app.

      * Function

      Function you want to use.

      NOTE:
      • The data returned by the configured function must be in JSON format. Otherwise, the data cannot be parsed.
      • Go functions can return stream data. To enable this feature, choose Configuration > Advanced Settings on the function details page, and select Streaming Response.

      * Version

      Function version you want to use.

      * CallMode

      By default, function nodes in a flow are invoked synchronously.

      NOTE:
      • Synchronous invocation does not support long-term running functions and is max. 15 minutes.
      • Asynchronous invocation supports long-term running functions. The max. duration of a function node is the same as that supported by FunctionGraph.

      Function Parameters

      Parameters that will be passed in JSON format in the body.

      Key: parameter name

      Value: parameter value

      DefaultValue: used if no value is specified for the parameter

      Operation: Edit or delete the parameter.

      Input Filter Expression

      Selects part of the JSON output of the previous step to use it as the input of the current step.

      Output Filter Expression

      Selects part of the JSON output of the current step to pass it to the next step.

      Subflow

      Subflow

      Select a flow.

      Proceed Until Subflow Completed

      This option is enabled by default.

      Input Filter Expression

      Selects part of the JSON output of the previous step to use it as the input of the current step.

      Output Filter Expression

      Selects part of the JSON output of the current step to pass it to the next step.

      Parallel Branch

      * Completion Criterion

      • All branches completed: suitable when there are two or more branches
      • 1 branch completed: suitable when there is only one branch
      • Set number of branches completed: suitable for one of the two or more branches if possible

      Input Filter Expression

      Selects part of the JSON output of the previous step to use it as the input of the current step.

      Output Filter Expression

      Selects part of the JSON output of the current step to pass it to the next step.

      Set Branches

      Set the number of branches that must be completed if you set Completion Criterion to Set number of branches completed.

      * Result Output Path

      Path to which the result of this parallel branch will be output in the JSON format. The path is a key and the result is a value. If this parameter is not set, the default path is result.

      Start

      Triggers

      Start of a flow. Each flow has only one start node. For details about how to create a trigger, see Creating a Flow Trigger.

      Error Handling

      * Retry

      Determines the next step in case of an execution failure.

      • Retry Condition(JSONPath): Example: $.status == 500
      • Retry Interval (1-30s): The default value is 1s.
      • Maximum Retries (1-8): The default value is 3.

      * Retry Condition

      A JSONPath expression. Result true indicates that an error is captured. The error handling node is executed then.

      Loop

      * Array Path

      Path of the array variable to be traversed.

      * Iteration Variable

      This variable will be replaced by the name of an element in the array during cyclic iteration.

      * Result Output Path

      Output path of the result array for all iteration branches.

      Parallel Iterations

      Number of iteration branches to be run concurrently. Value range: 0–100. 0 indicates unlimited.

      Iteration Interval (s)

      Interval between parallel iterations.

      Input Filter Expression

      Selects part of the JSON output of the previous step to use it as the input of the current step.

      Output Filter Expression

      Selects part of the JSON output of the current step to pass it to the next step.

      Wait

      * Latency (s)

      Default value: 1000s

      Service

      Execution Mode

      Way that functions in this node will be executed.

      • Serial: Functions will be executed in the order they are connected.
      • Parallel: Functions will be executed concurrently.

      Input Filter Expression

      JSONPath expression used to filter the input information of the node.

      Output Filter Expression

      JSONPath expression used to filter the output information of the node.

      Conditional Branch

      * Branch Type

      • Conditional
      • Default

      If there is a conditional branch, a default branch is required.

      Expression

      JSONPath expression required for a conditional branch. For details, see Expression Operators.

      Input Filter Expression

      JSONPath expression used to filter the input information of the node.

      Output Filter Expression

      JSONPath expression used to filter the output information of the node.

      Stop

      Stop

      Not followed by any other node.

    5. After configuring all nodes, click Save in the upper right corner.

      If a node in the flow is modified, save the changes before starting the flow.

    6. On the Create Flow page, click on the right of the function flow name in the upper left corner, set parameters, and click OK.
      Table 4 Configuration

      Parameter

      Description

      * Name

      Flow name.

      * Enterprise Project

      Select an enterprise project.

      Combine Input

      Whether to combine the previous node's output with the current node's input.

      Description

      Description about the flow.

      Figure 4 Editing a flow
    7. Click Start. On the Start Execution page, specify input or start the flow directly. In this example, select With input.
      {
        "input":3
      }
      Figure 5 Starting execution

      The input values must be in JSON format.

    8. Click Execute. A message indicating that the flow is started successfully is displayed in the upper right corner.
    9. Click the flow name to go to the details page and view the execution result.

Viewing Flows

  1. Return to the FunctionGraph console, and choose Flows in the navigation pane.
  2. View flows in card or list mode.

    Figure 6 Selecting a display mode
    • Card mode
      Figure 7 Card mode
    • List mode
      Figure 8 List mode

  3. View all flows that you have created, and perform the operations described in Table 5 as required.

    Table 5 Operation description

    Operation

    Description

    Edit

    Click Edit to modify a flow.

    Start

    Choose More > Start to execute a flow.

    Delete

    • Deleting a single flow: Choose More > Delete to delete a flow.
    • Deleting multiple flows: Select multiple flows and click Delete in the upper left corner to delete them.

  4. Click the name of a flow to view details.

    • Viewing basic information

      On the Basic Information tab page, view the flow name, ID, update time, and creation time.

    • Viewing execution records

      On the Metric tab page, view the execution history, input, output, and node logs.

      To modify the flow information, click Design in the upper right corner.

    • Viewing metrics

      On the Monitoring tab page, view the number of invocations, duration, number of errors, and number of executions that are in progress. Table 6 describes the metrics.

      Table 6 Flow metrics

      Metric

      Unit

      Description

      Invocations

      Count

      Total number of invocation requests, including successful, failed, and number of executions that are in progress. In case of asynchronous invocation, the count starts only when a flow executes in response to a request.

      Duration

      ms

      Average time taken to execute a flow in a specified period.

      Errors

      Count

      Number of times that a flow failed to be executed.

      Running Workflows

      Count

      Number of invocation requests that are being processed.

      Throttles

      Count

      Number of times that a flow failed to be executed due to rate limiting.