cloudquery: MSSQL Destination PK violations & unicode characters

Describe the Bug

Observations after testing new MSSQL destination plugin:

  1. Primary Key Violations
  2. Unicode characters I am using the Azure source plugin. In the tags column I am seeing issues with unicode characters {"BillTo":"P\u0026T"} instead of {"BillTo":"P&T"}. This works properly with Postgres destination.

Expected Behavior

No primary key violations, and data values with the actual special characters instead of the escaped unicode representations.

CloudQuery Version

cloudquery version 2.2.0 azure (v3.4.0) -> mssql (v1.0.0)

Debug Output

{"level":"error","module":"cli","class":14,"line_no":24,"message":"Violation of PRIMARY KEY constraint 'azure_network_azure_firewall_fqdn_tags_cqpk'. Cannot insert duplicate key in object 'dbo.azure_network_azure_firewall_fqdn_tags'. The duplicate key value is (/subscriptions//resourceGroups//providers/Microsoft.Network/azureFirewallFqdnTags/).","module":"dest-mssql","number":2627,"proc_name":"dbo.cq_proc_azure_network_azure_firewall_fqdn_tags","server_name":"<SQL_SERVER_INSTANCE>","state":1,"time":"2023-01-20T21:24:08Z"} {"level":"error","module":"cli","duration":1765.3814,"error":"mssql: Violation of PRIMARY KEY constraint 'azure_network_azure_firewall_fqdn_tags_cqpk'. Cannot insert duplicate key in object 'dbo.azure_network_azure_firewall_fqdn_tags'. The duplicate key value is (/subscriptions//resourceGroups//providers/Microsoft.Network/azureFirewallFqdnTags/).","len":3,"message":"failed to write batch","table":"azure_network_azure_firewall_fqdn_tags","time":"2023-01-20T21:24:08Z"} {"level":"error","module":"cli","class":14,"line_no":23,"message":"Violation of PRIMARY KEY constraint 'azure_network_express_route_service_providers_cqpk'. Cannot insert duplicate key in object 'dbo.azure_network_express_route_service_providers'. The duplicate key value is (/subscriptions//resourceGroups//providers/Microsoft.Network/expressRouteServiceProviders/).","module":"dest-mssql","number":2627,"proc_name":"dbo.cq_proc_azure_network_express_route_service_providers","server_name":"<SQL_SERVER_INSTANCE>","state":1,"time":"2023-01-20T21:24:21Z"} {"level":"error","module":"cli","duration":44.6381,"error":"mssql: Violation of PRIMARY KEY constraint 'azure_network_express_route_service_providers_cqpk'. Cannot insert duplicate key in object 'dbo.azure_network_express_route_service_providers'. The duplicate key value is (/subscriptions//resourceGroups//providers/Microsoft.Network/expressRouteServiceProviders/).","len":3,"message":"failed to write batch","table":"azure_network_express_route_service_providers","time":"2023-01-20T21:24:21Z"} {"level":"error","module":"cli","class":14,"line_no":23,"message":"Violation of PRIMARY KEY constraint 'azure_authorization_provider_operations_metadata_cqpk'. Cannot insert duplicate key in object 'dbo.azure_authorization_provider_operations_metadata'. The duplicate key value is (/providers/Microsoft.Authorization/providerOperations/Qumulo.QaaS).","module":"dest-mssql","number":2627,"proc_name":"dbo.cq_proc_azure_authorization_provider_operations_metadata","server_name":"<SQL_SERVER_INSTANCE>","state":1,"time":"2023-01-20T21:29:57Z"} {"level":"error","module":"cli","duration":141.0392,"error":"mssql: Violation of PRIMARY KEY constraint 'azure_authorization_provider_operations_metadata_cqpk'. Cannot insert duplicate key in object 'dbo.azure_authorization_provider_operations_metadata'. The duplicate key value is (/providers/Microsoft.Authorization/providerOperations/Qumulo.QaaS).","len":1000,"message":"failed to write batch","table":"azure_authorization_provider_operations_metadata","time":"2023-01-20T21:29:57Z"} {"level":"error","module":"cli","class":14,"line_no":31,"message":"Violation of PRIMARY KEY constraint 'azure_compute_skus_cqpk'. Cannot insert duplicate key in object 'dbo.azure_compute_skus'. The duplicate key value is (Aligned).","module":"dest-mssql","number":2627,"proc_name":"dbo.cq_proc_azure_compute_skus","server_name":"<SQL_SERVER_INSTANCE>","state":1,"time":"2023-01-20T21:29:59Z"} {"level":"error","module":"cli","duration":97.4163,"error":"mssql: Violation of PRIMARY KEY constraint 'azure_compute_skus_cqpk'. Cannot insert duplicate key in object 'dbo.azure_compute_skus'. The duplicate key value is (Aligned).","len":1000,"message":"failed to write batch","table":"azure_compute_skus","time":"2023-01-20T21:29:59Z"} {"level":"error","module":"cli","class":14,"line_no":22,"message":"Violation of PRIMARY KEY constraint 'azure_security_topology_cqpk'. Cannot insert duplicate key in object 'dbo.azure_security_topology'. The duplicate key value is (/subscriptions/<AZ_SUBSCRIPTION>/resourceGroups/<AZ_RG>/providers/Microsoft.Security/locations/westcentralus/topologies/virtualMachines).","module":"dest-mssql","number":2627,"proc_name":"dbo.cq_proc_azure_security_topology","server_name":"<SQL_SERVER_INSTANCE>","state":1,"time":"2023-01-20T21:36:57Z"} {"level":"error","module":"cli","duration":93.7219,"error":"mssql: Violation of PRIMARY KEY constraint 'azure_security_topology_cqpk'. Cannot insert duplicate key in object 'dbo.azure_security_topology'. The duplicate key value is (/subscriptions/<AZ_SUBSCRIPTION>/resourceGroups/<AZ_RG>/providers/Microsoft.Security/locations/westcentralus/topologies/virtualMachines).","len":564,"message":"failed to write batch","table":"azure_security_topology","time":"2023-01-20T21:36:57Z"}

