Skip to content

Commit

Permalink
Refactor log
Browse files Browse the repository at this point in the history
Signed-off-by: terassyi <[email protected]>
  • Loading branch information
terassyi committed May 30, 2024
1 parent 29f5151 commit dc8d748
Show file tree
Hide file tree
Showing 15 changed files with 325 additions and 141 deletions.
208 changes: 208 additions & 0 deletions e2e/topology/kubernetes-cni-compact.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
name: sart
topology:
kinds:
linux:
cmd: bash
nodes:
router0:
kind: linux
image: frrouting/frr:v8.4.0
exec:
- ip addr add 169.254.1.1/24 dev net0 scope link
- ip addr add 169.254.2.1/24 dev net1 scope link
- ip addr add 169.254.3.1/24 dev net2 scope link
- ip addr add 169.254.4.1/24 dev net3 scope link
- ip addr add 192.168.0.1/24 dev net4 scope link
# route for node primary address
- ip route add 172.18.0.6/32 dev net0
- ip route add 172.18.0.4/32 dev net1
- ip route add 172.18.0.5/32 dev net2
- ip route add 172.18.0.3/32 dev net3
- ip link add dummy0 type dummy
- ip addr add 9.9.9.9/32 dev dummy0
- ip link set up dev dummy0
- sysctl -w net.ipv4.fib_multipath_hash_policy=1
- sysctl -p
# Boiler plate to make FRR work
- touch /etc/frr/vtysh.conf
- sed -i -e 's/bgpd=no/bgpd=yes/g' /etc/frr/daemons
- /usr/lib/frr/frrinit.sh start
# FRR configuration
- >-
vtysh -c 'conf t'
-c 'frr defaults datacenter'
-c '!'
-c 'ip prefix-list LAB-SUBNET permit 10.0.0.0/8 ge 8'
-c '!'
-c 'router bgp 65000'
-c ' bgp router-id 9.9.9.9'
-c ' bgp bestpath as-path multipath-relax'
-c ' neighbor 169.254.1.2 remote-as 65010'
-c ' neighbor 169.254.2.2 remote-as 65020'
-c ' neighbor 169.254.3.2 remote-as 65030'
-c ' neighbor 169.254.4.2 remote-as 65040'
-c ' neighbor 169.254.1.2 update-source dummy0'
-c ' neighbor 169.254.2.2 update-source dummy0'
-c ' neighbor 169.254.3.2 update-source dummy0'
-c ' neighbor 169.254.4.2 update-source dummy0'
-c ' neighbor 169.254.1.2 next-hop-self'
-c ' neighbor 169.254.2.2 next-hop-self'
-c ' neighbor 169.254.3.2 next-hop-self'
-c ' neighbor 169.254.4.2 next-hop-self'
-c '!'
router0-debug:
kind: linux
image: nicolaka/netshoot:latest
network-mode: container:clab-sart-router0
router1:
kind: linux
image: frrouting/frr:v8.4.0
exec:
- ip addr add 169.253.1.1/24 dev net0 scope link
- ip addr add 169.253.2.1/24 dev net1 scope link
- ip addr add 169.253.3.1/24 dev net2 scope link
- ip addr add 169.253.4.1/24 dev net3 scope link
- ip addr add 192.168.1.1/24 dev net4 scope link
- ip link add dummy0 type dummy
- ip addr add 7.7.7.7/32 dev dummy0
- ip link set up dev dummy0
- ip route add 172.18.0.6/32 dev net0
- ip route add 172.18.0.4/32 dev net1
- ip route add 172.18.0.5/32 dev net2
- ip route add 172.18.0.3/32 dev net3
- sysctl -w net.ipv4.fib_multipath_hash_policy=1
- sysctl -p
# Boiler plate to make FRR work
- touch /etc/frr/vtysh.conf
- sed -i -e 's/bgpd=no/bgpd=yes/g' /etc/frr/daemons
- /usr/lib/frr/frrinit.sh start
# FRR configuration
- >-
vtysh -c 'conf t'
-c 'frr defaults datacenter'
-c '!'
-c 'ip prefix-list LAB-SUBNET permit 10.0.0.0/8 ge 8'
-c '!'
-c 'router bgp 65000'
-c ' bgp router-id 7.7.7.7'
-c ' bgp bestpath as-path multipath-relax'
-c ' neighbor 169.253.1.2 remote-as 65010'
-c ' neighbor 169.253.2.2 remote-as 65020'
-c ' neighbor 169.253.3.2 remote-as 65030'
-c ' neighbor 169.253.4.2 remote-as 65040'
-c ' neighbor 169.253.1.2 update-source dummy0'
-c ' neighbor 169.253.2.2 update-source dummy0'
-c ' neighbor 169.253.3.2 update-source dummy0'
-c ' neighbor 169.253.4.2 update-source dummy0'
-c ' neighbor 169.253.1.2 next-hop-self'
-c ' neighbor 169.253.2.2 next-hop-self'
-c ' neighbor 169.253.3.2 next-hop-self'
-c ' neighbor 169.253.4.2 next-hop-self'
-c '!'
router1-debug:
kind: linux
image: nicolaka/netshoot:latest
network-mode: container:clab-sart-router1
control-plane0:
kind: linux
image: nicolaka/netshoot:latest
network-mode: container:sart-control-plane
exec:
# Enable ECMP
- sysctl -w net.ipv4.fib_multipath_hash_policy=1
- sysctl -p
# Address for peering
- ip addr add 169.254.1.2/24 dev net0 scope link
- ip addr add 169.253.1.2/24 dev net1 scope link
# Route traffic to the lab through router
- ip route add 172.18.0.4/32 src 172.18.0.6 nexthop via 169.254.1.1 weight 1 nexthop via 169.253.1.1 weight 1
- ip route add 172.18.0.5/32 src 172.18.0.6 nexthop via 169.254.1.1 weight 1 nexthop via 169.253.1.1 weight 1
- ip route add 172.18.0.3/32 src 172.18.0.6 nexthop via 169.254.1.1 weight 1 nexthop via 169.253.1.1 weight 1
- ip route add 192.168.0.0/24 via 169.254.1.1 dev net0
- ip route add 192.168.1.0/24 via 169.253.1.1 dev net1
- ip route add 6.6.6.6/32 via 169.254.1.1 dev net0
- ip route add 9.9.9.9/32 via 169.254.1.1 dev net0
- ip route add 7.7.7.7/32 via 169.253.1.1 dev net1
worker0:
kind: linux
image: nicolaka/netshoot:latest
network-mode: container:sart-worker
exec:
# Enable ECMP
- sysctl -w net.ipv4.fib_multipath_hash_policy=1
- sysctl -p
# Address for peering
- ip addr add 169.254.2.2/24 dev net0 scope link
- ip addr add 169.253.2.2/24 dev net1 scope link
# Route traffic to the lab through router
- ip route add 172.18.0.6/32 src 172.18.0.4 nexthop via 169.254.2.1 weight 1 nexthop via 169.253.2.1 weight 1
- ip route add 172.18.0.5/32 src 172.18.0.4 nexthop via 169.254.2.1 weight 1 nexthop via 169.253.2.1 weight 1
- ip route add 172.18.0.3/32 src 172.18.0.4 nexthop via 169.254.2.1 weight 1 nexthop via 169.253.2.1 weight 1
- ip route add 192.168.0.0/24 via 169.254.2.1 dev net0
- ip route add 192.168.1.0/24 via 169.253.2.1 dev net1
- ip route add 6.6.6.6/32 via 169.254.2.1 dev net0
- ip route add 9.9.9.9/32 via 169.254.2.1 dev net0
- ip route add 7.7.7.7/32 via 169.253.2.1 dev net1
worker1:
kind: linux
image: nicolaka/netshoot:latest
network-mode: container:sart-worker2
exec:
# Enable ECMP
- sysctl -w net.ipv4.fib_multipath_hash_policy=1
- sysctl -p
# Address for peering
- ip addr add 169.254.3.2/24 dev net0 scope link
- ip addr add 169.253.3.2/24 dev net1 scope link
# Route traffic to the lab through router
- ip route add 172.18.0.6/32 src 172.18.0.5 nexthop via 169.254.3.1 weight 1 nexthop via 169.253.3.1 weight 1
- ip route add 172.18.0.4/32 src 172.18.0.5 nexthop via 169.254.3.1 weight 1 nexthop via 169.253.3.1 weight 1
- ip route add 172.18.0.3/32 src 172.18.0.5 nexthop via 169.254.3.1 weight 1 nexthop via 169.253.3.1 weight 1
- ip route add 192.168.0.0/24 via 169.254.3.1 dev net0
- ip route add 192.168.1.0/24 via 169.253.3.1 dev net1
- ip route add 6.6.6.6/32 via 169.254.3.1 dev net0
- ip route add 9.9.9.9/32 via 169.254.3.1 dev net0
- ip route add 7.7.7.7/32 via 169.253.3.1 dev net1
worker2:
kind: linux
image: nicolaka/netshoot:latest
network-mode: container:sart-worker3
exec:
# Enable ECMP
- sysctl -w net.ipv4.fib_multipath_hash_policy=1
- sysctl -p
# Address for peering
- ip addr add 169.254.4.2/24 dev net0 scope link
- ip addr add 169.253.4.2/24 dev net1 scope link
# Route traffic to the lab through router
- ip route add 172.18.0.6/32 src 172.18.0.3 nexthop via 169.254.4.1 weight 1 nexthop via 169.253.4.1 weight 1
- ip route add 172.18.0.4/32 src 172.18.0.3 nexthop via 169.254.4.1 weight 1 nexthop via 169.253.4.1 weight 1
- ip route add 172.18.0.5/32 src 172.18.0.3 nexthop via 169.254.4.1 weight 1 nexthop via 169.253.4.1 weight 1
- ip route add 192.168.0.0/24 via 169.254.4.1 dev net0
- ip route add 192.168.1.0/24 via 169.253.4.1 dev net1
- ip route add 6.6.6.6/32 via 169.254.4.1 dev net0
- ip route add 9.9.9.9/32 via 169.254.4.1 dev net0
- ip route add 7.7.7.7/32 via 169.253.4.1 dev net1
client0:
kind: linux
image: nicolaka/netshoot:latest
exec:
- ip addr add 192.168.0.2/24 dev net0
- ip addr add 192.168.1.2/24 dev net1
- ip link add dummy0 type dummy
- ip addr add 6.6.6.6/32 dev dummy0
- ip link set up dev dummy0
- ip route change default src 6.6.6.6 nexthop via 192.168.0.1 weight 1
- sysctl -w net.ipv4.fib_multipath_hash_policy=1
- sysctl -p
links:
- endpoints: ["router0:net0", "control-plane0:net0"]
- endpoints: ["router0:net1", "worker0:net0"]
- endpoints: ["router0:net2", "worker1:net0"]
- endpoints: ["router0:net3", "worker2:net0"]
- endpoints: ["router1:net0", "control-plane0:net1"]
- endpoints: ["router1:net1", "worker0:net1"]
- endpoints: ["router1:net2", "worker1:net1"]
- endpoints: ["router1:net3", "worker2:net1"]
- endpoints: ["router0:net4", "client0:net0"]
- endpoints: ["router1:net4", "client0:net1"]
2 changes: 0 additions & 2 deletions sartd/src/bgp/src/api_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ impl ApiServer {
#[tonic::async_trait]
impl BgpApi for ApiServer {
async fn health(&self, _req: Request<HealthRequest>) -> Result<Response<()>, Status> {
tracing::info!("start health checking");
let guard_tx = self.tx.lock().await;
guard_tx.send(ControlEvent::Health).await.unwrap();
self.signal.notified().await;
tracing::info!("health checking");
Ok(Response::new(()))
}

Expand Down
3 changes: 0 additions & 3 deletions sartd/src/bgp/src/peer/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ impl Peer {
};
let exporter = match exporter {
Some(path) => {
tracing::info!("Try to connect to BGP exporter");
match sartd_proto::sart::bgp_exporter_api_client::BgpExporterApiClient::connect(
format!("http://{}", path),
)
Expand Down Expand Up @@ -244,8 +243,6 @@ impl Peer {

let (msg_event_tx, mut msg_event_rx) = unbounded_channel::<BgpMessageEvent>();

tracing::debug!("handlng the peer event");

let (conn_close_tx, mut conn_close_rx) = channel::<u16>(2);

loop {
Expand Down
7 changes: 3 additions & 4 deletions sartd/src/bgp/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ impl Bgp {

#[tracing::instrument(skip(self, event))]
async fn handle_event(&mut self, event: ControlEvent) -> Result<(), Error> {
tracing::info!(event=%event);
match event {
ControlEvent::Health => {}
ControlEvent::GetBgpInfo => self.get_bgp_info().await?,
Expand All @@ -251,7 +250,7 @@ impl Bgp {
}
ControlEvent::DeletePath(family, prefixes) => {
self.delete_path(family, prefixes).await?;
},
}
ControlEvent::ConfigureMultiPath(enable) => {
self.set_multipath(enable).await?;
}
Expand Down Expand Up @@ -370,7 +369,7 @@ impl Bgp {
}
}
}
tracing::info!("set local asn");
tracing::info!(asn = asn, "set local asn");
self.rib_event_tx
.send(RibEvent::SetAsn(asn))
.await
Expand All @@ -388,7 +387,7 @@ impl Bgp {
return Ok(());
}
config.router_id = router_id;
tracing::info!("set local router_id");
tracing::info!(router_id =? router_id, "set local router_id");
self.rib_event_tx
.send(RibEvent::SetRouterId(router_id))
.await
Expand Down
2 changes: 1 addition & 1 deletion sartd/src/kubernetes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ serde_json = "1.0.108"
thiserror = "1.0.53"
tokio = { version = "1.35.1", features = ["rt-multi-thread", "macros"] }
tracing = "0.1.40"
sartd-trace = { path = "../trace" }
serde_yaml = "0.9.29"
tonic = "0.10.2"

sartd-cert = { path = "../cert" }
sartd-proto = { path = "../proto" }
sartd-ipam = { path = "../ipam" }
sartd-mock = { path = "../mock" }
sartd-trace = { path = "../trace" }
futures = "0.3.30"
rtnetlink = "0.13.1" # Ignore v0.14.x
actix-web = { version = "4.4.1", features = ["rustls-0_21"] }
Expand Down
17 changes: 6 additions & 11 deletions sartd/src/kubernetes/src/agent/reconciler/bgp_advertisement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use kube::{
runtime::{controller::Action, watcher::Config, Controller},
Api, Client, ResourceExt,
};
use tracing::{field, Span};

use crate::{
agent::{bgp::speaker, error::Error},
Expand All @@ -20,7 +21,7 @@ use crate::{

use super::node_bgp::{DEFAULT_SPEAKER_TIMEOUT, ENV_HOSTNAME};

#[tracing::instrument(skip_all)]
#[tracing::instrument(skip_all, fields(trace_id))]
pub async fn run(state: State, interval: u64) {
let client = Client::try_default()
.await
Expand Down Expand Up @@ -59,12 +60,6 @@ pub async fn reconciler(ba: Arc<BGPAdvertisement>, ctx: Arc<Context>) -> Result<

let bgp_advertisements = Api::<BGPAdvertisement>::namespaced(ctx.client.clone(), &ns);

tracing::info!(
name = ba.name_any(),
namespace = ns,
"Reconcile BGPAdvertisement"
);

reconcile(&bgp_advertisements, &ba, ctx).await
}

Expand All @@ -74,6 +69,9 @@ async fn reconcile(
ba: &BGPAdvertisement,
ctx: Arc<Context>,
) -> Result<Action, Error> {
let trace_id = sartd_trace::telemetry::get_trace_id();
Span::current().record("trace_id", &field::display(&trace_id));

let node_bgps = Api::<NodeBGP>::all(ctx.client.clone());
let node_name = std::env::var(ENV_HOSTNAME).map_err(Error::Var)?;

Expand Down Expand Up @@ -134,7 +132,6 @@ async fn reconcile(
})
.await
.map_err(Error::GotgPRC)?;
tracing::info!(name = ba.name_any(), namespace = ba.namespace(), status=?adv_status, response=?res,"Add path response");

*adv_status = AdvertiseStatus::Advertised;
need_update = true;
Expand All @@ -148,7 +145,6 @@ async fn reconcile(
})
.await
.map_err(Error::GotgPRC)?;
tracing::info!(name = ba.name_any(), namespace = ba.namespace(), status=?adv_status ,response=?res,"Add path response");
}
AdvertiseStatus::Withdraw => {
let res = speaker_client
Expand All @@ -158,7 +154,6 @@ async fn reconcile(
})
.await
.map_err(Error::GotgPRC)?;
tracing::info!(name = ba.name_any(), namespace = ba.namespace(), status=?adv_status, response=?res,"Delete path response");

peers.remove(&p.name);
need_update = true;
Expand All @@ -180,7 +175,7 @@ async fn reconcile(
tracing::info!(
name = ba.name_any(),
namespace = ba.namespace(),
"Update BGPAdvertisement"
"update BGPAdvertisement"
);
return Ok(Action::requeue(Duration::from_secs(60)));
}
Expand Down
Loading

0 comments on commit dc8d748

Please sign in to comment.