CosmosDB: Sql api is not supported for this database account

I’m submitting a…

  • [ ] Regression (a behavior that stopped working in a new release)
  • [ X ] Bug report
  • [ ] Performance issue
  • [ ] Documentation issue or request

Current behavior

I am trying to setup Squidex with CosmosDb, which in theory should work, as the CosmosDb implementation is still available within the source code, but now it is failing, as Azure CosmosDb APIs were recently updated.
All the configuration settings are setup properly according to Install Azure
When the application is launched, the CosmosDb database and collections get created well, however, when the Migrations kick start on the back-end, the following happens:

{
  "logLevel": "Fatal",
  "action": "Migration",
  "status": "Failed",
  "migrator": "Migrate_01.Migrations.RebuildSnapshots",
  "exception": {
    "type": "Microsoft.Azure.Documents.DocumentClientException",
    "message": "Sql api is not supported for this database account\r\nActivityId: f1e737ab-eda0-4b3b-bba9-316de7e74360, Microsoft.Azure.Documents.Common/2.7.0, Windows/10.0.17134 documentdb-netcore-sdk/2.7.0",
    "stackTrace": "   at Microsoft.Azure.Documents.GatewayStoreClient.ParseResponseAsync(HttpResponseMessage responseMessage, JsonSerializerSettings serializerSettings, DocumentServiceRequest request)\r\n   at Microsoft.Azure.Documents.GatewayStoreClient.InvokeAsync(DocumentServiceRequest request, ResourceType resourceType, Uri physicalAddress, CancellationToken cancellationToken)\r\n   at Microsoft.Azure.Documents.GatewayStoreModel.ProcessMessageAsync(DocumentServiceRequest request, CancellationToken cancellationToken)\r\n   at Microsoft.Azure.Documents.Client.DocumentClient.ProcessRequestAsync(DocumentServiceRequest request, IDocumentClientRetryPolicy retryPolicyInstance, CancellationToken cancellationToken)\r\n   at Microsoft.Azure.Documents.Client.DocumentClient.ProcessRequestAsync(String verb, DocumentServiceRequest request, IDocumentClientRetryPolicy retryPolicyInstance, CancellationToken cancellationToken, String testAuthorization)\r\n   at Microsoft.Azure.Documents.Query.DocumentQueryExecutionContextBase.ExecuteQueryRequestInternalAsync(DocumentServiceRequest request, IDocumentClientRetryPolicy retryPolicyInstance, CancellationToken cancellationToken)\r\n   at Microsoft.Azure.Documents.Query.DocumentQueryExecutionContextBase.ExecuteQueryRequestAsync(DocumentServiceRequest request, IDocumentClientRetryPolicy retryPolicyInstance, CancellationToken cancellationToken)\r\n   at Microsoft.Azure.Documents.Query.DefaultDocumentQueryExecutionContext.ExecuteOnceAsync(IDocumentClientRetryPolicy retryPolicyInstance, CancellationToken cancellationToken)\r\n   at Microsoft.Azure.Documents.Query.DefaultDocumentQueryExecutionContext.<>c__DisplayClass8_0.<<ExecuteInternalAsync>b__0>d.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at Microsoft.Azure.Documents.BackoffRetryUtility`1.ExecuteRetryAsync(Func`1 callbackMethod, Func`3 callShouldRetry, Func`1 inBackoffAlternateCallbackMethod, TimeSpan minBackoffForInBackoffCallback, CancellationToken cancellationToken, Action`1 preRetryCallback)\r\n   at Microsoft.Azure.Documents.ShouldRetryResult.ThrowIfDoneTrying(ExceptionDispatchInfo capturedException)\r\n   at Microsoft.Azure.Documents.BackoffRetryUtility`1.ExecuteRetryAsync(Func`1 callbackMethod, Func`3 callShouldRetry, Func`1 inBackoffAlternateCallbackMethod, TimeSpan minBackoffForInBackoffCallback, CancellationToken cancellationToken, Action`1 preRetryCallback)\r\n   at Microsoft.Azure.Documents.Query.DefaultDocumentQueryExecutionContext.ExecuteInternalAsync(CancellationToken token)\r\n   at Microsoft.Azure.Documents.Query.DocumentQueryExecutionContextBase.ExecuteNextAsync(CancellationToken cancellationToken)\r\n   at Microsoft.Azure.Documents.Query.ProxyDocumentQueryExecutionContext.ExecuteNextAsync(CancellationToken token)\r\n   at Microsoft.Azure.Documents.Linq.DocumentQuery`1.ExecuteNextPrivateAsync[TResponse](CancellationToken cancellationToken)\r\n   at Squidex.Infrastructure.EventSourcing.FilterExtensions.QueryAsync[T](IQueryable`1 queryable, Func`2 handler, CancellationToken ct) in C:\\Dev\\squidex-3.4.0\\src\\Squidex.Infrastructure.Azure\\EventSourcing\\FilterExtensions.cs:line 52\r\n   at Squidex.Infrastructure.EventSourcing.CosmosDbEventStore.QueryAsync(Func`2 callback, StreamPosition lastPosition, SqlQuerySpec query, EventPredicate filterExpression, CancellationToken ct) in C:\\Dev\\squidex-3.4.0\\src\\Squidex.Infrastructure.Azure\\EventSourcing\\CosmosDbEventStore_Reader.cs:line 113\r\n   at Migrate_01.Rebuilder.RebuildManyAsync[TState,TGrain](String filter, CancellationToken ct) in C:\\Dev\\squidex-3.4.0\\tools\\Migrate_01\\Rebuilder.cs:line 109\r\n   at Migrate_01.Migrations.RebuildSnapshots.UpdateAsync() in C:\\Dev\\squidex-3.4.0\\tools\\Migrate_01\\Migrations\\RebuildSnapshots.cs:line 24\r\n   at Squidex.Infrastructure.Migrations.Migrator.MigrateAsync(CancellationToken ct) in C:\\Dev\\squidex-3.4.0\\src\\Squidex.Infrastructure\\Migrations\\Migrator.cs:line 78"
  },
  "app": {
    "name": "Squidex",
    "version": "1.0.0.0",
    "sessionId": "9015772e-7f21-495a-bd38-8872cea8001c"
  },
  "timestamp": "2019-10-08T03:36:12Z"
}