Steps to Reproduce

cloudquery.exe sync .\config --log-level warn --log-format json
kind: source
spec:
 name: azure
 path: cloudquery/azure
 version: "v3.4.0"
 destinations: ["mssql"]
 tables: ["*"]
 concurrency: 150000
 scheduler: "round-robin"
 skip_tables:
  [
   "azure_monitor_tenant_activity_logs",
   "azure_portal_list_tenant_configuration_violations",
   "azure_appservice_web_app_auth_settings",
   "azure_policy_assignments",
   "azure_security_contacts",
   "azure_reservations_reservation_order",
   "azure_security_regulatory_compliance_standards",
   "azure_storage_tables",
   "azure_storage_blob_services",
   "azure_storage_containers",
  ]
 spec:
  subscriptions:
   [
    ...
   ]

kind: destination
spec:
 name: "mssql"
 registry: "github"
 path: "cloudquery/mssql"
 version: "v1.0.0"
 spec:
  connection_string: ${MSSQL_CONNECTION_STRING}
  auth_mode: ms
  schema: dbo

Additional Context

N/A

References

https://github.com/cloudquery/cloudquery/issues/6145#issuecomment-1398444499

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 19 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks @candiduslynx And thank you again for all the work on this new plugin

@rafaelrodrigues3092

I was actually interested in overwrite-delete-stale. My understanding was that this was the default (I don’t explicitly define anything).

I don’t recall seeing any DELETE statements in the stored procedures - but I wanted to test it out first, as I was not sure if it was being handled or it was simply not supported

Ah, I see. The delete part is handled by this code.

@rafaelrodrigues3092 additionally, errors that are present in the log are also very helpful, created:

@candiduslynx

Awesome. Thank you for that. I have a question regarding how the write_mode on the MSSQL destination plugin, but I want to test it out first before I go ahead and ask.

Is it cool if ask here? Or would you like me to open a new issue and ask it there?

@rafaelrodrigues3092 thanks for he info! The test plugin output is the required info. I’m going to add it to #7183 an close this issue as duplicate, if you don’t mind.

@candiduslynx

I ran the test as described. I am adding all the details below to set the stage properly. Few Items:

  • I actively skipped some tables because I know I either have permissions or API throttling issues with those
  • cloudquery reported 1657 errors. Many of them were 403s (expected on my end). I removed them from the output to keep it clean
  • I saw PK errors on the output of the test plugin, but these were not in the cloudquery log file

Please let me know if I missed something

Config:

kind: source
spec:
 name: azure
 path: cloudquery/azure
 version: "v3.4.0"
 destinations: ["test"]
 tables: ["*"]
 skip_tables:
  [
   "azure_keyvault_keyvault",
   "azure_keyvault_keyvault_managed_hsms",
   "azure_keyvault_keyvault_keys",
   "azure_keyvault_keyvault_secrets",
   "azure_storage_blob_services",
   "azure_storage_containers",
   "azure_storage_tables",
   "azure_storagecache_caches",
  ]
 spec:
  subscriptions:
   [
    (23 subscriptions)
   ]
---
kind: destination
spec:
 name: test
 path: localhost:7777
 registry: grpc
 write_mode: overwrite
 spec:

Command

