-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Stream analytics output to CosmosDB #16441
Conversation
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.
Hi @jiaweitao001, thanks for your effort on this PR. Overall this is off to a good start, I left some questions and comments in-line, once those are fixed up we can take another look through this.
Thanks!
internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go
Outdated
Show resolved
Hide resolved
internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go
Outdated
Show resolved
Hide resolved
internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go
Outdated
Show resolved
Hide resolved
internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go
Outdated
Show resolved
Hide resolved
internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go
Outdated
Show resolved
Hide resolved
|
||
* `database` - (Required) The name or id of the CosmosDB database. | ||
|
||
* `collection_name_pattern` - (Required) The collection name pattern for the collection to be used. It can be the name of the container, or a collection name format which contains an optional {partition} token. |
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.
As mentioned above I think it makes more sense for this to be named container_id
- I also haven't seen an a test that provides this property with an optional partition token. Could you find an example of what that looks like? This might need to be added as an additional/separate field to the resource.
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'll add another test for the scenario with an optional partition token.
|
||
* `document_id` - (Optional) The name of the field in output events used to specify the primary key which insert or update operations are based on. | ||
|
||
* `partition_key` - (Optional) The name of the field in output events used to specify the key for partitioning output across collections. If 'collection_name_pattern' contains the {partition} token, this property is required to be specified. |
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 this is required in specific circumstances should we be checking this in the create function?
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 the partition_key
does not exist under the described circumstance, an error message will show up to complain about the missing field, test proven.
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.
Thanks for making those changes @jiaweitao001! There are still a few things to fix up before we can merge this though.
In addition to the comments left in-line I would like to come back to the comments left in my initial review on the collection_name_pattern
. As mentioned this property is referred to as Container Name in the portal. In addition the field partition_key
isn't exposed at all and as far as I can tell doesn't actually do anything.
Despite the fact that the API allows the creation of a name pattern with a partition key e.g. container-name{partition}
, this results in an unusable connection with the following error.
After some digging I found this comment which says that this is deprecated and no longer supported - the portal reflects this behaviour.
As a result I think we should rename the property collection_name_pattern
to container_name
and remove the partition_key
property. WDYT?
func (id OutputId) StreamingJobID() string { | ||
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.StreamAnalytics/streamingjobs/%s" | ||
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.StreamingjobName) | ||
} | ||
|
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.
These files are generated so this will be overwritten when the provider is built
func (id OutputId) StreamingJobID() string { | |
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.StreamAnalytics/streamingjobs/%s" | |
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.StreamingjobName) | |
} |
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.
Will remove.
|
||
state := OutputCosmosDBResourceModel{ | ||
Name: id.Name, | ||
StreamAnalyticsJob: id.StreamingJobID(), |
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.
We should generate the streaming job ID here
state := OutputCosmosDBResourceModel{ | |
Name: id.Name, | |
StreamAnalyticsJob: id.StreamingJobID(), | |
streamingJobId := parse.NewStreamingJobID(id.SubscriptionId, id.ResourceGroup, id.StreamingjobName) | |
state := OutputCosmosDBResourceModel{ | |
Name: id.Name, | |
StreamAnalyticsJob: streamingJobId.ID(), |
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.
Sure. Will fix.
client := metadata.Client.StreamAnalytics.OutputsClient | ||
subscriptionId := metadata.Client.Account.SubscriptionId | ||
|
||
streamingJobStruct, err := parse.StreamingJobID(model.StreamAnalyticsJob) |
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 variable type Struct
in the name is redundant information, we usually append these with Id
to help with readability
streamingJobStruct, err := parse.StreamingJobID(model.StreamAnalyticsJob) | |
streamingJobId err := parse.StreamingJobID(model.StreamAnalyticsJob) |
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.
Will rename.
return metadata.ResourceRequiresImport(r.ResourceType(), id) | ||
} | ||
|
||
databaseIdStruct, err := cosmosParse.SqlDatabaseID(model.Database) |
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.
databaseIdStruct, err := cosmosParse.SqlDatabaseID(model.Database) | |
databaseId, err := cosmosParse.SqlDatabaseID(model.Database) |
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.
Will rename.
documentDbOutputProps := &streamanalytics.DocumentDbOutputDataSourceProperties{ | ||
AccountID: utils.String(databaseIdStruct.DatabaseAccountName), | ||
AccountKey: utils.String(model.AccountKey), | ||
Database: utils.String(model.Database), |
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.
This should actually be the database name and not the ID. Even though you can create the SA output with the ID, the connectivity test will fail.
Database: utils.String(model.Database), | |
Database: utils.String(databaseId.Name |
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.
Will fix.
|
||
if metadata.ResourceData.HasChangesExcept("name", "stream_analytics_job_id") { | ||
props := streamanalytics.Output{ | ||
OutputProperties: &streamanalytics.OutputProperties{ | ||
Datasource: streamanalytics.DocumentDbOutputDataSource{ | ||
Type: streamanalytics.TypeBasicOutputDataSourceTypeMicrosoftStorageDocumentDB, | ||
DocumentDbOutputDataSourceProperties: &streamanalytics.DocumentDbOutputDataSourceProperties{ | ||
AccountKey: &state.AccountKey, | ||
Database: &state.Database, |
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.
Same here, we need to parse this value as an ID and send the name of the database
if metadata.ResourceData.HasChangesExcept("name", "stream_analytics_job_id") { | |
props := streamanalytics.Output{ | |
OutputProperties: &streamanalytics.OutputProperties{ | |
Datasource: streamanalytics.DocumentDbOutputDataSource{ | |
Type: streamanalytics.TypeBasicOutputDataSourceTypeMicrosoftStorageDocumentDB, | |
DocumentDbOutputDataSourceProperties: &streamanalytics.DocumentDbOutputDataSourceProperties{ | |
AccountKey: &state.AccountKey, | |
Database: &state.Database, | |
databaseId, err := cosmosParse.SqlDatabaseID(state.Database) | |
if err != nil { | |
return err | |
} | |
if metadata.ResourceData.HasChangesExcept("name", "stream_analytics_job_id") { | |
props := streamanalytics.Output{ | |
OutputProperties: &streamanalytics.OutputProperties{ | |
Datasource: streamanalytics.DocumentDbOutputDataSource{ | |
Type: streamanalytics.TypeBasicOutputDataSourceTypeMicrosoftStorageDocumentDB, | |
DocumentDbOutputDataSourceProperties: &streamanalytics.DocumentDbOutputDataSourceProperties{ | |
AccountKey: &state.AccountKey, | |
Database: &databaseId.Name, |
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.
Will fix.
resource_group_name = azurerm_cosmosdb_account.test.resource_group_name | ||
account_name = azurerm_cosmosdb_account.test.name | ||
database_name = azurerm_cosmosdb_sql_database.updated.name | ||
partition_key_path = "/definition/id" |
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.
This is a nested partition key which isn't supported by Stream Analytics, an error will be thrown when testing the connectivity
partition_key_path = "/definition/id" | |
partition_key_path = "/definition" |
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.
Will fix.
resource_group_name = azurerm_cosmosdb_account.test.resource_group_name | ||
account_name = azurerm_cosmosdb_account.test.name | ||
database_name = azurerm_cosmosdb_sql_database.test.name | ||
partition_key_path = "/definition/id" |
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.
partition_key_path = "/definition/id" | |
partition_key_path = "/definition" |
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.
Will fix.
After testing on this param, I agree that 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.
Thanks for @jiaweitao001! LGTM 🍰
This functionality has been released in v3.4.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Added
azurerm_stream_analytics_output_cosmosdb
resource and corresponding tests.