Knative Flows Task Force
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Composable flows **Knative Eventing Working Group** **Last Updated:** Jan 27th, 2022 **Main GitHub Issue**: [1521](https://github.com/knative/eventing/issues/1521) **Contributor(s)**: - Lionel Villard (villard@us.ibm.com) ## Motivation / Abstract Knative Eventing flows constructs (Sequence and Parallel) are not composable, considerably limiting their usefulness. For instance, a Parallel branch cannot reference an existing Sequence and forward the result to the next step to, let's say, aggregate the results. This limitation cannot be easily solved at the application layer (for instance by calling a subflow) mostly due to the dependency on inner workings, such as reference resolution, to forward the result to an object somewhere in the middle of a flow. The only reasonable solution is for Knative Eventing to support this pattern out-of-the-box because 1. it is a very common pattern 2. it not something that can easily be done at the application level. ## Background Knative Eventing provides two flows constructs, [Sequence](https://knative.dev/docs/eventing/flows/sequence/) and [Parallel](https://knative.dev/docs/eventing/flows/parallel/). Both constructs allow references to external sinks with the implicit assumption that those sinks are [callable](https://knative.dev/docs/eventing/sinks/) (i.e. return 0 or 1 event) in order for the flow to *keep going* when an event is received and to be interrupted when no event is received. For instance, consider this sequence: ```yaml= apiVersion: flows.knative.dev/v1 kind: Sequence metadata: name: oneseq spec: steps: - ref: apiVersion: serving.knative.dev/v1 kind: Service name: identity - ref: apiVersion: serving.knative.dev/v1 kind: Service name: last-step ``` The second step is only executed when the service in the first step synchronously returns a non-empty event. When the first step is a reference to a flow construct, never immediately returning an event, the second step is consequently never executed. The proposal below leverages existing Knative Eventing capabilities, specifically [error handling](https://knative.dev/docs/eventing/event-delivery/) and delivery guarantees. Under the cover, both Sequence and Parallel get realized as a set of Channel and Subscription objects by their respective reconciler. ## Proposal Design / Approach Current flow constructs are not Callable, but they *eventually* produce zero or one event via [`reply`](https://knative.dev/docs/reference/api/eventing-api/#flows.knative.dev/v1.SequenceSpec). We propose to call this type of objects **composable**: - Composable objects are Addressable, i.e. an event can be delivered over HTTP to an address defined in their `status.address.url` field. - Composable objects can asynchronously forward events over HTTP to an address specified in their `spec.reply` field. In addition, sink objects can potentially invoked in two different ways: - async mode: The current event is forwarded to both the sink and the next step. Any event returned by the sink ingress is dropped. - sync mode: The event(s) produced by the sink (synchronously or asynchronously) are forwarded to the next step. Asynchronous invocation of both Callable and Composable objects is straightforward. The real challenge is synchronous invocation of composable objects, as discussed below. A simple approach is to clone the referenced composable object and to inject the address of the next step into the `spec.reply` field. While this solution could work (modulo some open questions like what happens when `spec.reply` is already specified?), it leads to a lot of additional objects being created, all connected the same way (same topology) except for the last `spec.reply`. An alternative solution is to dynamic dispatch flow construct results to the next step. This can be achieved by maintaining a stack of callers (e.g. by using a CloudEvent extension attribute) and by adding stack manipulation functions, one for the flow entry (push) and one for the flow exit (pop). This is how most compilers handle [function calls](https://en.wikipedia.org/wiki/Subroutine#Call_stack). TODO: explain how errors are handled, maybe from a continuation passing style PoV. ## Implementation ### Composable duck-type The Composable duck-type is defined as follows: ```go= type Composable struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` Spec ComposableSpec `json:"spec,omitempty"` Status ComposableStatus `json:"status,omitempty"` } // ComposableSpec contains Spec of the Composable object type ComposableSpec struct { // Reply is a Reference to where the Composable result // is sent to // +optional Reply *duckv1.Destination `json:"reply,omitempty"` } // ComposableStatus contains the Status of a Composable object. type ComposableStatus struct { // AddressStatus is the part where the Composable fulfills the Addressable contract. // +optional duckv1.AddressStatus `json:",inline"` } ``` ### Asynchronous Composable Invocation #### Call Stack The call stack is represented by a CloudEvent attribute. Let's call it `knativeflowcallstack`. Its value is a space-separated list of resolved URLs. ##### Maximum size Knative Eventing should enforce the limit on the maximum number of nested calls. A global configuration parameter will be added. ##### Security and integrity In this proposal the flow state is stored within the CloudEvent `knativeflowcallstack` extension attribute, which is visible to applications, possibly leading to meta-data corruption. A solution to this problem is to remove and reinject this attribute before and after a non-composable function is invoked. #### Data-Plane This solution relies on two managed stateless functions: `flow-push` and `flow-pop`. The first one manipulates the received `knativeflowcallstack` by adding a new URL, passed as an HTTP query parameter, to the end of the list and directly forwards the modified event to the specified reference. The second service removes the last URL from the received CloudEvent and directly forwards the modified event to the URL. Side comment: these services could be removed if Knative Eventing Subscription would support `ceOverrides` over list, or if it would support capabilities negociation. ![](https://i.imgur.com/QKusMUf.png) #### Control-Plane When the referenced composable is asynchronously invoked, the flow reconciler configures the underlying Subscription to point to the built-in `flow-push` function. Here an example of a generated Subscription: ```yaml= apiVersion: messaging.knative.dev/v1 kind: Subscription metadata: name: <subscription-name> # Name of the Subscription. spec: subscriber: uri: https://flow-push.knative-eventing?URL=<resolved URI> ``` On the egress, the flow operator checks the `spec.reply` field is properly set to send event to the `flow-pop` built-in function. If not, the reconciliation process fails. ## Integration Checklist ### Operations TBD ### Observability TBD ### Test Plan TBD ### Documentation TBD ### User Experience TBD ## Alternative Proposals ### Delivery Contract Extension As suggested [in this comment](https://docs.google.com/document/d/1j0DsiyTtET6QNyz3wcUrXhapJk602snurZBQm8Ru07k/edit?disco=AAAAHe6n54M), extend the delivery contract to include an optional `Reply-Location` header that indicates a URL where reply events may be POSTed (instead of, or in addition to, being processed from the HTTP Response). `Reply-Location` would _not_ be a CloudEvents attribute; it would be a hop-by-hop HTTP option on the delivery, similar to the `Prefer: Reply` header (and possibly set in similar circumstances). _Pros:_ * Possibly simpler implementation vs a call stack * Also applies to long-lived delivery to a Trigger or Subscription Target * Potentially provides an avenue for returning multiple response events to a single event. _Cons_: * Recipients using `Reply-Location` would need to ensure that the event was persisted to stable storage before returning a 200. * `Reply-Location` information might need to be persisted across multiple Channel hops in a Sequence or Parallel, which is not supported in the current implementation. * This does not avoid the conflict between having `Reply-Location` set on a request and `spec.reply` in Sequence or Parallel. (It seems to me that Broker and Channel would reasonably ignore this parameter.)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully