Skip to content

Azure Storage Queue scaler is reporting wrong number of messages in queue #2385

@jungopro

Description

@jungopro

Report

Hello
I think the azure_queue monitor is not reading the number of messages in the queue as it should
Looking at the code here I think that when Keda calculates the "visible messages" as 0 it returns 0, even though the actual number of messages in the queue is much higher

For example:
We see "showing 0 of 128503 messages in queue" in the portal, and Keda is also reporting 0 for the metric (even though the actual count is 128k) - see the right side in the screenshot
When we work with the c# SDK for azure storage we're getting the right numbers - see left side in the screen shot (csharp code below):

image

public async Task Run()
        {
            m_tracer.TraceInformation($"{nameof(StorageAccountMetricsLogger)} - Starting work.");
            CloudStorageAccount storageAccount = m_aadStorageProvider.GetStorageAccount(m_queueStorageName);
            var queueClient = storageAccount.CreateCloudQueueClient();
            var queueNames = queueClient.ListQueues();
            foreach (var cloudQueue in queueNames)
            {
                var dimension = new Dimensions();
                dimension.SetDimension("Name", cloudQueue.Name);
                var instrumentor = new Instrumentor(dimension);
                await cloudQueue.FetchAttributesAsync();
                if (!cloudQueue.ApproximateMessageCount.HasValue)
                {
                    m_tracer.TraceWarning(0, $"{nameof(StorageAccountMetricsLogger)} - Failed to retrieve message count for storage queue {cloudQueue.Name}.");
                    continue;
                }
                instrumentor.LogMetric(s_monitoringStorageQueueActiveMessageCountMetricName, cloudQueue.ApproximateMessageCount.Value);
                m_tracer.TraceInformation($"{nameof(StorageAccountMetricsLogger)} - Metrics for storage queue name \"{cloudQueue.Name}\" messages = {cloudQueue.ApproximateMessageCount}");
            }
            m_tracer.TraceInformation($"{nameof(StorageAccountMetricsLogger)} - Done.");
        }

Expected Behavior

keda should report the actual # of messages in queue

Actual Behavior

keda is reporting 0 messages in queue

Steps to Reproduce the Problem

  1. add messages to azure queue
  2. query the queue with keda

Logs from KEDA operator

No response

KEDA Version

2.4.0

Kubernetes Version

1.19

Platform

Other

Scaler Details

Azure storage queue

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstaleAll issues that are marked as stale due to inactivity

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions