From 80040c7be1da23027bcd858dc377b3ef4a834ce8 Mon Sep 17 00:00:00 2001 From: Fei Chen Date: Thu, 5 Oct 2023 05:28:46 -0700 Subject: [PATCH] introduce per vip sid routing stats Summary: as per title Reviewed By: avasylev Differential Revision: D49685686 fbshipit-source-id: 38636551a94aa92df70e98c83a32b60ede3772ec --- katran/lib/KatranLb.cpp | 14 ++++++++++++++ katran/lib/KatranLb.h | 9 +++++++++ katran/lib/bpf/balancer.bpf.c | 25 ++++++++++++++++++++++++- katran/lib/bpf/balancer_maps.h | 8 ++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/katran/lib/KatranLb.cpp b/katran/lib/KatranLb.cpp index d092893ad..a47d114b1 100644 --- a/katran/lib/KatranLb.cpp +++ b/katran/lib/KatranLb.cpp @@ -2584,4 +2584,18 @@ std::vector KatranLb::getGlobalLruMapsFds() { return result; } +lb_stats KatranLb::getSidRoutingStatsForVip(const VipKey& vip) { + auto vip_iter = vips_.find(vip); + if (vip_iter == vips_.end()) { + LOG(INFO) << fmt::format( + "trying to get sid routing stats for non-existing vip {}:{}:{}", + vip.address, + vip.port, + vip.proto); + return lb_stats{}; + } + auto vipNum = vip_iter->second.getVipNum(); + return getLbStats(vipNum, "server_id_routing_stats"); +} + } // namespace katran diff --git a/katran/lib/KatranLb.h b/katran/lib/KatranLb.h index 866f5c1cc..c146f7a0b 100644 --- a/katran/lib/KatranLb.h +++ b/katran/lib/KatranLb.h @@ -812,6 +812,15 @@ class KatranLb { */ lb_tpr_packets_stats getLbTprPacketsStats(); + /** + * @param VipKey vip + * @return struct lb_stats w/ statistic for specified vip + * + * helper function which return total ammount of initial/sync packets and + * server id routed packets which has been sent to specified vip. + */ + lb_stats getSidRoutingStatsForVip(const VipKey& vip); + private: /** * update vipmap(add or remove vip) in forwarding plane diff --git a/katran/lib/bpf/balancer.bpf.c b/katran/lib/bpf/balancer.bpf.c index 08c916adc..cadb68dbd 100644 --- a/katran/lib/bpf/balancer.bpf.c +++ b/katran/lib/bpf/balancer.bpf.c @@ -570,6 +570,21 @@ check_and_update_real_index_in_lru( return DST_NOT_FOUND_IN_LRU; } +__attribute__((__always_inline__)) static inline void +incr_server_id_routing_stats(__u32 vip_num, bool newConn, bool misMatchInLRU) { + struct lb_stats* per_vip_stats = + bpf_map_lookup_elem(&server_id_routing_stats, &vip_num); + if (!per_vip_stats) { + return; + } + if (newConn) { + per_vip_stats->v1 += 1; + } + if (misMatchInLRU) { + per_vip_stats->v2 += 1; + } +} + __attribute__((__always_inline__)) static inline int process_packet(struct xdp_md* xdp, __u64 off, bool is_ipv6) { void* data = (void*)(long)xdp->data; @@ -720,6 +735,7 @@ process_packet(struct xdp_md* xdp, __u64 off, bool is_ipv6) { pckt.flow.port16[0] = 0; } + vip_num = vip_info->vip_num; __u32 cpu_num = bpf_get_smp_processor_id(); void* lru_map = bpf_map_lookup_elem(&lru_mapping, &cpu_num); if (!lru_map) { @@ -794,6 +810,8 @@ process_packet(struct xdp_md* xdp, __u64 off, bool is_ipv6) { quic_packets_stats->dst_match_in_lru += 1; } else if (res == DST_MISMATCH_IN_LRU) { quic_packets_stats->dst_mismatch_in_lru += 1; + incr_server_id_routing_stats( + vip_num, /* new conn */ false, /* mismatch in lru */ true); } else { /* DST_NOT_FOUND_IN_LRU */ quic_packets_stats->dst_not_found_in_lru += 1; @@ -809,6 +827,8 @@ process_packet(struct xdp_md* xdp, __u64 off, bool is_ipv6) { quic_packets_stats->ch_routed += 1; } else { quic_packets_stats->cid_initial += 1; + incr_server_id_routing_stats( + vip_num, /* new conn */ true, /* mismatch in lru */ false); } } } @@ -830,6 +850,8 @@ process_packet(struct xdp_md* xdp, __u64 off, bool is_ipv6) { if (pckt.flags & F_SYN_SET) { tpr_packets_stats->tcp_syn += 1; + incr_server_id_routing_stats( + vip_num, /* new conn */ true, /* mismatch in lru */ false); } else { if (tcp_hdr_opt_lookup(xdp, is_ipv6, &dst, &pckt) == FURTHER_PROCESSING) { @@ -841,6 +863,8 @@ process_packet(struct xdp_md* xdp, __u64 off, bool is_ipv6) { &pckt, lru_map, /* update_lru */ true); if (res == DST_MISMATCH_IN_LRU) { tpr_packets_stats->dst_mismatch_in_lru += 1; + incr_server_id_routing_stats( + vip_num, /* new conn */ false, /* mismatch in lru */ true); } } tpr_packets_stats->sid_routed += 1; @@ -905,7 +929,6 @@ process_packet(struct xdp_md* xdp, __u64 off, bool is_ipv6) { return XDP_DROP; } - vip_num = vip_info->vip_num; data_stats = bpf_map_lookup_elem(&stats, &vip_num); if (!data_stats) { return XDP_DROP; diff --git a/katran/lib/bpf/balancer_maps.h b/katran/lib/bpf/balancer_maps.h index a0bf2196d..e07ed4c7f 100644 --- a/katran/lib/bpf/balancer_maps.h +++ b/katran/lib/bpf/balancer_maps.h @@ -201,4 +201,12 @@ struct { __uint(map_flags, NO_FLAGS); } tpr_packets_stats_map SEC(".maps"); +struct { + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); + __type(key, __u32); + __type(value, struct lb_stats); + __uint(max_entries, MAX_VIPS); + __uint(map_flags, NO_FLAGS); +} server_id_routing_stats SEC(".maps"); + #endif // of _BALANCER_MAPS