Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Support for FromEnv properties for Connections #76

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,32 @@ The specification below describes the `trigger` metadata in `ScaledObject` resou
triggers:
- type: external
metadata:
scalerAddress: external-scaler-azure-cosmos-db.keda:4050 # Mandatory. Address of the external scaler service.
connection: <connection> # Mandatory. Connection string of Cosmos DB account with monitored container.
databaseId: <database-id> # Mandatory. ID of Cosmos DB database containing monitored container.
containerId: <container-id> # Mandatory. ID of monitored container.
leaseConnection: <lease-connection> # Mandatory. Connection string of Cosmos DB account with lease container.
leaseDatabaseId: <lease-database-id> # Mandatory. ID of Cosmos DB database containing lease container.
leaseContainerId: <lease-container-id> # Mandatory. ID of lease container.
processorName: <processor-name> # Mandatory. Name of change-feed processor used by listener application.
scalerAddress: external-scaler-azure-cosmos-db.keda:4050 # Mandatory. Address of the external scaler service.
connectionFromEnv: <env-variable-for-connection> # Mandatory. Environment variable for the connection string of Cosmos DB account with monitored container.
databaseId: <database-id> # Mandatory. ID of Cosmos DB database containing monitored container.
containerId: <container-id> # Mandatory. ID of monitored container.
leaseConnectionFromEnv: <env-variable-for-lease-connection> # Mandatory. Environment variable for the connection string of Cosmos DB account with lease container.
leaseDatabaseId: <lease-database-id> # Mandatory. ID of Cosmos DB database containing lease container.
leaseContainerId: <lease-container-id> # Mandatory. ID of lease container.
processorName: <processor-name> # Mandatory. Name of change-feed processor used by listener application.
```

### Parameter List

- **`scalerAddress`** - Address of the external scaler service. This would be in format `<scaler-name>.<scaler-namespace>:<port>`. If you installed Azure Cosmos DB external scaler Helm chart in `keda` namespace and did not specify custom values, the metadata value would be `external-scaler-azure-cosmos-db.keda:4050`.

- **`connection`** - Connection string of the Cosmos DB account that contains the monitored container.
- **`connectionFromEnv`** - Name of the environment variable on the scale target to read the connection string of the Cosmos DB account that contains the monitored container.

- **`databaseId`** - ID of Cosmos DB database that contains the monitored container.

- **`containerId`** - ID of the monitored container.

- **`leaseConnection`** - Connection string of the Cosmos DB account that contains the lease container. This can be same or different from the value of `connection` metadata.
- **`leaseConnectionFromEnv`** - Name of the environment variable on the scale target to read the connection string of the Cosmos DB account that contains the lease container. This can be same or different from the value of `connection` metadata.

- **`leaseDatabaseId`** - ID of Cosmos DB database that contains the lease container. This can be same or different from the value of `databaseId` metadata.

- **`leaseContainerId`** - ID of the lease container containing the change feeds.

- **`processorName`** - Name of change-feed processor used by listener application. For more information on this, you can refer to [Implementing the change feed processor](https://docs.microsoft.com/azure/cosmos-db/sql/change-feed-processor#implementing-the-change-feed-processor) section.

> **Note** Ideally, we would have created `TriggerAuthentication` resource that would have prevented us from adding the connection strings in plain text in the `ScaledObject` trigger metadata. However, this is not possible since at the moment, the triggers of `external` type do not support referencing a `TriggerAuthentication` resource ([link](https://keda.sh/docs/scalers/external/#authentication-parameters)).
> **Note** Ideally, we would have created `TriggerAuthentication` resource that would have prevented us from adding the connection strings in plain text in the `ScaledObject` trigger metadata. However, this is not possible since at the moment, the triggers of `external` type do not support referencing a `TriggerAuthentication` resource ([link](https://keda.sh/docs/scalers/external/#authentication-parameters)).
4 changes: 2 additions & 2 deletions deploy/deploy-scaledobject.yaml
JatinSanghvi marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ spec:
- type: external
metadata:
scalerAddress: external-scaler-azure-cosmos-db.keda:4050
connection: <connection-string-of-monitored-container-account>
connectionFromEnv: <env-variable-for-connection-string-of-monitored-container-account>
databaseId: <database-id>
containerId: <container-id>
leaseConnection: <connection-string-of-lease-container-account>
leaseConnectionFromEnv: <env-variable-for-connection-string-of-lease-container-account>
leaseDatabaseId: <lease-database-id>
leaseContainerId: <lease-container-id>
processorName: <processor-name>
6 changes: 4 additions & 2 deletions src/Scaler.Demo/OrderProcessor/deploy-scaledobject.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ metadata:
name: cosmosdb-order-processor-scaledobject
namespace: default
spec:
minReplicaCount: 0
maxReplicaCount: 10
pollingInterval: 20
scaleTargetRef:
name: cosmosdb-order-processor
triggers:
- type: external
metadata:
scalerAddress: cosmosdb-scaler.default:4050
connection: <connection-string-of-monitored-container-account>
connectionFromEnv: CosmosDbConfig__Connection
databaseId: StoreDatabase
containerId: OrderContainer
leaseConnection: <connection-string-of-lease-container-account>
leaseConnectionFromEnv: CosmosDbConfig__LeaseConnection
leaseDatabaseId: StoreDatabase
leaseContainerId: OrderProcessorLeases
processorName: OrderProcessor
2 changes: 1 addition & 1 deletion src/Scaler.Demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ We will later deploy the order-processor application to Kubernetes cluster and u
...
```