PS D:\cloudquery> .\cloudquery.exe sync .\config --telemetry-level none --log-level error --log-format json
Loading spec(s) from .\config
Source azure (v3.4.0) will migrate and sync 238 tables.
Starting migration for: azure (v3.4.0) -> [test (grpc@localhost:7777)]
Migration completed successfully.
Starting sync for: azure (v3.4.0) -> [test (grpc@localhost:7777)]
Sync completed successfully. Resources: 1032989, Errors: 1657, Panics: 0, Time: 6m33s

Test Plugin StdOut

10:12AM INF Destination plugin server listening maddress=127.0.0.1:7777
10:12AM INF started call mgrpc.code=OK mgrpc.component=server mgrpc.method=Configure mgrpc.method_type=unary mgrpc.service=proto.Destination mgrpc.start_time=2023-01-25T10:12:55-05:00 mgrpc.time_ms=0 mpeer.address=127.0.0.1:55674 mprotocol=grpc
10:12AM INF finished call mgrpc.code=OK mgrpc.component=server mgrpc.method=Configure mgrpc.method_type=unary mgrpc.service=proto.Destination mgrpc.start_time=2023-01-25T10:12:55-05:00 mgrpc.time_ms=2.183 mpeer.address=127.0.0.1:55674 mprotocol=grpc
10:12AM INF started call mgrpc.code=OK mgrpc.component=server mgrpc.method=Migrate mgrpc.method_type=unary mgrpc.service=proto.Destination mgrpc.start_time=2023-01-25T10:12:55-05:00 mgrpc.time_ms=0 mpeer.address=127.0.0.1:55674 mprotocol=grpc
10:12AM INF finished call mgrpc.code=OK mgrpc.component=server mgrpc.method=Migrate mgrpc.method_type=unary mgrpc.service=proto.Destination mgrpc.start_time=2023-01-25T10:12:55-05:00 mgrpc.time_ms=3.62 mpeer.address=127.0.0.1:55674 mprotocol=grpc
10:12AM INF started call mgrpc.code=OK mgrpc.component=server mgrpc.method=Write2 mgrpc.method_type=client_stream mgrpc.service=proto.Destination mgrpc.start_time=2023-01-25T10:12:55-05:00 mgrpc.time_ms=2.675 mpeer.address=127.0.0.1:55674 mprotocol=grpc
10:15AM ERR Duplicate PK mcolumns=(id) mmodule=test mtable=azure_advisor_recommendation_metadata mvalue=(/providers/Microsoft.Advisor/metadata/caller)
10:15AM ERR Duplicate PK mcolumns=(id) mmodule=test mtable=azure_frontdoor_managed_rule_sets mvalue=(/providers/Microsoft.Network/frontdoorwebapplicationfirewallmanagedrulesets/BotProtection_preview-0.1)
10:15AM ERR Duplicate PK mcolumns=(id) mmodule=test mtable=azure_eventgrid_topic_types mvalue=(providers/Microsoft.EventGrid/topicTypes/Microsoft.DataBox.Jobs)
10:15AM ERR Duplicate PK mcolumns=(id) mmodule=test mtable=azure_authorization_provider_operations_metadata mvalue=(/providers/Microsoft.Authorization/providerOperations/Microsoft.CloudShell)
10:15AM ERR Duplicate PK mcolumns=(id) mmodule=test mtable=azure_security_secure_score_control_definitions mvalue=(/providers/Microsoft.Security/secureScoreControlDefinitions/<uuid>)
10:15AM ERR Duplicate PK mcolumns=(id) mmodule=test mtable=azure_reservations_reservation mvalue=(/providers/microsoft.capacity/reservationOrders/<uuid>/reservations/<uuid>)
10:15AM ERR Duplicate PK mcolumns=(id) mmodule=test mtable=azure_support_services mvalue=(/providers/Microsoft.Support/services/<uuid>)
10:15AM ERR Duplicate PK mcolumns=(id) mmodule=test mtable=azure_authorization_role_assignments mvalue=(/providers/Microsoft.Authorization/roleAssignments/<uuid>)
10:15AM ERR Duplicate PK mcolumns=(id) mmodule=test mtable=azure_security_assessments_metadata mvalue=(/providers/Microsoft.Security/assessmentMetadata/<uuid>)
10:15AM ERR Duplicate PK mcolumns=(id) mmodule=test mtable=azure_compute_skus mvalue=(Aligned)
10:18AM INF finished call mgrpc.code=OK mgrpc.component=server mgrpc.method=Write2 mgrpc.method_type=client_stream mgrpc.service=proto.Destination mgrpc.start_time=2023-01-25T10:12:55-05:00 mgrpc.time_ms=359482.4 mpeer.address=127.0.0.1:55674 mprotocol=grpc
10:18AM INF started call mgrpc.code=OK mgrpc.component=server mgrpc.method=Close mgrpc.method_type=unary mgrpc.service=proto.Destination mgrpc.start_time=2023-01-25T10:18:55-05:00 mgrpc.time_ms=0 mpeer.address=127.0.0.1:55674 mprotocol=grpc
10:18AM INF finished call mgrpc.code=OK mgrpc.component=server mgrpc.method=Close mgrpc.method_type=unary mgrpc.service=proto.Destination mgrpc.start_time=2023-01-25T10:18:55-05:00 mgrpc.time_ms=0 mpeer.address=127.0.0.1:55674 mprotocol=grpc

