This is an automated email from the ASF dual-hosted git repository.

squakez pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/main by this push:
     new 75c8da004 feat(keda): complete Azure Service Bus auto-scaler (#6992)
75c8da004 is described below

commit 75c8da0049a0b7dc6248ddb82264ff72ae676a2f
Author: Sanjeev Kumar <[email protected]>
AuthorDate: Fri Nov 27 13:02:32 2026 +0530

    feat(keda): complete Azure Service Bus auto-scaler (#6992)
    
    * feat(keda): add Azure Service Bus scaler mapping
    
    * test(keda): cover Azure Service Bus scaler mapping
    
    * docs(keda): document Azure Service Bus auto-discovery
    
    * test(keda): add Azure Service Bus emulator
    
    * test(keda): configure emulator TLS management proxy
    
    * test(keda): start Azure Service Bus emulator in KEDA workflow
    
    * test(keda): add Azure Service Bus queue autoscale fixture
    
    * test(keda): add Azure Service Bus queue producer fixture
    
    * test(keda): add Azure Service Bus topic autoscale fixture
    
    * test(keda): add Azure Service Bus topic producer fixture
    
    * test(keda): exercise Azure Service Bus queue and topic autoscaling
    
    * test(keda): import replica pointer matcher
    
    * test(keda): align emulator database and entity config with Microsoft setup
    
    * test(keda): mark emulator CA as a trusted signing authority
    
    * test(keda): assert component credentials stay out of trigger metadata
    
    * docs(keda): clarify Azure Service Bus authentication
    
    * test(keda): expose scaler connection through target pod template
    
    * test(keda): expose scaler connection through target pod template
    
    * test(keda): document scaler environment source
    
    * test(keda): document scaler environment source
    
    * docs(keda): clarify connectionFromEnv source
    
    * test(keda): keep Service Bus backlog visible to scaler
    
    * test(keda): keep Service Bus backlog visible to scaler
    
    * test(keda): use supported SQL Server image for Service Bus emulator
    
    * test(keda): format Azure Service Bus namespace test
    
    * fix(keda): use valid management port name
    
    * refactor(keda): drop Azure Service Bus emulator e2e
---
 docs/modules/traits/pages/keda.adoc             |   1 +
 pkg/trait/keda/scalers/azure_servicebus.go      |  82 +++++++++
 pkg/trait/keda/scalers/azure_servicebus_test.go | 213 ++++++++++++++++++++++++
 3 files changed, 296 insertions(+)

diff --git a/docs/modules/traits/pages/keda.adoc 
b/docs/modules/traits/pages/keda.adoc
index 6ac7f70a2..2195816cc 100644
--- a/docs/modules/traits/pages/keda.adoc
+++ b/docs/modules/traits/pages/keda.adoc
@@ -80,6 +80,7 @@ Automatic discovery currently supports the following Camel 
components:
 * `aws2-sqs`: creates an AWS SQS Queue trigger. `queueURL` comes from the 
`queueUrl` endpoint parameter, or is built from a queue ARN, or from the queue 
name with the `region` and `queueOwnerAWSAccountId` parameters. Otherwise the 
plain queue name is used, which KEDA accepts when it is unambiguous. 
`awsRegion` comes from `region` or the ARN, and `awsEndpoint` from 
`uriEndpointOverride` when `overrideEndpoint=true`. Set other metadata, such as 
`queueLength`, with `keda.autoMetadata`, and  [...]
 * `pulsar`: creates an Apache Pulsar trigger from the topic in the endpoint 
URI and the `subscriptionName` option (Camel's default `subs` when it is not 
set). When the service URL (`serviceUrl` option or 
`camel.component.pulsar.service-url` property) uses the `pulsar://` scheme, 
`adminURL` is set to `http://<host>:8080`; for TLS or a custom admin port, set 
it with `keda.autoMetadata`. See the 
https://keda.sh/docs/latest/scalers/pulsar/[KEDA Apache Pulsar scaler] 
documentation for the ava [...]
 * `spring-rabbitmq`: creates a RabbitMQ trigger whose `queueName` is the 
`queues` value of the endpoint URI, when it names a single queue. The broker 
address is not part of the URI: a `host` endpoint parameter, when present, is 
used as the trigger `host` as is; otherwise set `host`, together with `mode` 
and `value`, with `keda.autoMetadata`. See the 
https://keda.sh/docs/latest/scalers/rabbitmq-queue/[KEDA RabbitMQ Queue scaler] 
documentation for the available trigger metadata.
+* `azure-servicebus`: creates an Azure Service Bus trigger from the queue or 
topic name in the endpoint URI. `serviceBusType=topic` maps the path to 
`topicName` and requires `subscriptionName`; otherwise the path maps to 
`queueName`. The `serviceBusType`, `subscriptionName`, and 
`fullyQualifiedNamespace` options fall back to the corresponding 
`camel.component.azure-servicebus.*` properties. A public-cloud fully qualified 
namespace is reduced to the KEDA `namespace` metadata. For other Az [...]
 * `nats`: creates a NATS JetStream trigger for a JetStream consumer with a 
durable name (`jetstreamEnabled=true`, `jetstreamName` and `durableName`, as 
endpoint options or `camel.component.nats.*` properties). The stream is 
`jetstreamName`, the consumer is `<durableName>-durable` (the name Camel gives 
the durable consumer) and the account is `$G`, the default account of a NATS 
server without configured accounts. When `servers` is set, 
`natsServerMonitoringEndpoint` is set to `<host>:8222 [...]
 
 Unsupported Camel components do not produce an automatically discovered 
trigger. You can still configure their KEDA triggers explicitly with 
`keda.triggers`.
diff --git a/pkg/trait/keda/scalers/azure_servicebus.go 
b/pkg/trait/keda/scalers/azure_servicebus.go
new file mode 100644
index 000000000..9529255d3
--- /dev/null
+++ b/pkg/trait/keda/scalers/azure_servicebus.go
@@ -0,0 +1,82 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package scalers
+
+import (
+       "strings"
+
+       keda "github.com/apache/camel-k/v2/pkg/trait/keda"
+)
+
+// azureServiceBusPublicSuffix is the host suffix of Service Bus namespaces in 
the Azure public cloud.
+const azureServiceBusPublicSuffix = ".servicebus.windows.net"
+
+// AzureServiceBusScaler maps Camel Azure Service Bus consumer endpoints to 
the KEDA azure-servicebus scaler.
+type AzureServiceBusScaler struct{}
+
+func init() {
+       keda.Register(&AzureServiceBusScaler{})
+}
+
+func (a *AzureServiceBusScaler) Component() string {
+       return "azure-servicebus"
+}
+
+// Map takes the queue or topic name from the URI path. The Camel 
serviceBusType option (queue by
+// default) decides whether it becomes the KEDA queueName or topicName; a 
topic also requires a
+// subscriptionName. Component-level properties are used when an endpoint does 
not override them.
+// Connection strings are deliberately not copied into trigger metadata.
+func (a *AzureServiceBusScaler) Map(pathValue string, params 
map[string]string, props map[string]string) (string, map[string]string) {
+       if pathValue == "" {
+               return "", nil
+       }
+
+       metadata := make(map[string]string)
+       serviceBusType := azureServiceBusOption(params, props, 
"serviceBusType", "service-bus-type")
+       if strings.EqualFold(serviceBusType, "topic") {
+               subscriptionName := azureServiceBusOption(params, props, 
"subscriptionName", "subscription-name")
+               if subscriptionName == "" {
+                       // KEDA requires both topicName and subscriptionName 
for this scaler.
+                       return "", nil
+               }
+
+               metadata["topicName"] = pathValue
+               metadata["subscriptionName"] = subscriptionName
+       } else {
+               metadata["queueName"] = pathValue
+       }
+
+       // KEDA expects the namespace name, e.g. "my-namespace" for 
my-namespace.servicebus.windows.net.
+       // Other Azure clouds also need cloud/endpointSuffix, so they are left 
to keda.autoMetadata.
+       fqns := strings.ToLower(azureServiceBusOption(params, props, 
"fullyQualifiedNamespace", "fully-qualified-namespace"))
+       if name, ok := strings.CutSuffix(fqns, azureServiceBusPublicSuffix); ok 
&& name != "" && !strings.Contains(name, ".") {
+               metadata["namespace"] = name
+       }
+
+       return "azure-servicebus", metadata
+}
+
+// azureServiceBusOption returns an endpoint parameter, falling back to the 
component-level
+// property (camel.component.azure-servicebus.<property>) when the endpoint 
does not set it.
+func azureServiceBusOption(params map[string]string, props map[string]string, 
param string, property string) string {
+       if value := params[param]; value != "" {
+               return value
+       }
+
+       return props["camel.component.azure-servicebus."+property]
+}
diff --git a/pkg/trait/keda/scalers/azure_servicebus_test.go 
b/pkg/trait/keda/scalers/azure_servicebus_test.go
new file mode 100644
index 000000000..f8c41e649
--- /dev/null
+++ b/pkg/trait/keda/scalers/azure_servicebus_test.go
@@ -0,0 +1,213 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package scalers
+
+import (
+       "testing"
+
+       "github.com/stretchr/testify/assert"
+       "github.com/stretchr/testify/require"
+
+       keda "github.com/apache/camel-k/v2/pkg/trait/keda"
+)
+
+func TestAzureServiceBusScalerRegistered(t *testing.T) {
+       mapper, found := keda.GetMapper("azure-servicebus")
+       require.True(t, found, "azure-servicebus scaler should be registered")
+       assert.Equal(t, "azure-servicebus", mapper.Component())
+}
+
+func TestAzureServiceBusScalerMap(t *testing.T) {
+       scaler := &AzureServiceBusScaler{}
+
+       tests := []struct {
+               name         string
+               pathValue    string
+               params       map[string]string
+               props        map[string]string
+               expectedType string
+               expectedMeta map[string]string
+       }{
+               {
+                       name:         "queue by default",
+                       pathValue:    "orders",
+                       params:       map[string]string{},
+                       expectedType: "azure-servicebus",
+                       expectedMeta: map[string]string{"queueName": "orders"},
+               },
+               {
+                       name:         "explicit queue type",
+                       pathValue:    "orders",
+                       params:       map[string]string{"serviceBusType": 
"queue"},
+                       expectedType: "azure-servicebus",
+                       expectedMeta: map[string]string{"queueName": "orders"},
+               },
+               {
+                       name:         "topic with subscription",
+                       pathValue:    "events",
+                       params:       map[string]string{"serviceBusType": 
"topic", "subscriptionName": "audit"},
+                       expectedType: "azure-servicebus",
+                       expectedMeta: map[string]string{"topicName": "events", 
"subscriptionName": "audit"},
+               },
+               {
+                       name:         "topic type is case insensitive",
+                       pathValue:    "events",
+                       params:       map[string]string{"serviceBusType": 
"Topic", "subscriptionName": "audit"},
+                       expectedType: "azure-servicebus",
+                       expectedMeta: map[string]string{"topicName": "events", 
"subscriptionName": "audit"},
+               },
+               {
+                       name:         "topic without subscription is not 
discoverable",
+                       pathValue:    "events",
+                       params:       map[string]string{"serviceBusType": 
"topic"},
+                       expectedType: "",
+                       expectedMeta: nil,
+               },
+               {
+                       name:         "empty endpoint path is not discoverable",
+                       pathValue:    "",
+                       params:       map[string]string{},
+                       expectedType: "",
+                       expectedMeta: nil,
+               },
+               {
+                       name:         "public cloud namespace",
+                       pathValue:    "orders",
+                       params:       
map[string]string{"fullyQualifiedNamespace": 
"My-Namespace.servicebus.windows.net"},
+                       expectedType: "azure-servicebus",
+                       expectedMeta: map[string]string{
+                               "queueName": "orders",
+                               "namespace": "my-namespace",
+                       },
+               },
+               {
+                       name:         "other cloud namespace is left to 
autoMetadata",
+                       pathValue:    "orders",
+                       params:       
map[string]string{"fullyQualifiedNamespace": 
"my-namespace.servicebus.usgovcloudapi.net"},
+                       expectedType: "azure-servicebus",
+                       expectedMeta: map[string]string{"queueName": "orders"},
+               },
+               {
+                       name:         "connection string is not copied",
+                       pathValue:    "orders",
+                       params:       map[string]string{"connectionString": 
"Endpoint=sb://ns.servicebus.windows.net/;SharedAccessKey=secret"},
+                       expectedType: "azure-servicebus",
+                       expectedMeta: map[string]string{"queueName": "orders"},
+               },
+               {
+                       name:      "component connection string is not copied",
+                       pathValue: "orders",
+                       params:    map[string]string{},
+                       props: map[string]string{
+                               
"camel.component.azure-servicebus.connection-string": 
"Endpoint=sb://ns.servicebus.windows.net/;SharedAccessKey=secret",
+                       },
+                       expectedType: "azure-servicebus",
+                       expectedMeta: map[string]string{"queueName": "orders"},
+               },
+               {
+                       name:      "component properties",
+                       pathValue: "events",
+                       params:    map[string]string{},
+                       props: map[string]string{
+                               
"camel.component.azure-servicebus.service-bus-type":          "topic",
+                               
"camel.component.azure-servicebus.subscription-name":         "audit",
+                               
"camel.component.azure-servicebus.fully-qualified-namespace": 
"my-namespace.servicebus.windows.net",
+                       },
+                       expectedType: "azure-servicebus",
+                       expectedMeta: map[string]string{
+                               "topicName":        "events",
+                               "subscriptionName": "audit",
+                               "namespace":        "my-namespace",
+                       },
+               },
+               {
+                       name:      "endpoint parameters win over component 
properties",
+                       pathValue: "orders",
+                       params:    map[string]string{"serviceBusType": "queue"},
+                       props: map[string]string{
+                               
"camel.component.azure-servicebus.service-bus-type":          "topic",
+                               
"camel.component.azure-servicebus.subscription-name":         "audit",
+                       },
+                       expectedType: "azure-servicebus",
+                       expectedMeta: map[string]string{"queueName": "orders"},
+               },
+               {
+                       name:      "component topic without subscription is not 
discoverable",
+                       pathValue: "events",
+                       params:    map[string]string{},
+                       props: map[string]string{
+                               
"camel.component.azure-servicebus.service-bus-type": "topic",
+                       },
+                       expectedType: "",
+                       expectedMeta: nil,
+               },
+       }
+
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       kedaType, metadata := scaler.Map(tt.pathValue, 
tt.params, tt.props)
+                       assert.Equal(t, tt.expectedType, kedaType)
+                       assert.Equal(t, tt.expectedMeta, metadata)
+               })
+       }
+}
+
+func TestMapToKedaTriggerAzureServiceBus(t *testing.T) {
+       tests := []struct {
+               name         string
+               uri          string
+               props        map[string]string
+               expectedMeta map[string]string
+       }{
+               {
+                       name:         "queue",
+                       uri:          
"azure-servicebus:orders?serviceBusType=queue",
+                       expectedMeta: map[string]string{"queueName": "orders"},
+               },
+               {
+                       name: "topic from component properties",
+                       uri:  "azure-servicebus:events",
+                       props: map[string]string{
+                               
"camel.component.azure-servicebus.service-bus-type":          "topic",
+                               
"camel.component.azure-servicebus.subscription-name":         "audit",
+                               
"camel.component.azure-servicebus.fully-qualified-namespace": 
"my-namespace.servicebus.windows.net",
+                       },
+                       expectedMeta: map[string]string{
+                               "topicName":        "events",
+                               "subscriptionName": "audit",
+                               "namespace":        "my-namespace",
+                       },
+               },
+       }
+
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       trigger, err := keda.MapToKedaTrigger(tt.uri, tt.props)
+                       require.NoError(t, err)
+                       require.NotNil(t, trigger)
+                       assert.Equal(t, "azure-servicebus", trigger.Type)
+                       assert.Equal(t, tt.expectedMeta, trigger.Metadata)
+               })
+       }
+}
+
+func TestMapToKedaTriggerAzureServiceBusSkipsIncompleteTopic(t *testing.T) {
+       trigger, err := 
keda.MapToKedaTrigger("azure-servicebus:events?serviceBusType=topic", nil)
+       require.NoError(t, err)
+       assert.Nil(t, trigger)
+}

Reply via email to