Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add constraint evaluation to maintained strategies #32

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/strategies/applicationhostname.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ bool ApplicationHostname::isEnabled(const Context &context) {
getHostname(hostnameC);

if (std::string hostname{hostnameC}; std::find(m_applicationHostnames.begin(), m_applicationHostnames.end(),
hostname) != m_applicationHostnames.end())
return true;
return false;
hostname) == m_applicationHostnames.end())
return false;
return meetConstraints(context);
}
} // namespace unleash
10 changes: 5 additions & 5 deletions src/strategies/flexiblerollout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ bool FlexibleRollout::isEnabled(const Context &context) {
}
if (stickinessConfiguration == "userId") {
if (context.userId.empty()) return false;
return normalizedMurmur3(m_groupId + ":" + context.userId) <= m_rollout;
if (normalizedMurmur3(m_groupId + ":" + context.userId) > m_rollout) return false;
} else if (stickinessConfiguration == "sessionId") {
return normalizedMurmur3(m_groupId + ":" + context.sessionId) <= m_rollout;
if (normalizedMurmur3(m_groupId + ":" + context.sessionId) > m_rollout) return false;
} else if (stickinessConfiguration == "random") {
std::random_device dev;
std::mt19937 rng(dev());
std::uniform_int_distribution<std::mt19937::result_type> dist6(1, 100);
return dist6(rng) <= m_rollout;
if (dist6(rng) > m_rollout) return false;
} else {
auto customFieldIt = context.properties.find(stickinessConfiguration);
if (customFieldIt == context.properties.end()) return false;
return normalizedMurmur3(m_groupId + ":" + customFieldIt->second) <= m_rollout;
if (normalizedMurmur3(m_groupId + ":" + customFieldIt->second) > m_rollout) return false;
}
return false;
return meetConstraints(context);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest checking the constraints at the start:

bool FlexibleRollout::isEnabled(const Context &context) {
    if (!meetConstraints(context)) return false;
    // The rest of the function, unchanged
}

}
} // namespace unleash
4 changes: 2 additions & 2 deletions src/strategies/remoteaddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RemoteAddress::RemoteAddress(std::string_view parameters, std::string_view const
}

bool RemoteAddress::isEnabled(const Context &context) {
if (std::find(m_ips.begin(), m_ips.end(), context.remoteAddress) != m_ips.end()) return true;
return false;
if (std::find(m_ips.begin(), m_ips.end(), context.remoteAddress) == m_ips.end()) return false;
return meetConstraints(context);
}
} // namespace unleash