Which leads to the failure:

{
  "logLevel": "Error",
  "message": "RunClientMessagePump has thrown exception",
  "eventId": {
    "id": 100326
  },
  "exception": {
    "type": "System.OperationCanceledException",
    "message": "The operation was canceled.",
    "stackTrace": "   at System.Collections.Concurrent.BlockingCollection`1.TryTakeWithNoTimeValidation(T& item, Int32 millisecondsTimeout, CancellationToken cancellationToken, CancellationTokenSource combinedTokenSource)\r\n   at System.Collections.Concurrent.BlockingCollection`1.TryTake(T& item, Int32 millisecondsTimeout, CancellationToken cancellationToken)\r\n   at System.Collections.Concurrent.BlockingCollection`1.Take(CancellationToken cancellationToken)\r\n   at Orleans.Runtime.HostedClient.RunClientMessagePump() in D:\\build\\agent\\_work\\23\\s\\src\\Orleans.Runtime\\Core\\HostedClient.cs:line 0"
  },
  "app": {
    "name": "Squidex",
    "version": "1.0.0.0",
    "sessionId": "9015772e-7f21-495a-bd38-8872cea8001c"
  },
  "timestamp": "2019-10-08T03:36:15Z",
  "category": "Orleans.Runtime.HostedClient"
}

Expected behavior

The Migrations should have worked.

Minimal reproduction of the problem

Hook up Squidex to CosmosDb and this behaviour should happen.

Environment

  • [ ] Self hosted with docker
  • [ ] Self hosted with IIS
  • [ X ] Self hosted with Azure
  • [ ] Self hosted with other version
  • [ ] Cloud version

Version: 3.4.0

Browser:

  • [ ] Chrome (desktop)
  • [ ] Chrome (Android)
  • [ ] Chrome (iOS)
  • [ ] Firefox
  • [ ] Safari (desktop)
  • [ ] Safari (iOS)
  • [ ] IE
  • [ ] Edge
  • [ X ] Not a browser thing

I have decided not to support CosmosDB anymore a few months ago. Here is why:

In theory it should work out of the box, but they have changed something and you need 2 accounts now: One for event store and another one for the MongoDB interface. This makes it more expensive.

By default you will have provisioning per collection then and this means the costs explode. Without any configuration you will have to pay around 400€ per month. I have forgotten it twice to delete my test account and I was shocked how expensive it was.

You have to configure it very carefully then or you change to provisioning per database, which would be the better approach. But to get this working you need partition keys in all collections and you need to configure it carefully. So an out of the box setup is difficult.

Thank you for the reply. In this case we are definitely not using CosmosDb.