Skip to content

Commit

Permalink
introduce per vip sid routing stats
Browse files Browse the repository at this point in the history
Summary: as per title

Reviewed By: avasylev

Differential Revision: D49685686

fbshipit-source-id: 38636551a94aa92df70e98c83a32b60ede3772ec
  • Loading branch information
Fei Chen authored and facebook-github-bot committed Oct 5, 2023
1 parent ec61082 commit 80040c7
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
14 changes: 14 additions & 0 deletions katran/lib/KatranLb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2584,4 +2584,18 @@ std::vector<int> 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
9 changes: 9 additions & 0 deletions katran/lib/KatranLb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 24 additions & 1 deletion katran/lib/bpf/balancer.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}
}
Expand All @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions katran/lib/bpf/balancer_maps.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 80040c7

Please sign in to comment.