Database indexes not created correctly on Azure CosmosDB implementation of MongoDB
Opened this issue · 0 comments
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.