负载测试 Bot builder 机器人

Load testing Bot builder bot

更新

使用模拟器作为 channelId 并更新到 SDK 3.13.1 适合我。


问题描述

我尝试了 this link 中提到的步骤。这有两个部分。一是创建令牌,二是向机器人发送消息。 POSTMAN 请求导致 500 Internal Server Error 和 ERROR: ChatConnector: receive - 代码中的签名密钥或 OpenId 元数据文档无效。

代码示例

  1. 创建代币

     curl -X POST  https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token   -H 'cache-control: no-cache' -H 'content-type: application/x-www-form-urlencoded'  -H 'postman-token: 792660ab-b1aa-0cbd-edab-9b3847c170d5'  -d 'grant_type=client_credentials&client_id=8c082f92-fb38-4841-a29f-339eb315f7aa&client_secret=vxcihBT2679%7C(%23puEXBPT1!&scope=8c082f92-fb38-4841-a29f-339eb315f7aa%2F.default'
    
  2. 发送消息

     curl -X POST https://1c36f336.ngrok.io/api/messages -H 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ing0Nzh4eU9wbHNNMUg3TlhrN1N4MTd4MXVwYyJ9.eyJhdWQiOiI4YzA4MmY5Mi1mYjM4LTQ4NDEtYTI5Zi0zMzllYjMxNWY3YWEiLCJpc3MiOiJodHRwczovL2xvZ2luLm1pY3Jvc29mdG9ubGluZS5jb20vZDZkNDk0MjAtZjM5Yi00ZGY3LWExZGMtZDU5YTkzNTg3MWRiL3YyLjAiLCJpYXQiOjE1MTIxOTg2NjcsIm5iZiI6MTUxMjE5ODY2NywiZXhwIjoxNTEyMjAyNTY3LCJhaW8iOiJZMk5nWUZEOHRySzgvZk9XcDF2L1BMM2JibnRGRGdBPSIsImF6cCI6IjhjMDgyZjkyLWZiMzgtNDg0MS1hMjlmLTMzOWViMzE1ZjdhYSIsImF6cGFjciI6IjEiLCJ0aWQiOiJkNmQ0OTQyMC1mMzliLTRkZjctYTFkYy1kNTlhOTM1ODcxZGIiLCJ1dGkiOiJXLWdYbXpPSkxVYWdzSFZUbXBJd0FBIiwidmVyIjoiMi4wIn0.G705tzQIU5Mh6IROtXkIwm8Q9AKZ_q-VOtJuuozqP-ekhWoKc0HpcdhgBlnaMsMHKoM0RWhUlXn27xCfK46vEE9IZlkjcAh7huhvlWNtW8IP5w7QiL3JCSTYKCtBXZq-VKeWctNWR9M8Y9Ry4dyiEdcDMcHWrbOUqR6nXvlwG76GSR4YilqzMWdSW6t5Pep3hwOw07DSargYP0pDAnWAg3pWHnhcJ185533I1VVXEIuc_CK-RmP9qhUAScEbYkpp_7l75bVWzxKv-3E1UOG4SBj6UzfH47X5kwz_njn1kAJcrqBvP3s_CjS4qUdDSNARtxGZ3UQWj49UBKosqar0dg' -H 'cache-control: no-cache' -H 'content-type: application/json' -H 'postman-token: 3a74ce00-2da7-d674-5e4c-083f54ed30ff' -d '{ "type": "message", "id": "mid.$cAAGEkG8MNm1mOEBe-lgBvsWZbQUc", "channelId" : "test",  "conversation": { "id": "100023023852067-526013297749070"}, "from": { "id": "100023023852067" }, "recipient": { "id": "526013297749070" },  "serviceUrl": "https://1c36f336.ngrok.io", "text": "Hi message from postman !!!" }'
    

复制步骤

  1. 使用上面提到的两个curl请求。这应该会导致上述问题。

预期行为

POSTMAN 请求应该导致 202 Accepted 和机器人接收消息。我是不是遗漏了什么或者过程中有什么问题?我在负载测试中看到 some issues ,但其中 none 有帮助。

实际结果

POSTMAN 请求导致 500 内部服务器错误和错误:ChatConnector:接收 - 代码中的签名密钥或 OpenId 元数据文档无效。

不确定这是否有帮助,但如果您在负载测试的每个请求中使用相同的"fromId",它可能是相关的。

以前我遇到过类似的问题,要求我在每个请求中使用唯一的 "fromId",否则一系列快速连续的请求开始失败。

我在 github 上提出了这个问题,虽然它说 "followed up offline" 和 "problem was with the bot code",但实际上是因为在每个请求中使用相同的 "fromId"。

问题在这里:https://github.com/Microsoft/BotBuilder/issues/1176

我能够在以下时间之后让它工作:

1) 使用 botbuilder-azure 向机器人添加自定义状态客户端

2) 公开消息接收器,用于接收机器人响应

3) 将 channelId 更改为 "emulator"(显然节点 sdk 不处理 'test' 频道)

curl -X POST  https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token -H "content-type: application/x-www-form-urlencoded" -d "grant_type=client_credentials&client_id=MyMicrosoftAppId&client_secret=MyMicrosoftAppPassword&scope=MyMicrosoftAppId%2F.default"

curl -X POST https://e84a2f49.ngrok.io/api/messages -H "authorization: Bearer TokenFromPreviousCall" -d "{ \"type\": \"message\", \"id\": \"mid.$cAAGEkG8MNm1mOEBe-lgBvsWZbQUc\", \"channelId\" : \"emulator\",  \"conversation\": { \"id\": \"100023023852067-526013297749070\"}, \"from\": { \"id\": \"100023023852067\" }, \"recipient\": { \"id\": \"526013297749070\" },  \"serviceUrl\": \"https://e84a2f49.ngrok.io\", \"text\": \"Hi message from postman !!!\" }"

这是应用程序,供参考:

var restify = require('restify');
var builder = require('botbuilder');
var azure = require('botbuilder-azure');

var sqlConfig = {
    userName: 'SqlServerUserId',
    password: 'SqlServerPassword',
    server: 'mySqlServer.net',
    enforceTable: true, 
    options: {
        database: 'BotDatabaseName',
        table: 'BotDataTableName',
        encrypt: true,
        rowCollectionOnRequestCompletion: true
    }
}

var sqlClient = new azure.AzureSqlClient(sqlConfig);
var sqlStorage = new azure.AzureBotStorage({ gzipData: false }, sqlClient);

var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3980, function () {
    console.log('%s listening to %s', server.name, server.url);
});

var connector = new builder.ChatConnector({
    appId: "MyAppId",
    appPassword: "MyAppPassword" 
});

server.post('/api/messages', connector.listen());

var bot = new builder.UniversalBot(connector, function (session) {
    session.send("You said: %s", session.message.text);
}).set('storage', sqlStorage);;

//message sink 
server.post("/v3/conversations/:conversationId/activities/:activityId", function(Request, Response, next) {
    next();
});

添加 extended 字段后,我遇到了同样的错误。 不确定这有什么关系,但替换

server.use(bodyParser.urlencoded({ extended: true }));

至:

server.use(bodyParser.urlencoded());

已解决问题。