Cloudquery log file


{"level":"error","module":"cli","client":"<AZ_SUBID_4>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:25:33Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_5>","error":"unmarshalling type *armsecurity.ContactList: unmarshalling type *armsecurity.ContactList: json: cannot unmarshal array into Go value of type map[string]json.RawMessage","message":"table resolver finished with error","module":"azure-src","table":"azure_security_contacts","time":"2023-01-25T15:25:33Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_5>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:25:35Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_6>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:25:36Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_7>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:25:36Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_8>","error":"unmarshalling type *armsecurity.ContactList: unmarshalling type *armsecurity.ContactList: json: cannot unmarshal array into Go value of type map[string]json.RawMessage","message":"table resolver finished with error","module":"azure-src","table":"azure_security_contacts","time":"2023-01-25T15:25:36Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_8>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:25:40Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_9>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:25:40Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_10>","error":"unmarshalling type *armsecurity.ContactList: unmarshalling type *armsecurity.ContactList: json: cannot unmarshal array into Go value of type map[string]json.RawMessage","message":"table resolver finished with error","module":"azure-src","table":"azure_security_contacts","time":"2023-01-25T15:25:40Z"}   \"message\": \"The client '<client_id>' with object id '<client_id>' does not have authorization to perform action 'Microsoft.Insights/eventtypes/values/read' over scope '/providers/Microsoft.Insights/eventtypes/management' or the scope is invalid. If access was recently granted, please refresh your credentials.\"\n  }\n}\n--------------------------------------------------------------------------------\n","message":"table resolver finished with error","module":"azure-src","table":"azure_monitor_tenant_activity_logs","time":"2023-01-25T15:25:40Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_10>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:25:40Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_11>","error":"unmarshalling type *armsecurity.ContactList: unmarshalling type *armsecurity.ContactList: json: cannot unmarshal array into Go value of type map[string]json.RawMessage","message":"table resolver finished with error","module":"azure-src","table":"azure_security_contacts","time":"2023-01-25T15:25:42Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_1>","error":"GET https://management.azure.com/subscriptions/<AZ_SUBID_1>/providers/Microsoft.Security/regulatoryComplianceStandards\n--------------------------------------------------------------------------------\nRESPONSE 400: 400 Bad Request\nERROR CODE: Subscription with no standard pricing bundle\n--------------------------------------------------------------------------------\n{\n  \"error\": {\n    \"code\": \"Subscription with no standard pricing bundle\",\n    \"message\": \"Regulatory compliance is not supported for subscription '<AZ_SUBID_1>' as it has no standard pricing bundle\"\n  }\n}\n--------------------------------------------------------------------------------\n","message":"table resolver finished with error","module":"azure-src","table":"azure_security_regulatory_compliance_standards","time":"2023-01-25T15:25:42Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_12>","error":"unmarshalling type *armsecurity.ContactList: unmarshalling type *armsecurity.ContactList: json: cannot unmarshal array into Go value of type map[string]json.RawMessage","message":"table resolver finished with error","module":"azure-src","table":"azure_security_contacts","time":"2023-01-25T15:25:42Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_3>","error":"unmarshalling type *armsecurity.ContactList: unmarshalling type *armsecurity.ContactList: json: cannot unmarshal array into Go value of type map[string]json.RawMessage","message":"table resolver finished with error","module":"azure-src","table":"azure_security_contacts","time":"2023-01-25T15:25:42Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_13>","error":"unmarshalling type *armsecurity.ContactList: unmarshalling type *armsecurity.ContactList: json: cannot unmarshal array into Go value of type map[string]json.RawMessage","message":"table resolver finished with error","module":"azure-src","table":"azure_security_contacts","time":"2023-01-25T15:25:42Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_16>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:25:42Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_11>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:25:43Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_2>","error":"GET https://management.azure.com/subscriptions/<AZ_SUBID_2>/providers/Microsoft.Security/regulatoryComplianceStandards\n--------------------------------------------------------------------------------\nRESPONSE 400: 400 Bad Request\nERROR CODE: Subscription with no standard pricing bundle\n--------------------------------------------------------------------------------\n{\n  \"error\": {\n    \"code\": \"Subscription with no standard pricing bundle\",\n    \"message\": \"Regulatory compliance is not supported for subscription '<AZ_SUBID_2>' as it has no standard pricing bundle\"\n  }\n}\n--------------------------------------------------------------------------------\n","message":"table resolver finished with error","module":"azure-src","table":"azure_security_regulatory_compliance_standards","time":"2023-01-25T15:25:43Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_13>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:25:43Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_14>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:25:43Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_15>","error":"unmarshalling type *armsecurity.ContactList: unmarshalling type *armsecurity.ContactList: json: cannot unmarshal array into Go value of type map[string]json.RawMessage","message":"table resolver finished with error","module":"azure-src","table":"azure_security_contacts","time":"2023-01-25T15:25:48Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_17>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:25:49Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_3>","error":"GET https://management.azure.com/subscriptions/<AZ_SUBID_3>/providers/Microsoft.Security/regulatoryComplianceStandards\n--------------------------------------------------------------------------------\nRESPONSE 400: 400 Bad Request\nERROR CODE: Subscription with no standard pricing bundle\n--------------------------------------------------------------------------------\n{\n  \"error\": {\n    \"code\": \"Subscription with no standard pricing bundle\",\n    \"message\": \"Regulatory compliance is not supported for subscription '<AZ_SUBID_3>' as it has no standard pricing bundle\"\n  }\n}\n--------------------------------------------------------------------------------\n","message":"table resolver finished with error","module":"azure-src","table":"azure_security_regulatory_compliance_standards","time":"2023-01-25T15:25:49Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_15>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:25:49Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_12>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:25:50Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_2>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:25:50Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_16>","error":"unmarshalling type *armsecurity.ContactList: unmarshalling type *armsecurity.ContactList: json: cannot unmarshal array into Go value of type map[string]json.RawMessage","message":"table resolver finished with error","module":"azure-src","table":"azure_security_contacts","time":"2023-01-25T15:25:50Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_3>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:25:55Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_18>","error":"unmarshalling type *armsecurity.ContactList: unmarshalling type *armsecurity.ContactList: json: cannot unmarshal array into Go value of type map[string]json.RawMessage","message":"table resolver finished with error","module":"azure-src","table":"azure_security_contacts","time":"2023-01-25T15:25:56Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_19>","error":"unmarshalling type *armsecurity.ContactList: unmarshalling type *armsecurity.ContactList: json: cannot unmarshal array into Go value of type map[string]json.RawMessage","message":"table resolver finished with error","module":"azure-src","table":"azure_security_contacts","time":"2023-01-25T15:25:56Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_20>","error":"unmarshalling type *armsecurity.ContactList: unmarshalling type *armsecurity.ContactList: json: cannot unmarshal array into Go value of type map[string]json.RawMessage","message":"table resolver finished with error","module":"azure-src","table":"azure_security_contacts","time":"2023-01-25T15:25:56Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_21>","error":"unmarshalling type *armsecurity.ContactList: unmarshalling type *armsecurity.ContactList: json: cannot unmarshal array into Go value of type map[string]json.RawMessage","message":"table resolver finished with error","module":"azure-src","table":"azure_security_contacts","time":"2023-01-25T15:25:57Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_1>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:25:57Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_7>","error":"unmarshalling type *armsecurity.ContactList: unmarshalling type *armsecurity.ContactList: json: cannot unmarshal array into Go value of type map[string]json.RawMessage","message":"table resolver finished with error","module":"azure-src","table":"azure_security_contacts","time":"2023-01-25T15:25:59Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_17>","error":"unmarshalling type *armsecurity.ContactList: unmarshalling type *armsecurity.ContactList: json: cannot unmarshal array into Go value of type map[string]json.RawMessage","message":"table resolver finished with error","module":"azure-src","table":"azure_security_contacts","time":"2023-01-25T15:25:59Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_4>","error":"unmarshalling type *armsecurity.ContactList: unmarshalling type *armsecurity.ContactList: json: cannot unmarshal array into Go value of type map[string]json.RawMessage","message":"table resolver finished with error","module":"azure-src","table":"azure_security_contacts","time":"2023-01-25T15:25:59Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_9>","error":"unmarshalling type *armsecurity.ContactList: unmarshalling type *armsecurity.ContactList: json: cannot unmarshal array into Go value of type map[string]json.RawMessage","message":"table resolver finished with error","module":"azure-src","table":"azure_security_contacts","time":"2023-01-25T15:25:59Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_18>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:25:59Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_22>","error":"unmarshalling type *armsecurity.ContactList: unmarshalling type *armsecurity.ContactList: json: cannot unmarshal array into Go value of type map[string]json.RawMessage","message":"table resolver finished with error","module":"azure-src","table":"azure_security_contacts","time":"2023-01-25T15:26:00Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_23>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:26:00Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_23>","error":"unmarshalling type *armsecurity.ContactList: unmarshalling type *armsecurity.ContactList: json: cannot unmarshal array into Go value of type map[string]json.RawMessage","message":"table resolver finished with error","module":"azure-src","table":"azure_security_contacts","time":"2023-01-25T15:26:00Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_22>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:26:02Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_6>","error":"unmarshalling type *armsecurity.ContactList: unmarshalling type *armsecurity.ContactList: json: cannot unmarshal array into Go value of type map[string]json.RawMessage","message":"table resolver finished with error","module":"azure-src","table":"azure_security_contacts","time":"2023-01-25T15:26:06Z"}
{"level":"error","module":"cli","client":"<AZ_SUBID_20>","error":"unmarshalling type *armreservations.ReservationOrderList: unmarshalling type *armreservations.ReservationOrderList: struct field Value: json: cannot unmarshal string into Go value of type []*armreservations.ReservationOrderResponse","message":"table resolver finished with error","module":"azure-src","table":"azure_reservations_reservation_order","time":"2023-01-25T15:26:06Z"}

