Skip to content

Ovalenti/rox 29399 directional ext i ps jv 2 #2142

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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

JoukoVirtanen
Copy link
Contributor

Description

Fixes a problem where IsEnabled(Direction::NONE) always returns true.

Checklist

  • Investigated and inspected CI test results
  • Updated documentation accordingly

Automated testing

  • Added unit tests
  • Added integration tests
  • Added regression tests

If any of these don't apply, please comment below.

Testing Performed

CI is sufficient.

@JoukoVirtanen JoukoVirtanen requested a review from a team as a code owner May 27, 2025 21:44
@JoukoVirtanen JoukoVirtanen requested review from ovalenti and removed request for a team May 27, 2025 21:44
@@ -155,4 +156,95 @@ TEST(CollectorConfigTest, TestEnableExternalIpsRuntimeConfig) {
EXPECT_TRUE(config.ExternalIPsConf().IsEnabled(Direction::BOTH));
}

TEST(CollectorConfigTest, TestIsEnabledIngress) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These tests could all be done in one test in a loop.

@@ -11,7 +11,7 @@ namespace collector {
class ExternalIPsConfig {
public:
enum Direction {
NONE = 0,
NONE = 1 << 2,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it makes more sense to change IsEnabled like this:

bool IsEnabled(Direction direction) const { return direction != Direction::None && (direction & direction_enabled_) == direction; }

On a different note, I don't think IsEnabled(Direction::NONE) is something anyone would write, so I'm not convinced the extra overhead for the check is worth it. Maybe we can do a static check instead?

bool IsEnabled(Direction direction) const {
  static_assert(direction != Direction::NONE);
  return (direction & direction_enabled_) == direction;
}

Or, if a compile time check is not possible, then just use good old assert to make the invariant explicit.

bool IsEnabled(Direction direction) const {
  assert(direction != Direction::NONE);
  return (direction & direction_enabled_) == direction;
}

Base automatically changed from ovalenti/ROX-29399-directional-extIPs to master May 28, 2025 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants