microsoft / azure-container-apps

Roadmap and issues for Azure Container Apps
MIT License
362 stars 29 forks source link

Container does not scale down to 0 with ASB queues #1039

Closed Mithgroth closed 9 months ago

Mithgroth commented 9 months ago

Please provide us with the following information:

This issue is a: (mark with an x)

Issue description

I have a .NET 8.0 console application in a container, which is deployed to ACR and run on ContainerApps. Application is built on MassTransit, uses Azure Service Bus queues. It works great, but I always have one active replica running even there are no requests at all.

I tried it both ways with having my scaling rules with queue and connection, no change at all.

Unlike #952, I have no key-vault references, my secrets are Container Apps Secrets.

Here's the JSON of my resource:

{
    "id": "<redacted>",
    "name": "<redacted>",
    "type": "Microsoft.App/containerApps",
    "location": "West Europe",
    "tags": {
        "created_by": "cdktf",
        "environment": "Staging"
    },
    "systemData": {
        "createdBy": "1a6afc85-d01a-45ad-8de2-4aa26f74828d",
        "createdByType": "Application",
        "createdAt": "2023-12-12T10:39:02.4044595",
        "lastModifiedBy": "1a6afc85-d01a-45ad-8de2-4aa26f74828d",
        "lastModifiedByType": "Application",
        "lastModifiedAt": "2023-12-19T07:47:57.7108815"
    },
    "properties": {
        "provisioningState": "Succeeded",
        "runningStatus": "Running",
        "managedEnvironmentId": "<redacted>",
        "environmentId": "<redacted>",
        "workloadProfileName": null,
        "outboundIpAddresses": [
            "<redacted>"
        ],
        "latestRevisionName": "<redacted>--8psntt0",
        "latestReadyRevisionName": "<redacted>--8psntt0",
        "latestRevisionFqdn": "",
        "customDomainVerificationId": "<redacted>",
        "configuration": {
            "secrets": [
                {
                    "name": "container-registry-admin-password"
                },
                {
                    "name": "servicebus"
                }
            ],
            "activeRevisionsMode": "Single",
            "ingress": null,
            "registries": [
                {
                    "server": "<redacted>",
                    "username": "<redacted>",
                    "passwordSecretRef": "container-registry-admin-password",
                    "identity": ""
                }
            ],
            "dapr": null,
            "maxInactiveRevisions": null,
            "service": null
        },
        "template": {
            "revisionSuffix": "",
            "terminationGracePeriodSeconds": null,
            "containers": [
                {
                    "image": "<redacted>",
                    "name": "processor",
                    "args": [
                        "dotnet",
                        "Processor.dll"
                    ],
                    "env": [
                        {
                            "name": "DOTNET_ENVIRONMENT",
                            "value": "Staging"
                        }
                    ],
                    "resources": {
                        "cpu": 1,
                        "memory": "2Gi",
                        "ephemeralStorage": "4Gi"
                    },
                    "probes": []
                }
            ],
            "initContainers": null,
            "scale": {
                "minReplicas": null,
                "maxReplicas": 5,
                "rules": [
                    {
                        "name": "order-accepted",
                        "azureQueue": {
                            "queueName": "order-accepted",
                            "queueLength": 10,
                            "auth": [
                                {
                                    "secretRef": "servicebus",
                                    "triggerParameter": "connection"
                                }
                            ]
                        }
                    },
                    {
                        "name": "order-fulfilled",
                        "azureQueue": {
                            "queueName": "order-fulfilled",
                            "queueLength": 10,
                            "auth": [
                                {
                                    "secretRef": "servicebus",
                                    "triggerParameter": "connection"
                                }
                            ]
                        }
                    },
                    {
                        "name": "order-rejected",
                        "azureQueue": {
                            "queueName": "order-rejected",
                            "queueLength": 10,
                            "auth": [
                                {
                                    "secretRef": "servicebus",
                                    "triggerParameter": "connection"
                                }
                            ]
                        }
                    },
                    {
                        "name": "order-state",
                        "azureQueue": {
                            "queueName": "order-state",
                            "queueLength": 10,
                            "auth": [
                                {
                                    "secretRef": "servicebus",
                                    "triggerParameter": "connection"
                                }
                            ]
                        }
                    },
                    {
                        "name": "process-order",
                        "azureQueue": {
                            "queueName": "process-order",
                            "queueLength": 5,
                            "auth": [
                                {
                                    "secretRef": "servicebus",
                                    "triggerParameter": "connection"
                                }
                            ]
                        }
                    },
                    {
                        "name": "submit-order",
                        "azureQueue": {
                            "queueName": "submit-order",
                            "queueLength": 10,
                            "auth": [
                                {
                                    "secretRef": "servicebus",
                                    "triggerParameter": "connection"
                                }
                            ]
                        }
                    },
                    {
                        "name": "validation",
                        "azureQueue": {
                            "queueName": "validation",
                            "queueLength": 10,
                            "auth": [
                                {
                                    "secretRef": "servicebus",
                                    "triggerParameter": "connection"
                                }
                            ]
                        }
                    }
                ]
            },
            "volumes": [],
            "serviceBinds": null
        },
        "eventStreamEndpoint": "<redacted>"
    },
    "identity": {
        "type": "None"
    }
}

Steps to reproduce

  1. ..
  2. ..

Expected behavior [What you expected to happen.] Container replicas scaling down to 0 after cool down period

Actual behavior [What actually happened.] 1 container is always up

Screenshots
If applicable, add screenshots to help explain your problem. 7+ minutes in, container is still alive. image

Additional context

Ex. Did this issue occur in the CLI or the Portal? Portal

anthonychu commented 9 months ago

It looks like you're using the azureQueue scaler, which is for Azure Storage queues, not Azure Service Bus. See this doc for information on how to configure an ASB rule: https://learn.microsoft.com/en-us/azure/container-apps/scale-app?pivots=azure-resource-manager#example-2

Mithgroth commented 9 months ago

Thanks, it works as intended now.