1. In the manifest file for scaled object, `src/Scaler.Demo/OrderProcessor/deploy-scaledobject.yaml`, update the values of connection strings to point to the test Cosmos DB account and apply it.
1. Apply the manifest file for scaled object, `src/Scaler.Demo/OrderProcessor/deploy-scaledobject.yaml`

```text
kubectl apply --filename=src/Scaler.Demo/OrderProcessor/deploy-scaledobject.yaml
Expand Down
1 change: 0 additions & 1 deletion src/Scaler.Demo/Shared/CosmosDbConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public class CosmosDbConfig
public string DatabaseId { get; set; }
public string ContainerId { get; set; }
public int ContainerThroughput { get; set; }

public string LeaseConnection { get; set; }
public string LeaseDatabaseId { get; set; }
public string LeaseContainerId { get; set; }
Expand Down
18 changes: 9 additions & 9 deletions src/Scaler.Tests/CosmosDbScalerServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public CosmosDbScalerServiceTests()
}

[Theory]
[InlineData("connection")]
[InlineData("connectionFromEnv")]
[InlineData("databaseId")]
[InlineData("containerId")]
[InlineData("leaseConnection")]
[InlineData("leaseConnectionFromEnv")]
[InlineData("leaseDatabaseId")]
[InlineData("leaseContainerId")]
[InlineData("processorName")]
Expand Down Expand Up @@ -50,10 +50,10 @@ public async Task IsActive_ReturnsFalseOnNonZeroPartitions(long partitionCount)
}

[Theory]
[InlineData("connection")]
[InlineData("connectionFromEnv")]
[InlineData("databaseId")]
[InlineData("containerId")]
[InlineData("leaseConnection")]
[InlineData("leaseConnectionFromEnv")]
[InlineData("leaseDatabaseId")]
[InlineData("leaseContainerId")]
[InlineData("processorName")]
Expand Down Expand Up @@ -99,10 +99,10 @@ public async Task GetMetrics_ReturnsSameMetricNameIfPassed(string requestMetricN
}

[Theory]
[InlineData("connection")]
[InlineData("connectionFromEnv")]
[InlineData("databaseId")]
[InlineData("containerId")]
[InlineData("leaseConnection")]
[InlineData("leaseConnectionFromEnv")]
[InlineData("leaseDatabaseId")]
[InlineData("leaseContainerId")]
[InlineData("processorName")]
Expand Down Expand Up @@ -144,7 +144,7 @@ public async Task GetMetricSpec_ReturnsSameMetricNameIfPassed(string requestMetr
public async Task GetMetricSpec_ReturnsNormalizedMetricName()
{
ScaledObjectRef request = GetScaledObjectRef();
request.ScalerMetadata["leaseConnection"] = "AccountEndpoint=https://example.com:443/;AccountKey=ZHVtbXky";
request.ScalerMetadata["leaseConnectionFromEnv"] = "AccountEndpoint=https://example.com:443/;AccountKey=ZHVtbXky";
request.ScalerMetadata["leaseDatabaseId"] = "Dummy.Lease.Database.Id";
request.ScalerMetadata["leaseContainerId"] = "Dummy:Lease:Container:Id";
request.ScalerMetadata["processorName"] = "Dummy%Processor%Name";
Expand Down Expand Up @@ -194,10 +194,10 @@ private static ScaledObjectRef GetScaledObjectRef()

MapField<string, string> scalerMetadata = scaledObjectRef.ScalerMetadata;

scalerMetadata["connection"] = "AccountEndpoint=https://example1.com:443/;AccountKey=ZHVtbXkx";
scalerMetadata["connectionFromEnv"] = "AccountEndpoint=https://example1.com:443/;AccountKey=ZHVtbXkx";
scalerMetadata["databaseId"] = "dummy-database-id";
scalerMetadata["containerId"] = "dummy-container-id";
scalerMetadata["leaseConnection"] = "AccountEndpoint=https://example2.com:443/;AccountKey=ZHVtbXky";
scalerMetadata["leaseConnectionFromEnv"] = "AccountEndpoint=https://example2.com:443/;AccountKey=ZHVtbXky";
scalerMetadata["leaseDatabaseId"] = "dummy-lease-database-id";
scalerMetadata["leaseContainerId"] = "dummy-lease-container-id";
scalerMetadata["processorName"] = "dummy-processor-name";
Expand Down
1 change: 0 additions & 1 deletion src/Scaler/Services/CosmosDbScalerService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Threading.Tasks;
using Grpc.Core;
using Microsoft.Extensions.Logging;

namespace Keda.CosmosDb.Scaler
{
Expand Down
2 changes: 2 additions & 0 deletions src/Scaler/Services/ScalerMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ internal sealed class ScalerMetadata
{
private string _metricName;

[JsonProperty("ConnectionFromEnv")]
public string Connection { get; set; }
public string DatabaseId { get; set; }
public string ContainerId { get; set; }
[JsonProperty("LeaseConnectionFromEnv")]
public string LeaseConnection { get; set; }
public string LeaseDatabaseId { get; set; }
public string LeaseContainerId { get; set; }
Expand Down