From 187e1e33a1dff772cfc07552bf283bc130e023df Mon Sep 17 00:00:00 2001 From: Antonio Ruiz Date: Thu, 28 Dec 2023 14:48:25 +0100 Subject: [PATCH] Implement custom stickiness for flexible rollout --- src/strategies/flexiblerollout.cpp | 5 +++++ test/tests.cpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/strategies/flexiblerollout.cpp b/src/strategies/flexiblerollout.cpp index 953daf1..89f59fb 100644 --- a/src/strategies/flexiblerollout.cpp +++ b/src/strategies/flexiblerollout.cpp @@ -3,6 +3,7 @@ #include #include + namespace unleash { FlexibleRollout::FlexibleRollout(std::string_view parameters, std::string_view constraints) : Strategy("flexibleRollout", constraints) { @@ -34,6 +35,10 @@ bool FlexibleRollout::isEnabled(const Context &context) { std::mt19937 rng(dev()); std::uniform_int_distribution dist6(1, 100); return dist6(rng) <= m_rollout; + } else { + auto customFieldIt = context.properties.find(stickinessConfiguration); + if (customFieldIt == context.properties.end()) return false; + return normalizedMurmur3(m_groupId + ":" + customFieldIt->second) <= m_rollout; } return false; } diff --git a/test/tests.cpp b/test/tests.cpp index de94dcb..06f0b07 100644 --- a/test/tests.cpp +++ b/test/tests.cpp @@ -36,7 +36,7 @@ std::vector readSpecificationTestFromDisk(const std::string &testPath // range-based to read each test for (auto &element : j) { // Only features implemented for now auto testNumber = std::stoi(element.get().substr(0, 2)); - if (testNumber <= 11) { + if (testNumber <= 12) { std::cout << testPath + element.get() << std::endl; std::ifstream testFile(testPath + element.get()); nlohmann::json testJson;