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

How to persist bot state to CosmosDB using CI/CD? #8864

Closed
nicolas-martin-dte opened this issue Dec 20, 2021 · 7 comments
Closed

How to persist bot state to CosmosDB using CI/CD? #8864

nicolas-martin-dte opened this issue Dec 20, 2021 · 7 comments
Assignees
Labels
Bot Services Required for internal Azure reporting. Do not delete. Do not change color. customer-replied-to Required for internal reporting. Do not delete. customer-reported Required for internal Azure reporting. Do not delete.

Comments

@nicolas-martin-dte
Copy link

nicolas-martin-dte commented Dec 20, 2021

We have a Composer bot that we are not deploying manually via a publish profile, but instead followed the documentation here:
https://docs.microsoft.com/en-us/composer/how-to-cicd

However, that documentation does not describe how to get the Composer bot to write bot state to an existing CosmosDB container. I have tried setting app settings in the Azure App Service for cosmosDb:authKey, cosmosDb:cosmosDbEndpoint, cosmosDb:containerId, etc., and equivalents replacing ":" with "__", but to no avail. We simply never see state in CosmosDB. I figured these app settings would be valid per the documentation here showing how the app settings are defined in the publish profile (plus, this is how the C# templates structure the app settings OOTB as well): https://docs.microsoft.com/en-us/composer/how-to-provision-azure-resources#share-resource-details

Incidentally, I have also tried setting these app settings in Composer's configuration advanced editor locally to write to my CosmosDB Emulator but also to no avail.

Please don't tell me to configure the publish profile as the answer - that is not the answer for many enterprise scenarios and the Bot Framework team should well know it. Similarly, please don't simply link me to Bot Framework C# documentation about setting bot state, because I've authored several C# Bot Framework solutions and know very, very, very well how to get that to work.

@nicolas-martin-dte nicolas-martin-dte added the Needs-triage A new issue that require triage label Dec 20, 2021
@dmvtech dmvtech added Bot Services Required for internal Azure reporting. Do not delete. Do not change color. customer-reported Required for internal Azure reporting. Do not delete. labels Dec 20, 2021
@dmvtech
Copy link
Collaborator

dmvtech commented Dec 20, 2021

Hi @nicolas-martin-dte

Can you confirm the runtimeSettings:storage set to the name of your cosmosDB?:

  "runtimeSettings": {
    "storage": "cosmosDB",
  },

@dmvtech dmvtech added the customer-replied-to Required for internal reporting. Do not delete. label Dec 20, 2021
@nicolas-martin-dte
Copy link
Author

I can confirm that configuration was not set because I didn't see that documented anywhere. Even now Googling for that isn't yielding anything.

Nonetheless, I tried adding Azure App Service app setting named runtimeSettings:storage or runtimeSettings__storage with value cosmosDB and neither worked. I would at least feel better to get runtime exceptions telling me I have bot state misconfigured or something.

How might I know all the configuration settings that are available to the Bot Framework Composer's runtime? If I'm to assume that Azure App Service app settings get loaded by the Bot Framework Composer's runtime, I have to believe there is a combination of settings to make it work.

@nicolas-martin-dte
Copy link
Author

@dmvtech - I think I initially misread your message. The runtimeSettings:storage setting is to be the name of the Cosmos DB? Do you mean the CosmosDB account, or the actual database ID within the account? Or is it to be the full connection string? Only giving a database name (id) doesn't seem like it could be sufficient... I could use a clarifying explanation please.

@nicolas-martin-dte
Copy link
Author

Ok, finally got this working. It seems value CosmosDbPartitionedStorage is the proper incantation needed for runtimeSettings:storage with the connection details defined in a config section of the same name.

Here's the snippet from the ARM template's app settings I have that is now finally writing bot state to CosmosDB:

            "CosmosDbPartitionedStorage:authKey": "[concat('@Microsoft.KeyVault(SecretUri=', reference(resourceId('Microsoft.KeyVault/vaults/secrets', parameters('keyVaultName'), 'CosmosDbAuthKey')).secretUriWithVersion, ')')]",
            "CosmosDbPartitionedStorage:containerId": "[variables('cosmosDbBotStateContainerName')]",
            "CosmosDbPartitionedStorage:cosmosDBEndpoint": "[variables('cosmosDbBotStateEndpoint')]",
            "CosmosDbPartitionedStorage:databaseId": "[variables('cosmosDbBotStateDatabaseName')]",
            "runtimeSettings:storage": "CosmosDbPartitionedStorage",

I only found this because I created another bot from a template and provisioned/deployed to a personal Azure subscription and dug into the publish files to find how it was actually configured in the settings file from the publish profile.

Please document this sort of thing. All the various app settings / configuration options as loaded by Composer should be fully documented.

@dmvtech
Copy link
Collaborator

dmvtech commented Dec 21, 2021

Thanks @nicolas-martin-dte

I think I initially misread your message. The runtimeSettings:storage setting is to be the name of the Cosmos DB? Do you mean the CosmosDB account, or the actual database ID within the account? Or is it to be the full connection string? Only giving a database name (id) doesn't seem like it could be sufficient... I could use a clarifying explanation please.

This would be name of the configuration node. I think it can be anything, but I would need to test to confirm (you may be able to do so before I could get to it). So, for example, either of these should work:

{
    "runtimeSettings" : {
        "storage": "CosmosDbPartitionedStorage"
    },
    "CosmosDbPartitionedStorage": {
        "authKey": "",
        "containerId": "",
        "cosmosDBEndpoint": "",
        "databaseId": ""
    }
}

OR

{
    "runtimeSettings" : {
        "storage": "CosmosDB "
    },
    "CosmosDB ": {
        "authKey": "",
        "containerId": "",
        "cosmosDBEndpoint": "",
        "databaseId": ""
    }
}

@JonathanFingold for docs input.

@dmvtech dmvtech self-assigned this Dec 21, 2021
@dmvtech dmvtech removed the Needs-triage A new issue that require triage label Dec 21, 2021
@nicolas-martin-dte
Copy link
Author

I tried the latter with no success. Maybe I had a case mismatch or something, but it didn't appear to work for me.

@dmvtech
Copy link
Collaborator

dmvtech commented Dec 30, 2021

Yeah, my bad. CosmosDB was an older, allowed config option. Looks like it is only CosmosDbPartitionedStorage now. Glad you got it working.

@dmvtech dmvtech closed this as completed Dec 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bot Services Required for internal Azure reporting. Do not delete. Do not change color. customer-replied-to Required for internal reporting. Do not delete. customer-reported Required for internal Azure reporting. Do not delete.
Projects
None yet
Development

No branches or pull requests

2 participants