Hi @rafaelrodrigues3092! As we’re discussing the proper way to introduce the testing tool, could you test with the following setup:

  1. Take the code from feat(test): Add primary key violation check to test destination #7179
  2. Run he local copy of test plugin (cd plugins/destination/test; go run . serve)
  3. Use the following destination config:
kind: destination
spec:
  name:       test
  path:       localhost:7777
  registry:   grpc
  write_mode: overwrite
  spec:
  1. Sync your resources to this destination & post the error log entries (be sure to remove private info) to Azure primary key violations #7183

I will give this a try. Please allow me some time to figure out how to run it locally with the instructions above 😃

Hi @rafaelrodrigues3092! Yes, the problem is with Azure plugin. In fact, we saw this in another sources as well, so we’ll be fixing it in #7173.

The issue can be observer via Microsoft SQL Server if and only if a couple of resources with the same primary key end up being sent in the same batch (overwrite and overwrite-delete-stale modes). This is the reason why you saw different tables with issues on different runs.

We’ll be prioritizing #7173 issue to fix all PK violations found.

Once the testing plugin is updated, would you mind running the sync against it? As you have several azure subscriptions to sync from it may help to find additional violations.

Adding to my comment above – I checked my Postgres database. I see the PK is the id (SkuName) as well. When searching for ‘Standard_NV18ads_A10_v5’ I found a single record - rather than 1 record per subscription.

