Skip to content
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 indexes not created correctly on Azure CosmosDB implementation of MongoDB #1868

Open
AndrewNiven opened this issue Jul 17, 2023 · 0 comments

Comments

@AndrewNiven
Copy link

Issue Summary

During setup, Alerta creates database collections and sets appropriate indexes on them. The MongoDB code to create indexes is found here: https://github.com/alerta/alerta/blob/master/alerta/database/backends/mongodb/base.py#L50

When run against an Azure CosmosDB implementation of MongoDB, the second command (db.alerts.create_index([('$**', TEXT)])) fails. This means that this index, and all the indexes after it, are not created. The log output is:

2023-07-17 16:36:19,966 DEBG 'uwsgi' stdout output:
2023-07-17 16:36:19,966 alerta.app[27]: [WARNING] 'text' is not supported, full error: {'ok': 0.0, 'errmsg': "'text' is not supported", 'code': 115, 'codeName': 'CommandNotSupported'} [in /venv/lib/python3.7/site-packages/alerta/database/base.py:51]

Environment

OS: Linux

API version: 8.5.0

Deployment: Azure Kubernetes Service

Database: Azure CosmosDB

Server config: Output of config endpoint: alerta-config.txt

web UI version: 8.5.0

CLI version: 8.5.0

To Reproduce

Deploy Alerta configured to use Azure CosmosDB's implementation of MongoDB. Observe that indexes are not correctly configured.

Alternatively, this can be recreated manually. Set up an Azure CosmosDB account, obtain a connection string, template it into the following python snippet, and run the snippet:

import pymongo

CONNECTION_STRING="<AZURE_COSMOSDB_CONNECTION_STRING>"
DATABASE_NAME="test"
COLLECTION_NAME="test"

my_client = pymongo.MongoClient(CONNECTION_STRING)

db = my_client[DATABASE_NAME]

alerts = db[COLLECTION_NAME]

alerts.create_index([('$**', pymongo.TEXT)])

This fails with the same error as Alerta:

pymongo.errors.OperationFailure: 'text' is not supported, full error: {'ok': 0.0, 'errmsg': "'text' is not supported", 'code': 115, 'codeName': 'CommandNotSupported'}

Expected behavior

All indexes are created normally at startup.

Additional context

The actual bug here is in Azure CosmosDB's implementation of MongoDB, rather than in Alerta. I'm just raising this here to flag that Alerta doesn't work as expected with that database.

Alerta is still usable with Azure CosmosDB: the most important index, which enforces uniqueness on alerts, is applied normally, as this is done before the failed index creation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant