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 Client Server role option #38

Merged

Conversation

Andrewmatilde
Copy link
Member

@Andrewmatilde Andrewmatilde commented Apr 25, 2022

Add a Client-Server role option.
When user set Client role in config, action will just apply when HTTP-TCP-source-IP == default IP.
When user set Server role in config, action will just apply when HTTP-TCP-dst-IP == default IP.

I also delete some interface option in proxy just because I find this option not really works & brings some BUGs.
related issue: #46

Signed-off-by: andrewmatilde <[email protected]>
Signed-off-by: andrewmatilde <[email protected]>
Signed-off-by: andrewmatilde <[email protected]>
@Andrewmatilde
Copy link
Member Author

PTAL , @Hexilee @STRRL @YangKeao @cwen0

Copy link
Member

@STRRL STRRL left a comment

Choose a reason for hiding this comment

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

Here is my first time trying to review codes in chaos-tproxy.

Please point me the thing I missed if I give the misleading comments.

Comment on lines 48 to 49
RawRole::Client => Role::Client(ipv4s[0]),
RawRole::Server => Role::Server(ipv4s[0]),
Copy link
Member

Choose a reason for hiding this comment

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

It seems we could only resolve the first IP of the first NIC.

And there is nowhere to extend the place. Should we consider that?

Copy link
Member Author

@Andrewmatilde Andrewmatilde May 10, 2022

Choose a reason for hiding this comment

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

The problem of we could only resolve the first NIC is caused by I have write a customed NIC function with some severe BUG , so I delete it. I will fix it later. I have leave a TODO for it.
I will fix the problem of we could only resolve the first IP , but that was a rare situation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

Comment on lines -80 to -91
match config.interface {
None => {}
Some(interface) => {
self.net_env.set_ip_with_interface_name(&interface)?;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

after that, there is nowhere to call the set_ip_with_interface_name, maybe we could also remove that unused method?

Also there is nowhere to change NetEnv.ip, I am not sure it would introduce unexpected situation or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with you.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also there is nowhere to change NetEnv.ip, I am not sure it would introduce unexpected situation or not.

I will fix the problem later. Now the chaos-tproxy is only used in container networks , so , IMO , it is safe.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

Signed-off-by: andrewmatilde <[email protected]>
# Conflicts:
#	chaos-tproxy-controller/src/proxy/exec.rs
Copy link
Member

@STRRL STRRL left a comment

Choose a reason for hiding this comment

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

rest LGTM

PTAL @Andrewmatilde

Comment on lines 138 to 153
fn role_ok(&self) -> bool {
let role = match &self.config.role {
None => return true,
Some(r) => r.clone(),
};
let remote_v4 = match self.remote.ip() {
IpAddr::V4(ipv4) => ipv4,
_ => return false,
};
let target_v4 = match self.target.ip() {
IpAddr::V4(ipv4) => ipv4,
_ => return false,
};

select_role(&remote_v4, &target_v4, &role)
}
Copy link
Member

Choose a reason for hiding this comment

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

I prefer to move this logic as a part of selector, in function select_role()

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed. Move some logical into select_role()

async fn handle(self, mut request: Request<Body>) -> Result<Response<Body>> {
let log_key = format!("{{remote = {}, target = {} }}", self.remote, self.target);
debug!("{} : Proxy is handling http request", log_key);

let ok = self.role_ok();
Copy link
Member

Choose a reason for hiding this comment

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

ok -> role_ok or role_matched, role_selected

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed. ok -> role_ok

# Conflicts:
#	chaos-tproxy-controller/src/proxy/config.rs
#	chaos-tproxy-controller/src/proxy/net/bridge.rs
#	chaos-tproxy-controller/src/raw_config.rs
#	chaos-tproxy-proxy/src/proxy/http/server.rs
#	chaos-tproxy-proxy/src/raw_config.rs
Signed-off-by: andrewmatilde <[email protected]>
Signed-off-by: andrewmatilde <[email protected]>
Copy link
Member

@STRRL STRRL left a comment

Choose a reason for hiding this comment

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

LGTM!

@Andrewmatilde Andrewmatilde merged commit 955c9f1 into chaos-mesh:master Jul 18, 2022
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