-
Notifications
You must be signed in to change notification settings - Fork 72
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
database: Merge Cosmos DB containers #1215
base: main
Are you sure you want to change the base?
Conversation
Please rebase pull request. |
1dab915
to
ccd20c3
Compare
Please rebase pull request. |
ccd20c3
to
e636adf
Compare
e636adf
to
8a36e1e
Compare
2d7c94e
to
225f6ec
Compare
f2091f2
to
0848be4
Compare
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.
OK - this review is partial. Major finding is panic risky code - let's fixup the interfaces we actually need for this instead of using T
(you arrived there too - just didn't make it into prod code - YAY TESTS!).
Great work as always Matt - I'll find time to review the rest later.
For my future self: My review ended on the first commit - stopped at typeddocument_test.go
d2101b6
to
b737235
Compare
b737235
to
9ce401f
Compare
Requested changes were addressed.
Prepended a new commit to adapt to #1272. Just when I claim the Cosmos DB system-generated fields aren't needed outside the database package, a case pops up. |
4b3433b
to
9aa92e5
Compare
I changed the query expression prematurely. The JSON field for ResourceDocument.ResourceID is still "key". It will change to "resourceId" in PR #1215, along with many other breaking Cosmos DB changes.
Please rebase pull request. |
9aa92e5
to
ea349b4
Compare
Small hack to expose the "_ts" field from a Subscription document in Cosmos DB for metrics reporting. This has a JSON tag of "-" so it will never appear in HTTP response bodies.
This is a major breaking change to our Cosmos DB documents. typedDocument standardizes the structure of documents as follows: { "id": <item-id> "partitionKey": <partition-key> "resourceType": <azure-resource-type> "properties": { ... } "_rid": <system-generated> "_self": <system-generated> "_etag": <system-generated> "_ts": <system-generated> } A key insight is none of the system-generated fields are used outside of the database package. Therefore the data that the frontend/backend components care about can be encapsulated in a "properties" value, and the other document types no longer need to embed baseDocument. DocumentProperties is an interface for types that can be plugged into the "properties" field, like ResourceDocument. It requires a GetValidTypes() method that returns a set of valid values for the "resourceType" field, used for validation when [un]marshalling. One case worth noting is SubscriptionDocument was mostly already following this format, with its "subscription" field defined as a arm.Subscription struct. Instead, arm.Subscription now implements the DocumentProperties interface and SubscriptionDocument is gone. Also worth mentioning is DBClientIterator has been redefined as a iter.Seq2 instead of a iter.Seq. Effectively this means the Items method now returns the Cosmos DB item ID separately from the item (document) itself. To illustrate: old style: for doc := range iterator.Items() new style: for id, doc := range iterator.Items() Apologies for the size of this commit, but the changes here are all intertwined.
This parameter is not used yet, this is just to get some API changes out of the way. The parameter type is azcosmos.PartitionKey instead of string for type safety. If the partition key and item ID parameters were both strings, there would be a risk of callers mixing up the arguments.
Discard the 'Operations' and 'Subscriptions' containers. This data now lives in the 'Resources' container. Doing this enables the use of transactional batch operations when multiple Cosmos DB items of different types need to be created or updated together.
In some cases documentation was moved above the method declaration in the interface rather than above the cosmosDBClient method, which is private to the database package.
azcosmos v1.3.0 partially supports cross-partition queries [1], well enough for our purpose anyway. The PartitionKeys container hack is no longer needed. [1] https://github.com/Azure/azure-sdk-for-go/releases/tag/sdk/data/azcosmos/v1.3.0
ea349b4
to
66bcada
Compare
I tacked on yet another commit to undo #1189 - database: Add PartitionKeys container because Microsoft has released partial cross-partition query support in azcosmos v1.3.0. I tested and verified that it works well enough for our purpose. Adding here since it fits with the theme of dropping Cosmos containers. |
What this PR does
This pull request contains all the breaking changes related to ARO-14170 - Merge Cosmos DB containers.
🚨 Give the ARO-HCP team a heads up before merging this! (auto-merge is disabled) 🚨
In addition to merging the "resources", "operations", and "subscriptions" Cosmos DB containers, this pull request also changes the structure of all Cosmos DB documents in this merged container.
A new
typedDocument
struct standardizes the structure of documents as follows:A key insight is none of the system-generated fields are used outside of the database package. Therefore the data that the frontend/backend components care about can be encapsulated in a
"properties"
value, and the other document types no longer need to embedbaseDocument
.DocumentProperties
is an interface for types that can be plugged into the"properties"
field, likeResourceDocument
. The interface requires aGetValidTypes()
method that returns a set of valid values for the"resourceType"
field, used for validation when [un]marshalling.One case worth noting is
SubscriptionDocument
was mostly already following this format, with its top-level"subscription"
field defined as aarm.Subscription
struct:With this PR,
arm.Subscription
now implements theDocumentProperties
interface andSubscriptionDocument
is gone.Also worth mentioning is
DBClientIteratorItem
has been redefined as a iter.Seq2 instead of a iter.Seq. Effectively this means theDBClientIterator.Items
method now returns the Cosmos DB item ID separately from the item (document) itself.To illustrate:
Jira: ARO-14170 - Merge Cosmos DB containers
Link to demo recording:
Special notes for your reviewer