如何使用反向代理机制模拟 Azure Cosmos DB 和 Azure Redis 区域故障场景?

问题描述

为了模拟区域故障,在“OnBeforeResponse”函数下创建了自定义规则下的 Fiddler。

我能够成功拦截对 Azure 存储帐户 的 http 调用,并且能够注入失败的响应,而对于 Azure Cosmos DB 调用的 https 调用我无法拦截,为什么?我错过了什么吗?

我什至无法拦截 Azure redis 相关调用,但我可以理解 Redis 不使用 HTTP 通信的原因,但为什么我无法拦截 Azure Cosmos DB 调用的 https 调用,不知道,需要专业意见。

还需要关于如何拦截Redis调用和注入人为故障响应代码的建议?模拟 Azure Redis 区域故障情况。

         static function OnBeforeResponse(oSession: Session) {
                if (m_Hide304s && oSession.responseCode == 304) {
                    oSession["ui-hide"] = "true";
                }
    
                // az storage account call manipulated response
                if (oSession.hostname == "mystorageaccount.blob.core.windows.net")
                {
                    oSession.responseCode = 503;
                }
    
                // az cosmos db account call manipulated response -- not working
                if (oSession.hostname == "mydocdb.documents.azure.com")
                {
                    oSession.responseCode = 503;
                }
                // az redis call manipulated response -- not working
                if (oSession.hostname == "myrediscache.redis.cache.windows.net")
                {
                    oSession.responseCode = 503;
                }       

Sample network traffic captured via fiddler:

P.S: 目前我们使用的是 cosmos db SDK v2 cosmos db SDK v2 默认使用 HTTP 还是 TCP?根据提琴手的说法,它是 HTTP。

解决方法

我不知道 Redis 是做什么的,但您可以通过手动将区域故障转移到辅助区域来在 Cosmos 中进行故障转移测试。这可以在门户中或使用 PS、CLI、模板或使用 Azure 管理 SDK 来完成。

可以在此处了解更多信息,Perform a manual failover on a Cosmos DB account

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...