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

[forge] fix chaos-mesh injection direction #13476

Merged
merged 1 commit into from
May 31, 2024
Merged
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions testsuite/forge/src/backend/k8s/chaos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ impl K8sSwarm {
for group_netem in &swarm_netem.group_netems {
let source_instance_labels = self.get_instance_labels(&group_netem.source_nodes);
let target_instance_labels = self.get_instance_labels(&group_netem.target_nodes);
let service_targets = self.get_service_targets(&group_netem.target_nodes);

network_chaos_specs.push(format!(
include_str!(NETEM_CHAOS_TEMPLATE!()),
Expand All @@ -180,6 +181,7 @@ impl K8sSwarm {
instance_labels = &source_instance_labels,
target_instance_labels = &target_instance_labels,
rate = group_netem.rate_in_mbps,
service_targets = &service_targets,
));
}

Expand Down Expand Up @@ -285,4 +287,23 @@ impl K8sSwarm {
INVALID_NODE_STRING
}
}

fn get_service_name(&self, node: &AccountAddress) -> Option<String> {
if let Some(validator) = self.validator(*node) {
validator.service_name()
} else if let Some(fullnode) = self.full_node(*node) {
fullnode.service_name()
} else {
// TODO: should we throw an error here instead of failing silently?
None
}
}

pub(crate) fn get_service_targets(&self, target_nodes: &[AccountAddress]) -> String {
target_nodes
.iter()
.filter_map(|node| self.get_service_name(node))
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be returning the ip addresses instead of the service name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Services names get resolved via DNS. so still works.

.collect::<Vec<_>>()
.join(",")
}
}
4 changes: 3 additions & 1 deletion testsuite/forge/src/backend/k8s/chaos/netem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ spec:
rate: "{rate}mbps"
limit: 20971520 # placeholder value. not supported by tc netem
buffer: 10000 # placeholder value. not supported by tc netem
direction: both
direction: to
target:
selector:
namespaces:
- {namespace}
expressionSelectors:
- {{ key: app.kubernetes.io/instance, operator: In, values: [{target_instance_labels}] }}
mode: all
# This is required to ensure that the network chaos is applied when using service IPs instead of pod IPs
externalTargets: [{service_targets}]
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,20 @@ fullnode:
# force enable the telemetry service to try to send telemetry
force_enable_telemetry: true

# Make all services internal NodePort and open all ports
# NodePort is required for ChaosMesh to function correctly: https://github.com/chaos-mesh/chaos-mesh/issues/3278#issuecomment-1134248492
service:
validator:
external:
type: "NodePort"
type: "ClusterIP"
internal:
type: "NodePort"
type: "ClusterIP"
enableRestApi: true
enableMetricsPort: true

fullnode:
external:
type: "NodePort"
type: "ClusterIP"
internal:
type: "NodePort"
type: "ClusterIP"
enableRestApi: true
enableMetricsPort: true

Expand Down
4 changes: 4 additions & 0 deletions testsuite/forge/src/backend/k8s/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ impl Node for K8sNode {
)
.await
}

fn service_name(&self) -> Option<String> {
Some(self.service_name.clone())
}
}

impl Validator for K8sNode {}
Expand Down
4 changes: 4 additions & 0 deletions testsuite/forge/src/backend/local/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ impl Node for LocalNode {
fn expose_metric(&self) -> Result<u64> {
Ok(0)
}

fn service_name(&self) -> Option<String> {
None
}
}

impl Validator for LocalNode {}
Expand Down
2 changes: 2 additions & 0 deletions testsuite/forge/src/interface/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ pub trait Node: Send + Sync {
fn counter(&self, counter: &str, port: u64) -> Result<f64>;

fn expose_metric(&self) -> Result<u64>;

fn service_name(&self) -> Option<String>;
}