I am wondering if the problem here is with the Azure source plugin?

Thanks

@candiduslynx

I tested v2.1.0 and the PK issue is still there. I decided to trace the database, and I think I found the problem. I focused on the [azure_compute_skus] table. And for this case, we essentially need a composite key. The current Id (PK) is the VM SkuName but across multiple subscriptions the SkuName repeats.

For example:

declare @p3 dbo.cq_tbl_azure_compute_skus
insert into @p3 values(N'azure','2023-01-24 03:04:13.5204127 +00:00',0x07C0497405779C41A2DE7145D062CDB5,NULL,N'<AZ_SUB_ID_20>',N'Standard_NV18ads_A10_v5',N'',N'[{"name":"MaxResourceVolumeMB","value":"737280"},{"name":"OSVhdSizeMB","value":"1047552"},{"name":"vCPUs","value":"18"},{"name":"MemoryPreservingMaintenanceSupported","value":"False"},{"name":"HyperVGenerations","value":"V1,V2"},{"name":"MemoryGB","value":"220"},{"name":"MaxDataDiskCount","value":"16"},{"name":"CpuArchitectureType","value":"x64"},{"name":"LowPriorityCapable","value":"True"},{"name":"PremiumIO","value":"True"},{"name":"VMDeploymentTypes","value":"IaaS"},{"name":"vCPUsAvailable","value":"18"},{"name":"GPUs","value":"1"},{"name":"vCPUsPerCore","value":"2"},{"name":"CombinedTempDiskAndCachedIOPS","value":"8000"},{"name":"CombinedTempDiskAndCachedReadBytesPerSecond","value":"125829120"},{"name":"CombinedTempDiskAndCachedWriteBytesPerSecond","value":"125829120"},{"name":"CachedDiskBytes","value":"309237645312"},{"name":"UncachedDiskIOPS","value":"12000"},{"name":"UncachedDiskBytesPerSecond","value":"184320000"},{"name":"EphemeralOSDiskSupported","value":"True"},{"name":"EncryptionAtHostSupported","value":"True"},{"name":"CapacityReservationSupported","value":"False"},{"name":"AcceleratedNetworkingEnabled","value":"True"},{"name":"RdmaEnabled","value":"False"},{"name":"MaxNetworkInterfaces","value":"6"}]',N'',N'[]',N'StandardNVADSA10v5Family',N'',N'[{"location":"eastus","zoneDetails":[{"capabilities":[{"name":"UltraSSDAvailable","value":"True"}],"name":["3"]}],"zones":["3"]}]',N'eastus',N'Standard_NV18ads_A10_v5',N'virtualMachines',N'[]',N'NV18ads_A10_v5',N'Standard')
insert into @p3 values(N'azure','2023-01-24 03:04:13.5204127 +00:00',0x10C90A60F7BB82418B8448EBDB9CE568,NULL,N'<AZ_SUB_ID_21>',N'Standard_NV18ads_A10_v5',N'',N'[{"name":"MaxResourceVolumeMB","value":"737280"},{"name":"OSVhdSizeMB","value":"1047552"},{"name":"vCPUs","value":"18"},{"name":"MemoryPreservingMaintenanceSupported","value":"False"},{"name":"HyperVGenerations","value":"V1,V2"},{"name":"MemoryGB","value":"220"},{"name":"MaxDataDiskCount","value":"16"},{"name":"CpuArchitectureType","value":"x64"},{"name":"LowPriorityCapable","value":"True"},{"name":"PremiumIO","value":"True"},{"name":"VMDeploymentTypes","value":"IaaS"},{"name":"vCPUsAvailable","value":"18"},{"name":"GPUs","value":"1"},{"name":"vCPUsPerCore","value":"2"},{"name":"CombinedTempDiskAndCachedIOPS","value":"8000"},{"name":"CombinedTempDiskAndCachedReadBytesPerSecond","value":"125829120"},{"name":"CombinedTempDiskAndCachedWriteBytesPerSecond","value":"125829120"},{"name":"CachedDiskBytes","value":"309237645312"},{"name":"UncachedDiskIOPS","value":"12000"},{"name":"UncachedDiskBytesPerSecond","value":"184320000"},{"name":"EphemeralOSDiskSupported","value":"True"},{"name":"EncryptionAtHostSupported","value":"True"},{"name":"CapacityReservationSupported","value":"False"},{"name":"AcceleratedNetworkingEnabled","value":"True"},{"name":"RdmaEnabled","value":"False"},{"name":"MaxNetworkInterfaces","value":"6"}]',N'',N'[]',N'StandardNVADSA10v5Family',N'',N'[{"location":"northeurope","zoneDetails":[{"capabilities":[{"name":"UltraSSDAvailable","value":"True"}],"name":["1"]}],"zones":["1"]}]',N'northeurope',N'Standard_NV18ads_A10_v5',N'virtualMachines',N'[]',N'NV18ads_A10_v5',N'Standard')
insert into @p3 values(N'azure','2023-01-24 03:04:13.5204127 +00:00',0x32C94F6700ED4F49BE0761C913449D47,NULL,N'<AZ_SUB_ID_23>',N'Standard_NV18ads_A10_v5',N'',N'[{"name":"MaxResourceVolumeMB","value":"737280"},{"name":"OSVhdSizeMB","value":"1047552"},{"name":"vCPUs","value":"18"},{"name":"MemoryPreservingMaintenanceSupported","value":"False"},{"name":"HyperVGenerations","value":"V1,V2"},{"name":"MemoryGB","value":"220"},{"name":"MaxDataDiskCount","value":"16"},{"name":"CpuArchitectureType","value":"x64"},{"name":"LowPriorityCapable","value":"True"},{"name":"PremiumIO","value":"True"},{"name":"VMDeploymentTypes","value":"IaaS"},{"name":"vCPUsAvailable","value":"18"},{"name":"GPUs","value":"1"},{"name":"vCPUsPerCore","value":"2"},{"name":"CombinedTempDiskAndCachedIOPS","value":"8000"},{"name":"CombinedTempDiskAndCachedReadBytesPerSecond","value":"125829120"},{"name":"CombinedTempDiskAndCachedWriteBytesPerSecond","value":"125829120"},{"name":"CachedDiskBytes","value":"309237645312"},{"name":"UncachedDiskIOPS","value":"12000"},{"name":"UncachedDiskBytesPerSecond","value":"184320000"},{"name":"EphemeralOSDiskSupported","value":"True"},{"name":"EncryptionAtHostSupported","value":"True"},{"name":"CapacityReservationSupported","value":"False"},{"name":"AcceleratedNetworkingEnabled","value":"True"},{"name":"RdmaEnabled","value":"False"},{"name":"MaxNetworkInterfaces","value":"6"}]',N'',N'[]',N'StandardNVADSA10v5Family',N'',N'[{"location":"northeurope","zoneDetails":[{"capabilities":[{"name":"UltraSSDAvailable","value":"True"}],"name":["2"]}],"zones":["2"]}]',N'northeurope',N'Standard_NV18ads_A10_v5',N'virtualMachines',N'[]',N'NV18ads_A10_v5',N'Standard')
insert into @p3 values(N'azure','2023-01-24 03:04:13.5204127 +00:00',0xFFE3375944D8664CB44CBF02281C2D61,NULL,N'<AZ_SUB_ID_22>',N'Standard_NV18ads_A10_v5',N'',N'[{"name":"MaxResourceVolumeMB","value":"737280"},{"name":"OSVhdSizeMB","value":"1047552"},{"name":"vCPUs","value":"18"},{"name":"MemoryPreservingMaintenanceSupported","value":"False"},{"name":"HyperVGenerations","value":"V1,V2"},{"name":"MemoryGB","value":"220"},{"name":"MaxDataDiskCount","value":"16"},{"name":"CpuArchitectureType","value":"x64"},{"name":"LowPriorityCapable","value":"True"},{"name":"PremiumIO","value":"True"},{"name":"VMDeploymentTypes","value":"IaaS"},{"name":"vCPUsAvailable","value":"18"},{"name":"GPUs","value":"1"},{"name":"vCPUsPerCore","value":"2"},{"name":"CombinedTempDiskAndCachedIOPS","value":"8000"},{"name":"CombinedTempDiskAndCachedReadBytesPerSecond","value":"125829120"},{"name":"CombinedTempDiskAndCachedWriteBytesPerSecond","value":"125829120"},{"name":"CachedDiskBytes","value":"309237645312"},{"name":"UncachedDiskIOPS","value":"12000"},{"name":"UncachedDiskBytesPerSecond","value":"184320000"},{"name":"EphemeralOSDiskSupported","value":"True"},{"name":"EncryptionAtHostSupported","value":"True"},{"name":"CapacityReservationSupported","value":"False"},{"name":"AcceleratedNetworkingEnabled","value":"True"},{"name":"RdmaEnabled","value":"False"},{"name":"MaxNetworkInterfaces","value":"6"}]',N'',N'[]',N'StandardNVADSA10v5Family',N'',N'[{"location":"japaneast","zoneDetails":[{"capabilities":[{"name":"UltraSSDAvailable","value":"True"}],"name":["2"]}],"zones":["2"]}]',N'japaneast',N'Standard_NV18ads_A10_v5',N'virtualMachines',N'[]',N'NV18ads_A10_v5',N'Standard')

