diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index dc98fd28..0a8f418d 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.8.4] - 2020-06-26 + +(cobra bots) remove bots which is not required now that we can use Python extensions + ## [9.8.3] - 2020-06-25 (cmake) new python code is optional and enabled at cmake time with -DUSE_PYTHON=1 diff --git a/ixbots/CMakeLists.txt b/ixbots/CMakeLists.txt index dc424a44..2debd82b 100644 --- a/ixbots/CMakeLists.txt +++ b/ixbots/CMakeLists.txt @@ -8,7 +8,6 @@ set (IXBOTS_SOURCES ixbots/IXCobraToSentryBot.cpp ixbots/IXCobraToStatsdBot.cpp ixbots/IXCobraToStdoutBot.cpp - ixbots/IXCobraMetricsToStatsdBot.cpp ixbots/IXCobraMetricsToRedisBot.cpp ixbots/IXCobraToPythonBot.cpp ixbots/IXStatsdClient.cpp @@ -20,7 +19,6 @@ set (IXBOTS_HEADERS ixbots/IXCobraToSentryBot.h ixbots/IXCobraToStatsdBot.h ixbots/IXCobraToStdoutBot.h - ixbots/IXCobraMetricsToStatsdBot.h ixbots/IXCobraMetricsToRedisBot.h ixbots/IXCobraToPythonBot.h ixbots/IXStatsdClient.h diff --git a/ixbots/ixbots/IXCobraMetricsToStatsdBot.cpp b/ixbots/ixbots/IXCobraMetricsToStatsdBot.cpp deleted file mode 100644 index cb498727..00000000 --- a/ixbots/ixbots/IXCobraMetricsToStatsdBot.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/* - * IXCobraMetricsToStatsdBot.cpp - * Author: Benjamin Sergeant - * Copyright (c) 2020 Machine Zone, Inc. All rights reserved. - */ - -#include "IXCobraMetricsToStatsdBot.h" - -#include "IXCobraBot.h" -#include "IXStatsdClient.h" -#include -#include -#include -#include -#include -#include -#include -#include - - -namespace -{ - std::string removeSpaces(const std::string& str) - { - std::string out(str); - out.erase( - std::remove_if(out.begin(), out.end(), [](unsigned char x) { return std::isspace(x); }), - out.end()); - - return out; - } -} - -namespace ix -{ - bool processNetRequestMetricsEvent(const Json::Value& msg, - StatsdClient& statsdClient) - { - auto durationMs = msg["data"]["duration_ms"].asUInt64(); - auto size = msg["data"]["size"].asUInt64(); - auto controller = msg["data"]["params"]["_controller"].asString(); - auto action = msg["data"]["params"]["_action"].asString(); - auto game = msg["device"]["game"].asString(); - auto status = msg["data"]["status"].asInt(); - auto osName = msg["device"]["os_name"].asString(); - - bool valid = true; - valid |= controller == "game_session" && action == "start"; - valid |= controller == "asset" && action == "manifest"; - valid |= controller == "iso_login" && action == "post_start_session"; - if (!valid) return false; - - // We only worry about successful requests - if (status != 200) return false; - - std::stringstream ss; - ss << msg["id"].asString() << "." - << "v1." - << game << "." - << osName << "." - << controller << "." - << action; - - std::string id = ss.str(); - - statsdClient.gauge(id + ".duration_ms", durationMs); - statsdClient.gauge(id + ".size", size); - - return true; - } - - bool processPerfMetricsEvent(const Json::Value& msg, - StatsdClient& statsdClient) - { - auto frameRateHistogram = msg["data"]["FrameRateHistogram"]; - auto frameTimeTotal = msg["data"]["FrameTimeTotal"].asFloat(); - - auto gt_60 = 100 * frameRateHistogram[0].asFloat() / frameTimeTotal; - auto lt_60 = 100 * frameRateHistogram[1].asFloat() / frameTimeTotal; - auto lt_30 = 100 * frameRateHistogram[2].asFloat() / frameTimeTotal; - auto lt_20 = 100 * frameRateHistogram[3].asFloat() / frameTimeTotal; - auto lt_15 = 100 * frameRateHistogram[4].asFloat() / frameTimeTotal; - auto lt_12 = 100 * frameRateHistogram[5].asFloat() / frameTimeTotal; - auto lt_10 = 100 * frameRateHistogram[6].asFloat() / frameTimeTotal; - auto lt_08 = 100 * frameRateHistogram[7].asFloat() / frameTimeTotal; - - std::stringstream ss; - ss << msg["id"].asString() << "." - << msg["device"]["game"].asString() << "." - << msg["device"]["os_name"].asString() << "." - << removeSpaces(msg["data"]["Tag"].asString()); - - std::string id = ss.str(); - - statsdClient.gauge(id + ".lt_30", gt_60 + lt_60 + lt_30); - statsdClient.gauge(id + ".lt_20", lt_20); - statsdClient.gauge(id + ".lt_15", lt_15); - statsdClient.gauge(id + ".lt_12", lt_12); - statsdClient.gauge(id + ".lt_10", lt_10); - statsdClient.gauge(id + ".lt_08", lt_08); - - return true; - } - - std::string getDeviceIdentifier(const Json::Value& msg) - { - std::string deviceId("na"); - - auto osName = msg["device"]["os_name"]; - if (osName == "Android") - { - deviceId = msg["device"]["model"].asString(); - } - else if (osName == "iOS") - { - deviceId = msg["device"]["hardware_model"].asString(); - } - - return deviceId; - } - - bool processPerfMetricsEventSlowFrames(const Json::Value& msg, - StatsdClient& statsdClient, - std::map& deviceIdCounters, - std::atomic& sentCount) - { - auto frameRateHistogramCounts = msg["data"]["FrameRateHistogramCounts"]; - - int slowFrames = 0; - slowFrames += frameRateHistogramCounts[4].asInt(); - slowFrames += frameRateHistogramCounts[5].asInt(); - slowFrames += frameRateHistogramCounts[6].asInt(); - slowFrames += frameRateHistogramCounts[7].asInt(); - - std::stringstream ss; - ss << msg["id"].asString() << "_slow_frames" << "." - << msg["device"]["game"].asString() << "." - << removeSpaces(msg["data"]["Tag"].asString()); - - std::string id = ss.str(); - statsdClient.timing(id, slowFrames); - - // extract device model names for common devices - auto deviceId = getDeviceIdentifier(msg); - deviceIdCounters[deviceId]++; - - if (deviceId == "N841AP" || deviceId == "SM-N960U") - { - ss.str(""); // reset the stringstream - ss << msg["id"].asString() << "_slow_frames_by_device" << "." - << deviceId << "." - << msg["device"]["game"].asString() << "." - << removeSpaces(msg["data"]["Tag"].asString()); - - std::string id = ss.str(); - statsdClient.timing(id, slowFrames); - } - - // periodically display all device ids - if (sentCount % 1000 == 0) - { - ss.str(""); // reset the stringstream - ss << "## " << deviceIdCounters.size() << " unique device ids ##" << std::endl; - for (auto&& it : deviceIdCounters) - { - ss << it.first << " => " << it.second << std::endl; - } - CoreLogger::info(ss.str()); - } - - return true; - } - - int64_t cobra_metrics_to_statsd_bot(const ix::CobraBotConfig& config, - StatsdClient& statsdClient, - bool verbose) - { - CobraBot bot; - std::map deviceIdCounters; - - bot.setOnBotMessageCallback( - [&statsdClient, &verbose, &deviceIdCounters] - (const Json::Value& msg, - const std::string& /*position*/, - std::atomic& /*throttled*/, - std::atomic& /*fatalCobraError*/, - std::atomic& sentCount) -> void { - if (msg["device"].isNull()) - { - CoreLogger::info("no device entry, skipping event"); - return; - } - - if (msg["id"].isNull()) - { - CoreLogger::info("no id entry, skipping event"); - return; - } - - // - // Display full message with - if (verbose) - { - CoreLogger::info(msg.toStyledString()); - } - - bool success = false; - if (msg["id"].asString() == "engine_performance_metrics_id") - { - success = processPerfMetricsEvent(msg, statsdClient); - success |= processPerfMetricsEventSlowFrames(msg, statsdClient, deviceIdCounters, sentCount); - } - else if (msg["id"].asString() == "engine_net_request_id") - { - success = processNetRequestMetricsEvent(msg, statsdClient); - } - - if (success) sentCount++; - }); - - return bot.run(config); - } -} diff --git a/ixbots/ixbots/IXCobraMetricsToStatsdBot.h b/ixbots/ixbots/IXCobraMetricsToStatsdBot.h deleted file mode 100644 index 6c9b980b..00000000 --- a/ixbots/ixbots/IXCobraMetricsToStatsdBot.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * IXCobraMetricsToStatsdBot.h - * Author: Benjamin Sergeant - * Copyright (c) 2020 Machine Zone, Inc. All rights reserved. - */ -#pragma once - -#include -#include -#include "IXCobraBotConfig.h" -#include -#include - -namespace ix -{ - int64_t cobra_metrics_to_statsd_bot(const ix::CobraBotConfig& config, - StatsdClient& statsdClient, - bool verbose); -} // namespace ix diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index a6f7fd17..a3b2c5fb 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "9.8.3" +#define IX_WEBSOCKET_VERSION "9.8.4" diff --git a/ws/ws.cpp b/ws/ws.cpp index 4eb2b598..c415f7fa 100644 --- a/ws/ws.cpp +++ b/ws/ws.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -364,16 +363,6 @@ int main(int argc, char** argv) addTLSOptions(cobra2python); addCobraBotConfig(cobra2python); - CLI::App* cobraMetrics2statsd = app.add_subcommand("cobra_metrics_to_statsd", "Cobra metrics to statsd"); - cobraMetrics2statsd->fallthrough(); - cobraMetrics2statsd->add_option("--host", hostname, "Statsd host"); - cobraMetrics2statsd->add_option("--port", statsdPort, "Statsd port"); - cobraMetrics2statsd->add_option("--prefix", prefix, "Statsd prefix"); - cobraMetrics2statsd->add_flag("-v", verbose, "Verbose"); - cobraMetrics2statsd->add_option("--pidfile", pidfile, "Pid file"); - addTLSOptions(cobraMetrics2statsd); - addCobraBotConfig(cobraMetrics2statsd); - CLI::App* cobra2sentry = app.add_subcommand("cobra_to_sentry", "Cobra to sentry"); cobra2sentry->fallthrough(); cobra2sentry->add_option("--dsn", dsn, "Sentry DSN"); @@ -619,23 +608,6 @@ int main(int argc, char** argv) cobraBotConfig, statsdClient, scriptPath); } } - else if (app.got_subcommand("cobra_metrics_to_statsd")) - { - ix::StatsdClient statsdClient(hostname, statsdPort, prefix, verbose); - - std::string errMsg; - bool initialized = statsdClient.init(errMsg); - if (!initialized) - { - spdlog::error(errMsg); - ret = 1; - } - else - { - ret = (int) ix::cobra_metrics_to_statsd_bot( - cobraBotConfig, statsdClient, verbose); - } - } else if (app.got_subcommand("cobra_to_sentry")) { ix::SentryClient sentryClient(dsn);