/// Trait used to represent a running Validator
Expand Down
46 changes: 30 additions & 16 deletions testsuite/testcases/src/multi_region_network_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,39 @@ impl InterRegionNetEmConfig {
let group_netems: Vec<GroupNetEm> = peer_groups
.iter()
.combinations(2)
.map(|comb| {
.flat_map(|comb| {
let (from_region, from_chunk, stats) = &comb[0];
let (to_region, to_chunk, _) = &comb[1];

let (bandwidth, latency) = stats.get(to_region).unwrap();
let netem = GroupNetEm {
name: format!("{}-to-{}-netem", from_region, to_region),
source_nodes: from_chunk.to_vec(),
target_nodes: to_chunk.to_vec(),
delay_latency_ms: *latency as u64,
delay_jitter_ms: self.delay_jitter_ms,
delay_correlation_percentage: self.delay_correlation_percentage,
loss_percentage: self.loss_percentage,
loss_correlation_percentage: self.loss_correlation_percentage,
rate_in_mbps: *bandwidth / 1e6 as u64,
};
info!("inter-region netem {:?}", netem);

netem
let (bandwidth, rtt_latency) = stats.get(to_region).unwrap();
let hop_latency = rtt_latency / 2.0;
let netems = [
GroupNetEm {
name: format!("{}-to-{}-netem", from_region, to_region),
source_nodes: from_chunk.to_vec(),
target_nodes: to_chunk.to_vec(),
delay_latency_ms: hop_latency as u64,
delay_jitter_ms: self.delay_jitter_ms,
delay_correlation_percentage: self.delay_correlation_percentage,
loss_percentage: self.loss_percentage,
loss_correlation_percentage: self.loss_correlation_percentage,
rate_in_mbps: *bandwidth / 1e6 as u64,
},
GroupNetEm {
name: format!("{}-to-{}-netem", to_region, from_region),
source_nodes: to_chunk.to_vec(),
target_nodes: from_chunk.to_vec(),
delay_latency_ms: hop_latency as u64,
delay_jitter_ms: self.delay_jitter_ms,
delay_correlation_percentage: self.delay_correlation_percentage,
loss_percentage: self.loss_percentage,
loss_correlation_percentage: self.loss_correlation_percentage,
rate_in_mbps: *bandwidth / 1e6 as u64,
},
];
info!("inter-region netem {:?}", netems);

netems
})
.collect();

Expand Down
1 change: 1 addition & 0 deletions testsuite/testcases/src/network_bandwidth_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use aptos_forge::{
GroupNetworkBandwidth, NetworkContext, NetworkTest, SwarmChaos, SwarmNetworkBandwidth, Test,
};

/// This is deprecated. Use [crate::multi_region_network_test::MultiRegionNetworkEmulationTest] instead
pub struct NetworkBandwidthTest;

// Bandwidth
Expand Down
1 change: 1 addition & 0 deletions testsuite/testcases/src/network_loss_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use crate::{LoadDestination, NetworkLoadTest};
use aptos_forge::{NetworkContext, NetworkTest, SwarmChaos, SwarmNetworkLoss, Test};

/// This is deprecated. Use [crate::multi_region_network_test::MultiRegionNetworkEmulationTest] instead
pub struct NetworkLossTest;

// Loss parameters
Expand Down
1 change: 1 addition & 0 deletions testsuite/testcases/src/network_partition_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use crate::{LoadDestination, NetworkLoadTest};
use aptos_forge::{NetworkContext, NetworkTest, SwarmChaos, SwarmNetworkPartition, Test};

/// This is deprecated. Use [crate::multi_region_network_test::MultiRegionNetworkEmulationTest] instead
pub struct NetworkPartitionTest;

// Partition
Expand Down
2 changes: 2 additions & 0 deletions testsuite/testcases/src/three_region_simulation_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ impl Test for ThreeRegionSameCloudSimulationTest {
/// 2. Each region has minimal network delay amongst its nodes
/// 3. Each region has a network delay to the other two regions, as estimated by https://www.cloudping.co/grid
/// 4. Currently simulating a 50 percentile network delay between us-west <--> af-south <--> eu-north
///
/// This is deprecated and flawed. Use [crate::multi_region_network_test::MultiRegionNetworkEmulationTest] instead
fn create_three_region_swarm_network_delay(swarm: &dyn Swarm) -> SwarmNetworkDelay {
let all_validators = swarm.validators().map(|v| v.peer_id()).collect::<Vec<_>>();

Expand Down
Loading