Skip to content

dlb: optimize auto detect logic#23465

Merged
adisuissa merged 8 commits intoenvoyproxy:mainfrom
daixiang0:detect
Oct 19, 2022
Merged

dlb: optimize auto detect logic#23465
adisuissa merged 8 commits intoenvoyproxy:mainfrom
daixiang0:detect

Conversation

@daixiang0
Copy link
Copy Markdown
Member

@daixiang0 daixiang0 commented Oct 13, 2022

Signed-off-by: Loong loong.dai@intel.com

The default of type uint32 in protobuf is 0, so the else field can not run into.

Fix the above issue and add tests to cover some cases.

DLB mock functions are in development, so only test the config logic for now.

Commit Message:
Additional Description:
Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

@daixiang0 daixiang0 marked this pull request as draft October 13, 2022 05:04
@daixiang0 daixiang0 marked this pull request as ready for review October 13, 2022 06:12
@daixiang0 daixiang0 marked this pull request as draft October 13, 2022 06:12
@daixiang0 daixiang0 force-pushed the detect branch 7 times, most recently from 41d6894 to 277d5c8 Compare October 14, 2022 06:45
@daixiang0
Copy link
Copy Markdown
Member Author

daixiang0 commented Oct 14, 2022

I want to create a fake file under /dev to test detect logic but seems that CI can not create files under /dev, so do not add it :(

Try the below ways:

  • fstream then stat
  • open then stat

Both stat return -1.

@daixiang0 daixiang0 marked this pull request as ready for review October 14, 2022 06:46
Signed-off-by: Loong <loong.dai@intel.com>
@daixiang0
Copy link
Copy Markdown
Member Author

@adisuissa @wrowe could you help review?

Copy link
Copy Markdown
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

LGTM, just left a question.
RE how to test this, I don't think the test should create "/dev/..." files.
Can you refactor the code so it reads it from a different location? Then the test will use the functions from https://github.com/envoyproxy/envoy/blob/main/test/test_common/environment.h to create the temp files.

Comment thread contrib/network/connection_balance/dlb/source/connection_balancer_impl.cc Outdated
@daixiang0
Copy link
Copy Markdown
Member Author

@adisuissa I have refactored it and added new tests, please review and merge if possible.

Signed-off-by: Loong <loong.dai@intel.com>
Signed-off-by: Loong <loong.dai@intel.com>
Signed-off-by: Loong <loong.dai@intel.com>
Signed-off-by: Loong <loong.dai@intel.com>
Comment thread contrib/network/connection_balance/dlb/source/connection_balancer_impl.cc Outdated
Comment thread contrib/network/connection_balance/dlb/source/connection_balancer_impl.h Outdated
@daixiang0
Copy link
Copy Markdown
Member Author

@adisuissa please review again.

Signed-off-by: Loong <loong.dai@intel.com>
Signed-off-by: Loong <loong.dai@intel.com>
Signed-off-by: Loong <loong.dai@intel.com>
Copy link
Copy Markdown
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

LGTM, left a comment for future reference.

// The dir should always be "/dev" in production.
// For test it is a temporary directory.
// Return Dlb device id, absl::nullopt means error.
static absl::optional<uint> detectDlbDevice(const uint config_id, const std::string& dir) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: you can use absl::StatusOr as it allows you to specify the error.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sorry for slow response due to sickness, I will optimize it in the next PR.

@adisuissa adisuissa merged commit c1dcb02 into envoyproxy:main Oct 19, 2022
@daixiang0 daixiang0 deleted the detect branch October 21, 2022 04:26
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.

2 participants