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 Managed Identity support for connecting to Cosmos DB, Update dependencies with latest. #71

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sandeepsnairms
Copy link

Provide a description of what has been changed

Checklist

  • Commits are signed with Developer Certificate of Origin (DCO)
  • A PR is opened to update the documentation on our docs repo

Fixes #

README.md Outdated

- **`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.
- **`leaseEndpoint`** - Endpoint URL of the Cosmos DB account that contains the lease container. This can be same or different from the value of `connection` metadata.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`connection` metadata to `endpoint` metadata.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What changes were made to the PowerPoint file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None

COPY src/Scaler.Demo/OrderGenerator/ src/Scaler.Demo/OrderGenerator/
COPY src/Scaler.Demo/Shared/ src/Scaler.Demo/Shared/
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
Copy link
Collaborator

@JatinSanghvi JatinSanghvi Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should WORKDIR be /src/Scaler.Demo/OrderGenerator? Other files inside /src will not be required to be copied for either build or restore.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, the earlier Dockerfile was small and used to work. Can you minimize the changes to each Dockerfile, and keep it close to the original?

@@ -1,6 +1,7 @@
{
"CosmosDbConfig": {
"Connection": "<connection-string-of-monitored-container-account>",
"Endpoint": "https://{Cosmos Account Name}.documents.azure.com:443/",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either keep just the 'Endpoint' config or make it clear that either one of the two properties are required.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of Order Generator, we are not deploying it on AKS. It just used locally to generate CosmosDB records and trigger the Change Feed, hence Order Generator is using connection string method to authenticate.

var credential = new DefaultAzureCredential();

leaseDatabase = new Microsoft.Azure.Cosmos.CosmosClient(_cosmosDbConfig.LeaseEndpoint, credential, clientOptions)
.GetDatabase(_cosmosDbConfig.LeaseDatabaseId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check the demo project's Readme but creating the lease database here prevents user from that manual step.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No new database is getting created, the code has been modified to handle AAD based CS based authentications

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you create the lease database in that case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

namespace Keda.CosmosDb.Scaler
{
internal sealed class CosmosDbMetricProvider : ICosmosDbMetricProvider
{
private readonly CosmosDbFactory _factory;
private readonly ILogger<CosmosDbMetricProvider> _logger;

static Meter s_meter = new Meter("OrderProcessor.CFStore", "1.0.0");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set visibility of properties explicitly. Use standard C# property names and put newlines between property declarations and methods.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

.GetContainer(scalerMetadata.DatabaseId, scalerMetadata.ContainerId)
.GetChangeFeedEstimator(scalerMetadata.ProcessorName, leaseContainer);
var credential = new DefaultAzureCredential();
var cosmosClient = new CosmosClient(scalerMetadata.Endpoint, credential);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use GetCosmosClient to have a single connection if both endpoints happen to be same.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

}

s_CFRecordsReceived.Add(lagCount);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't find s_* variables are used anywhere. Can you explain what do they achieve?

@@ -39,8 +41,16 @@ private string LeaseAccountHost
{
get
{
var builder = new DbConnectionStringBuilder { ConnectionString = this.LeaseConnection };
return new Uri((string)builder["AccountEndpoint"]).Host;
if(!string.IsNullOrEmpty(this.LeaseConnection))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we support connection string based connections or not?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a miss

@@ -18,10 +18,10 @@ public CosmosDbScalerServiceTests()
}

[Theory]
[InlineData("connection")]
[InlineData("endpoint")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retain support for connection-string based connections and have tests for both scenarios.

int partitionCount = 0;

using (FeedIterator<ChangeFeedProcessorState> iterator = estimator.GetCurrentStateIterator())
long lagCount=0;
Copy link
Collaborator

@JatinSanghvi JatinSanghvi Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put proper spacing.

@@ -1,16 +1,23 @@
# https://hub.docker.com/_/microsoft-dotnet
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this Dockerfile generated using Visual Studio?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the original was not working. So, had to overwrite with VS generated Docker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants