serverless-azure-functions icon indicating copy to clipboard operation
serverless-azure-functions copied to clipboard

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

Open Rapol opened this issue 5 years ago • 8 comments

This is a Bug Report

Description

  • What went wrong?

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.

  • What did you expect should have happened?

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

  • What was the config you used?
processEventHubLogs:
    handler: src/eventHubHandler
    events:
      - eventHub:
        x-azure-settings:
          name: fileMessages
          path: EVENT_HUB_PATH
          connection: EVENT_HUB_CONNECTION_STRING
          cardinality: many

Additional Data

  • Serverless Framework Version you're using: 1.67.0
  • Serverless CLI Version you're using: 2.3.0
  • Serverless Azure Plugin Version you're using: 2.0.9
  • Operating System: mac os

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"
                }

Rapol avatar Jun 27 '20 20:06 Rapol

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

tbarlow12 avatar Jun 28 '20 04:06 tbarlow12

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.

Rapol avatar Jun 29 '20 13:06 Rapol

Hello,

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

bdatdo0601 avatar Sep 18 '20 01:09 bdatdo0601

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"
                },

Rapol avatar Feb 10 '21 18:02 Rapol

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

ShanonJackson avatar Jun 10 '21 04:06 ShanonJackson

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

Rapol avatar Jun 10 '21 18:06 Rapol

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.

jovanamarko avatar Jul 06 '21 16:07 jovanamarko

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.

Rapol avatar Jul 19 '21 14:07 Rapol