From d0cd4aed5a795400841bb7cdbd4555e32fd76ce4 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Thu, 11 Jun 2020 08:20:03 -0700 Subject: [PATCH] (redis cobra bots) xadd with maxlen + fix bug in xadd client implementation and ws cobra metrics to redis command argument parsing --- docs/CHANGELOG.md | 4 +++ ixbots/ixbots/IXCobraMetricsToRedisBot.cpp | 34 +++++++++++++--------- ixredis/ixredis/IXRedisClient.cpp | 11 +++++-- ixredis/ixredis/IXRedisClient.h | 5 +++- ixwebsocket/IXWebSocketVersion.h | 2 +- ws/ws.cpp | 2 +- 6 files changed, 38 insertions(+), 20 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index d74ade86..f1fad782 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All changes to this project will be documented in this file. +## [9.7.0] - 2020-06-11 + +(redis cobra bots) xadd with maxlen + fix bug in xadd client implementation and ws cobra metrics to redis command argument parsing + ## [9.6.9] - 2020-06-10 (redis cobra bots) update the cobra to redis bot to use the bot framework, and change it to report fps metrics into redis streams. diff --git a/ixbots/ixbots/IXCobraMetricsToRedisBot.cpp b/ixbots/ixbots/IXCobraMetricsToRedisBot.cpp index f95d7125..61fee3dd 100644 --- a/ixbots/ixbots/IXCobraMetricsToRedisBot.cpp +++ b/ixbots/ixbots/IXCobraMetricsToRedisBot.cpp @@ -45,33 +45,39 @@ namespace ix slowFrames += frameRateHistogramCounts[6].asInt(); slowFrames += frameRateHistogramCounts[7].asInt(); + // + // XADD without a device id + // std::stringstream ss; ss << msg["id"].asString() << "_slow_frames" << "." << msg["device"]["game"].asString() << "." << msg["device"]["os_name"].asString() << "." << removeSpaces(msg["data"]["Tag"].asString()); + int maxLen; + maxLen = 100000; std::string id = ss.str(); std::string errMsg; - if (redisClient.xadd(id, std::to_string(slowFrames), errMsg).empty()) + if (redisClient.xadd(id, std::to_string(slowFrames), maxLen, errMsg).empty()) { CoreLogger::info(std::string("redis xadd error: ") + errMsg); } - if (deviceId == "N841AP" || deviceId == "SM-N960U") - { - ss.str(""); // reset the stringstream - ss << msg["id"].asString() << "_slow_frames_by_device" << "." - << deviceId << "." - << msg["device"]["game"].asString() << "." - << msg["device"]["os_name"].asString() << "." - << removeSpaces(msg["data"]["Tag"].asString()); + // + // XADD with a device id + // + ss.str(""); // reset the stringstream + ss << msg["id"].asString() << "_slow_frames_by_device" << "." + << deviceId << "." + << msg["device"]["game"].asString() << "." + << msg["device"]["os_name"].asString() << "." + << removeSpaces(msg["data"]["Tag"].asString()); - std::string id = ss.str(); - if (redisClient.xadd(id, std::to_string(slowFrames), errMsg).empty()) - { - CoreLogger::info(std::string("redis xadd error: ") + errMsg); - } + id = ss.str(); + maxLen = 1000; + if (redisClient.xadd(id, std::to_string(slowFrames), maxLen, errMsg).empty()) + { + CoreLogger::info(std::string("redis xadd error: ") + errMsg); } return true; diff --git a/ixredis/ixredis/IXRedisClient.cpp b/ixredis/ixredis/IXRedisClient.cpp index c20c055a..7acf6610 100644 --- a/ixredis/ixredis/IXRedisClient.cpp +++ b/ixredis/ixredis/IXRedisClient.cpp @@ -251,12 +251,16 @@ namespace ix } std::string RedisClient::prepareXaddCommand(const std::string& stream, - const std::string& message) + const std::string& message, + int maxLen) { std::stringstream ss; - ss << "*5\r\n"; + ss << "*8\r\n"; ss << writeString("XADD"); ss << writeString(stream); + ss << writeString("MAXLEN"); + ss << writeString("~"); + ss << writeString(std::to_string(maxLen)); ss << writeString("*"); ss << writeString("field"); ss << writeString(message); @@ -266,6 +270,7 @@ namespace ix std::string RedisClient::xadd(const std::string& stream, const std::string& message, + int maxLen, std::string& errMsg) { errMsg.clear(); @@ -276,7 +281,7 @@ namespace ix return std::string(); } - std::string command = prepareXaddCommand(stream, message); + std::string command = prepareXaddCommand(stream, message, maxLen); bool sent = _socket->writeBytes(command, nullptr); if (!sent) diff --git a/ixredis/ixredis/IXRedisClient.h b/ixredis/ixredis/IXRedisClient.h index 34895efd..00b7c59b 100644 --- a/ixredis/ixredis/IXRedisClient.h +++ b/ixredis/ixredis/IXRedisClient.h @@ -40,9 +40,12 @@ namespace ix // XADD std::string xadd(const std::string& channel, const std::string& message, + int maxLen, std::string& errMsg); - std::string prepareXaddCommand(const std::string& stream, const std::string& message); + std::string prepareXaddCommand(const std::string& stream, + const std::string& message, + int maxLen); std::string readXaddReply(std::string& errMsg); diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index 0f714205..514a2023 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "9.6.9" +#define IX_WEBSOCKET_VERSION "9.7.0" diff --git a/ws/ws.cpp b/ws/ws.cpp index 30d65a3d..50b89320 100644 --- a/ws/ws.cpp +++ b/ws/ws.cpp @@ -370,7 +370,7 @@ int main(int argc, char** argv) cobra2redisApp->add_option("--port", redisPort, "Redis port"); cobra2redisApp->add_flag("-v", verbose, "Verbose"); addTLSOptions(cobra2redisApp); - addCobraConfig(cobra2redisApp); + addCobraBotConfig(cobra2redisApp); CLI::App* snakeApp = app.add_subcommand("snake", "Snake server"); snakeApp->fallthrough();