serverless / serverless-azure-functions

Serverless Azure Functions Plugin – Add Azure Functions support to the Serverless Framework
MIT License
266 stars 161 forks source link

Eventhub trigger cardinality not being set in 2.x.x #478

Open Rapol opened 4 years ago

Rapol commented 4 years ago

This is a Bug Report

Description

Deploying an event hub trigger doesn't set the cardinality in 2.0.9. This worked at least on 1.0.2-16 which we were using before upgrading to 2.x.x.

sls deploy should generate the correct host.json for event hub trigger and include the cardinality

processEventHubLogs:
    handler: src/eventHubHandler
    events:
      - eventHub:
        x-azure-settings:
          name: fileMessages
          path: EVENT_HUB_PATH
          connection: EVENT_HUB_CONNECTION_STRING
          cardinality: many

Additional Data

We found that in the default bindings (bindings.json), the binding of type eventhubTrigger cardinality setting was removed in 2.0.0. This setting needs to be added back

{
                    "name": "cardinality",
                    "value": "enum",
                    "required": false,
                    "defaultValue": "many",
                    "enum": [
                        {
                            "value": "one",
                            "display": "One"
                        },
                        {
                            "value": "many",
                            "display": "Many"
                        }
                    ],
                    "label": "$eventHubTrigger_cardinality_label",
                    "help": "$eventHubTrigger_cardinality_help"
                }
tbarlow12 commented 4 years ago

Hey @Rapol, I'll see if I can look into this sometime this week. Could you try running without x-azure-settings?


processEventHubLogs:
    handler: src/eventHubHandler
    events:
      - eventHub:
         name: fileMessages
         path: EVENT_HUB_PATH
         connection: EVENT_HUB_CONNECTION_STRING
         cardinality: many
Rapol commented 4 years ago

We just tried it again with and without x-azure-settings and it is adding the cardinality to the host.json in both cases. Not able to reproduce and we tried the same serverless config without any modifications. Closing this, thanks for the quick response.

bdatdo0601 commented 4 years ago

Hello,

I got into the same issue with version 2.0.13. I was unable to add cardinality into function.json

Rapol commented 3 years ago

We just migrated to 2.1.0 to be able to deploy node12 and v3 function runtime and stumbled again with this issue. We have our own fork and by adding the following to bindings.json (https://github.com/serverless/serverless-azure-functions/blob/master/src/shared/bindings.json#L60) the plugin set the cardinality correctly in the function.json

{
            "type": "eventHubTrigger",
            "displayName": "$eventHubTrigger_displayName",
            "direction": "trigger",
            "enabledInTryMode": false,
            "documentation": "$content=Documentation\\eventHubTrigger.md",
            "settings": [
               /**** Add cardinality ****/
                {
                    "name": "cardinality",
                    "value": "enum",
                    "required": false,
                    "defaultValue": "many",
                    "enum": [
                        {
                            "value": "one",
                            "display": "One"
                        },
                        {
                            "value": "many",
                            "display": "Many"
                        }
                    ],
                    "label": "$eventHubTrigger_cardinality_label",
                    "help": "$eventHubTrigger_cardinality_help"
                },
ShanonJackson commented 3 years ago

Whats the fix here guys? cardinality seems to be completely ignored in the servleress.yml; And although Azure suggests it should default to "many" its only receiving a single event (not an array).

TL;DR We set cardinality: many in Azure there's no config for cardinality after deployment it just disappears

Rapol commented 3 years ago

We fixed it by adding the following item to the eventHubTrigger binding settings array

                {
                    "name": "cardinality",
                    "value": "enum",
                    "required": false,
                    "defaultValue": "many",
                    "enum": [
                        {
                            "value": "one",
                            "display": "One"
                        },
                        {
                            "value": "many",
                            "display": "Many"
                        }
                    ],
                    "label": "$eventHubTrigger_cardinality_label",
                    "help": "$eventHubTrigger_cardinality_help"
                },

Add the previous object to this array https://github.com/serverless/serverless-azure-functions/blob/master/src/shared/bindings.json#L65

jovanamarko commented 3 years ago

We have solved this with adding the object in bindings.json file as described by @Rapol, but instead of forking I created a patch using patch-package. However, this is still an issue that should be considered resolving in next version of the module, even more so because it is a simple fix in bindings.json.

Rapol commented 3 years ago

Unfortunately, azure seems to have abandoned this project. The community might need to fork it to fix bugs and add new features.

Function app has been adding features to hook them up with apim, cdn, authorization, etc somewhat easily so my guess is they want to move to ARM/terraform and not maintain sls framework.