|
| 1 | +# OpenFunction Context Specs |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +### Statement |
| 6 | + |
| 7 | +`Scope` indicates which functions-framework has already support this item. |
| 8 | + |
| 9 | +#### functions-framework abbreviation |
| 10 | + |
| 11 | +OpenFunction/functions-framework-go -> ff-go |
| 12 | + |
| 13 | +## Context |
| 14 | + |
| 15 | +Example: |
| 16 | + |
| 17 | +```json |
| 18 | +{ |
| 19 | + "name": "function", |
| 20 | + "version": "v1", |
| 21 | + "requestID": "a0f2ad8d-5062-4812-91e9-95416489fb01", |
| 22 | + "port": "50002", |
| 23 | + "clientPort": "44538", |
| 24 | + "inputs": {}, |
| 25 | + "outputs": {}, |
| 26 | + "runtime": "Async", |
| 27 | + "state": "", |
| 28 | + "prePlugins": [], |
| 29 | + "postPlugins": [], |
| 30 | + "pluginsTracing": { |
| 31 | + "enable": true, |
| 32 | + "provider": { |
| 33 | + "name": "skywalking", |
| 34 | + "oapServer": "localhost:xxx" |
| 35 | + }, |
| 36 | + "tags": { |
| 37 | + "key": "value" |
| 38 | + }, |
| 39 | + "baggage": { |
| 40 | + "key": "value" |
| 41 | + } |
| 42 | + }, |
| 43 | + "out": { |
| 44 | + "code": 200, |
| 45 | + "data": "", |
| 46 | + "error": "", |
| 47 | + "metadata": {} |
| 48 | + } |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +Specification: |
| 53 | + |
| 54 | +| Key | Type | Description | Scope | example | |
| 55 | +| ---------- | --------------- | --------------------------------------------------------- | ------------------------------------------------------------ | -------------------------------------- | |
| 56 | +| name | string, require | Function name. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | "myfunction", "hello-func" | |
| 57 | +| version | string, require | Function version. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | "v1", "v2" | |
| 58 | +| requestID | string | Request ID, uuid format. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | "a0f2ad8d-5062-4812-91e9-95416489fb01" | |
| 59 | +| port | string | Function serving port. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | "50003" | |
| 60 | +| clientPort | string | Dapr client port. (default is "50001" in Kubernetes mode) | [ff-go](https://github.com/OpenFunction/functions-framework-go) | "50001" | |
| 61 | +| inputs | map | Function input from bindings data.<br />A map of Input objects. The key is the name of input and the value is input object, see [Input](#input). <br />Empty means no input. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | | |
| 62 | +| outputs | map | Function output to bindings data. <br />A map of Output objects. The key is the name of output and the value is output object, see [Output](#output). <br />Empty means no output. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | | |
| 63 | +| runtime | enum, require | Function serving runtime, see [Runtime](#runtime). | [ff-go](https://github.com/OpenFunction/functions-framework-go) | "Knative", "Async" | |
| 64 | +| state | string | Used to store the states of the function in operation. | | | |
| 65 | +| out | map | Outputs after the function is run, see [Out](#out). | [ff-go](https://github.com/OpenFunction/functions-framework-go) | | |
| 66 | +| prePlugins | array | List of names of plugins executed before the user function. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | ["plg1", "plg2"] | |
| 67 | +| postPlugins | array | List of names of plugins executed after the user function. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | ["plg1", "plg2"] | |
| 68 | +| pluginsTracing | map | Configuration of the tracing plugins, see [PluginsTracing](#pluginstracing). | [ff-go](https://github.com/OpenFunction/functions-framework-go) | | |
| 69 | + |
| 70 | +### Input |
| 71 | + |
| 72 | +Example: |
| 73 | + |
| 74 | +```json |
| 75 | +{ |
| 76 | + "my-input": { |
| 77 | + "uri": "my-uri", |
| 78 | + "componentName": "my-component", |
| 79 | + "componentType": "bindings.kafka", |
| 80 | + "metadata": { |
| 81 | + "Content-Type": "application/json; charset=utf-8" |
| 82 | + } |
| 83 | + } |
| 84 | +} |
| 85 | +``` |
| 86 | + |
| 87 | +Specification: |
| 88 | + |
| 89 | +| Key | Type | Description | Scope | example | |
| 90 | +| ---------- | ------ | ------------------------------------------------------------ | -------------------------------------- | -------------------------------------- | |
| 91 | +| name(key) | string | Input name. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | "demo-kafka", "cron-job" | |
| 92 | +| uri | string | Input serving listening path. This indicates the destination of the input data.<br />Bindings: same as the component's name, can be omitted.<br />Pubsub: represent the topic's name, cannot be omitted. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | "echo" | |
| 93 | +| componentType | string | Input type. When using Async as runtime, you need to set the `type` (refer to [Input Type](#input-type)) parameter. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | "bindings.kafka" | |
| 94 | +| componentName | string | The component's name. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | "componentA" | |
| 95 | +| metadata | map | The metadata to be passed to dapr for use. Usage can be found in dapr's documentation. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | | |
| 96 | + |
| 97 | +#### Input Type |
| 98 | + |
| 99 | +Effective only when using Async as runtime. |
| 100 | + |
| 101 | +| Value | Description | Scope | |
| 102 | +| ---------- | ------------------------------------------------------------ | ------------------------------------------------------------ | |
| 103 | +| bindings.* | Indicates that the input is the Dapr bindings component. Refer to [Bindings API reference](https://docs.dapr.io/reference/api/bindings_api/) to learn more about Dapr bindings components. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | |
| 104 | +| pubsub.* | Indicates that the input is the Dapr pubsub component. Refer to [Pub/sub API reference](https://docs.dapr.io/reference/api/pubsub_api/) to learn more about Dapr bindings components. <br />:heavy_exclamation_mark:Note that when using pubsub as input, the name of pubsub's topic should be assigned to the input's uri. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | |
| 105 | + |
| 106 | +<div align="right"> |
| 107 | + <b><a href="#context">↥ back to Context</a></b> |
| 108 | +</div> |
| 109 | + |
| 110 | +### Outputs |
| 111 | + |
| 112 | +Examples: |
| 113 | + |
| 114 | +```json |
| 115 | +{ |
| 116 | + "my-output": { |
| 117 | + "uri": "my-uri", |
| 118 | + "componentName": "my-component", |
| 119 | + "componentType": "bindings.kafka", |
| 120 | + "operation": "post" |
| 121 | + } |
| 122 | +} |
| 123 | +``` |
| 124 | + |
| 125 | +Specification: |
| 126 | + |
| 127 | +#### Output |
| 128 | + |
| 129 | +| Key | Type | Description | Scope | example | |
| 130 | +| ------------- | ------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------ | |
| 131 | +| name(key) | string | Output name. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | "demo-kafka", "cron-job" | |
| 132 | +| uri | string | Output serving listening path. This indicates the destination of the output data.<br />Bindings: same as the component's name, can be omitted.<br />Pubsub: represent the topic's name, cannot be omitted. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | "echo" | |
| 133 | +| componentType | string | Output type. When using Async as runtime, you need to set the `type` (refer to [Output Type](#output-type)) parameter. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | "bindings.kafka" | |
| 134 | +| componentName | string | The component's name. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | "componentA" | |
| 135 | +| metadata | map | The metadata to be passed to dapr for use. Usage can be found in dapr's documentation. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | | |
| 136 | +| operation | string | The operation's name. Usage can be found in dapr's documentation. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | "post", "create" | |
| 137 | + |
| 138 | +##### Output Type |
| 139 | + |
| 140 | +| Value | Description | Scope | |
| 141 | +| ---------- | ------------------------------------------------------------ | ------------------------------------------------------------ | |
| 142 | +| bindings.* | Indicates that the output is the Dapr bindings component. Refer to [Bindings API reference](https://docs.dapr.io/reference/api/bindings_api/) to learn more about Dapr bindings components. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | |
| 143 | +| pubsub.* | Indicates that the output is the Dapr pubsub component. Refer to [Pub/sub API reference](https://docs.dapr.io/reference/api/pubsub_api/) to learn more about Dapr bindings components. <br />:heavy_exclamation_mark:Note that when using pubsub as output, the name of pubsub's topic should be assigned to the output's uri. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | |
| 144 | + |
| 145 | +<div align="right"> |
| 146 | + <b><a href="#context">↥ back to Context</a></b> |
| 147 | +</div> |
| 148 | + |
| 149 | +### Runtime |
| 150 | + |
| 151 | +We currently support `Knative` and `Async` serving runtime. |
| 152 | + |
| 153 | +| Value | Description | Scope | |
| 154 | +| ------- | --------------------------------------------------------- | ------------------------------------------------------------ | |
| 155 | +| Knative | Serving function with Knative runtime (based on Knative). | [ff-go](https://github.com/OpenFunction/functions-framework-go) | |
| 156 | +| Async | Serving function with Async runtime (based on KEDA+Dapr). | [ff-go](https://github.com/OpenFunction/functions-framework-go) | |
| 157 | + |
| 158 | +<div align="right"> |
| 159 | + <b><a href="#context">↥ back to Context</a></b> |
| 160 | +</div> |
| 161 | +### Out |
| 162 | + |
| 163 | +| Key | Type | Description | Scope | example | |
| 164 | +| -------- | ------ | ----------------------------------------------- | ------------------------------------------------------------ | ---------------- | |
| 165 | +| code | int | Return code of the function. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | 200, 500 | |
| 166 | +| data | string | The data returned by the function. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | "some data" | |
| 167 | +| error | string | The error information returned by the function. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | "some error" | |
| 168 | +| metadata | map | The metadata returned by the function. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | {"key": "value"} | |
| 169 | + |
| 170 | +<div align="right"> |
| 171 | + <b><a href="#context">↥ back to Context</a></b> |
| 172 | +</div> |
| 173 | + |
| 174 | +### PluginsTracing |
| 175 | + |
| 176 | +| Key | Type | Description | Scope | example | |
| 177 | +| -------- | ---- | ------------------------------------------------------------ | ------------------------------------------------------------ | --------------------------------- | |
| 178 | +| enable | bool | Whether to enable tracing capability. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | true, false | |
| 179 | +| provider | map | Configuration of tracing capability provider, see [TracingProvider](#tracingprovider) | [ff-go](https://github.com/OpenFunction/functions-framework-go) | | |
| 180 | +| tags | map | Tags for tracing. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | {"func": "function-with-tracing"} | |
| 181 | +| baggage | map | Baggage for tracing. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | {"key": "sw8-correlation"} | |
| 182 | + |
| 183 | +<div align="right"> |
| 184 | + <b><a href="#context">↥ back to Context</a></b> |
| 185 | +</div> |
| 186 | + |
| 187 | +### TracingProvider |
| 188 | + |
| 189 | +| Key | Type | Description | Scope | example | |
| 190 | +| --------- | ------ | ------------------------------------------------------------ | ------------------------------------------------------------ | --------------- | |
| 191 | +| name | string | The name of the provider (if the tracing capability is enabled, this name will be automatically inserted into the list of plugin names) | [ff-go](https://github.com/OpenFunction/functions-framework-go) | "skywalking" | |
| 192 | +| oapServer | string | The oap server address. | [ff-go](https://github.com/OpenFunction/functions-framework-go) | "localhost:xxx" | |
| 193 | + |
| 194 | +<div align="right"> |
| 195 | + <b><a href="#context">↥ back to Context</a></b> |
| 196 | +</div> |
| 197 | + |
0 commit comments