-
Notifications
You must be signed in to change notification settings - Fork 206
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
Cosmos DB: Migration to V3 SDK #717
Conversation
c6ce32d
to
da0b1b9
Compare
Tagging @divyagandhisethi - for reference - for PR: kedacore/external-scaler-azure-cosmos-db#1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial comments...
if (item is string) | ||
{ | ||
convertedItem = JObject.Parse(item.ToString()); | ||
JObject asJObject = JObject.Parse(item.ToString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use System.Text.Json here? Would that allow you to remove a ref to Newtonsoft?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind... I forgot we require Newtonsoft.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SDK could take System.Text.Json using a custom serializer if that is the approach we want to take.
document = await _context.Service.GetContainer(_context.ResolvedAttribute.DatabaseName, _context.ResolvedAttribute.CollectionName) | ||
.ReadItemAsync<T>(_context.ResolvedAttribute.Id, partitionKey); | ||
|
||
_originalItem = JObject.FromObject(document); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we want to continue supporting this "update-in-place" behavior. It's never worked for out-of-proc languages and has resulted in a decent amount of confusion as it seems all of the bindings handle it differently.
@fabiocav -- thoughts?
/// <summary> | ||
/// Gets or sets the lease options for the DocumentDB Trigger. | ||
/// </summary> | ||
public ChangeFeedHostOptions LeaseOptions { get; set; } = new ChangeFeedHostOptions(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these not settable now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They were already there in the Trigger properties. Normally these are for a very advanced customization of the trigger, and having it as a general configuration (for all the Triggers in the project) wouldn't have sense.
/// </summary> | ||
[AppSetting] | ||
[ConnectionString] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should probably know this... but what's the difference between this and [AppSetting]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually don't know, but the CosmosDBAttribute
file had it as ConnectionString
so thought it should be consistent?
|
||
Type documentType = CosmosDBTriggerAttributeBindingProviderGenerator.GetParameterType(context.Parameter); | ||
|
||
if (typeof(JArray).IsAssignableFrom(documentType)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right... I forgot we required a Newtonsoft ref...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we were to change to System.Text.Json, which would be the equivalent?
// TODO: What's up with string | ||
if (typeof(string).IsAssignableFrom(documentType)) | ||
{ | ||
documentType = typeof(JObject); // When binding to JArray, use JObject as contract. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I added E2E tests for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static void TriggerWithString(
[CosmosDBTrigger(DatabaseName, CollectionName, CreateLeaseCollectionIfNotExists = true, LeaseCollectionPrefix = "withstring")] string documents,
ILogger log)
{
foreach (var document in JArray.Parse(documents))
{
log.LogInformation("Trigger with string called!");
}
}
} | ||
|
||
Dictionary<string, object> bindingData = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase); | ||
bindingData.Add("CosmosDBTrigger", value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this supported before? Not sure if we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it was required, but I removed it and still worked.
This PR migrates the current implementation to V3 SDK and bumps the version to 4.0.0.
Closes #610