exec sp_executesql N'exec [dbo].[cq_proc_azure_compute_skus] @TVP;',N'@TVP dbo.cq_tbl_azure_compute_skus READONLY',@TVP=@p3

Thanks!

@rafaelrodrigues3092 I’ve updated the code for stored procedures. It’ll be available in the next release of the destination plugin (v2.1.0). Thanks for the suggestion!

@candiduslynx after a fresh run w/ the v2.0.0 of the plugin I got an updated list of tables w/ PK violations

azure_cdn_managed_rule_sets
azure_support_services
azure_authorization_provider_operations_metadata azure_security_assessments_metadata
azure_policy_set_definitions
azure_compute_skus
azure_eventgrid_topic_types
azure_network_bgp_service_communities
azure_policy_data_policy_manifests
azure_cdn_edge_nodes
azure_frontdoor_managed_rule_sets
azure_security_secure_score_control_definitions azure_reservations_reservation
azure_policy_definitions
azure_advisor_recommendation_metadata
azure_security_topology
azure_authorization_role_assignments

An interesting observation is that it seems that some of the original tables are not part of this updated list. FYI, I have RSCI enabled on my database ALTER DATABASE "<db_name>" SET READ_COMMITTED_SNAPSHOT ON and in terms of scale, I am collecting data from 23 Azure subscriptions.

For the stored procedures, may I suggest the insert be done using a LEFT JOIN instead?

...
FROM @TVP AS [src]
LEFT JOIN [dbo].[azure_compute_skus] AS [tgt]
	ON [tgt].[id] = [src].[id]
WHERE
	[tgt].[id] IS NULL

Hi @rafaelrodrigues3092! Thank you for the report. I’ve extracted the Unicode issue into a separate issue (#7001). The PK violation will be fixed in this one.