Skip to content

Commit e9af645

Browse files
optimize logic
Signed-off-by: 923048992@qq.com <923048992@qq.com>
1 parent 8615e75 commit e9af645

File tree

10 files changed

+21
-498
lines changed

10 files changed

+21
-498
lines changed

bpf/kmesh/ads/include/circuit_breaker.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ struct {
4242

4343
static inline void update_cluster_active_connections(const struct cluster_stats_key *key, int delta)
4444
{
45+
struct cluster_stats *stats = NULL;
4546
if (!key) {
4647
return;
4748
}
48-
struct cluster_stats *stats = NULL;
4949
stats = kmesh_map_lookup_elem(&map_of_cluster_stats, key);
5050
if (!stats) {
5151
struct cluster_stats init_value = {0};
@@ -67,7 +67,8 @@ static inline void update_cluster_active_connections(const struct cluster_stats_
6767
BPF_LOG(
6868
DEBUG,
6969
CIRCUIT_BREAKER,
70-
"update existing stats(netns_cookie = %lld, cluster_id = %ld), current active connections: %d",
70+
"update existing stats(netns_cookie = %lld, cluster_id = %ld), "
71+
"current active connections: %d",
7172
key->netns_cookie,
7273
key->cluster_id,
7374
stats->active_connections);
@@ -90,7 +91,8 @@ static inline int on_cluster_sock_bind(ctx_buff_t *ctx, const Cluster__Cluster *
9091
BPF_LOG(
9192
DEBUG,
9293
CIRCUIT_BREAKER,
93-
"Current active connections %d exceeded max connections %d, reject connection",
94+
"Current active connections %d exceeded max connections "
95+
"%d, reject connection",
9496
stats->active_connections,
9597
cbs->max_connections);
9698
return -1;
@@ -141,7 +143,8 @@ static inline void on_cluster_sock_connect(struct bpf_sock_ops *ctx)
141143
BPF_LOG(
142144
DEBUG,
143145
CIRCUIT_BREAKER,
144-
"increase cluster active connections(netns_cookie = %lld, cluster id = %ld)",
146+
"increase cluster active connections(netns_cookie = %lld, cluster "
147+
"id = %ld)",
145148
key.netns_cookie,
146149
key.cluster_id);
147150
update_cluster_active_connections(&key, 1);
@@ -165,7 +168,8 @@ static inline void on_cluster_sock_close(struct bpf_sock_ops *ctx)
165168
BPF_LOG(
166169
DEBUG,
167170
CIRCUIT_BREAKER,
168-
"decrease cluster active connections(netns_cookie = %lld, cluster id = %ld)",
171+
"decrease cluster active connections(netns_cookie = %lld, cluster "
172+
"id = %ld)",
169173
key.netns_cookie,
170174
key.cluster_id);
171175
BPF_LOG(DEBUG, CIRCUIT_BREAKER, "record sock close for cluster id = %ld", data->cluster_id);

bpf/kmesh/ads/include/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#define map_of_virtual_host kmesh_virtual_host
4747
#define map_of_route kmesh_route
4848
#define map_of_cluster kmesh_cluster
49+
#define map_of_cluster_stats kmesh_cluster_stats
4950
#define map_of_loadbalance kmesh_loadbalance
5051
#define map_of_endpoint kmesh_endpoint
5152
#define map_of_tail_call_prog kmesh_tail_call_prog

bpf/kmesh/ads/include/kmesh_common.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,31 +71,6 @@ static inline char *bpf_strncpy(char *dst, int n, const char *src)
7171
}
7272
#endif
7373

74-
struct {
75-
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
76-
__uint(key_size, sizeof(__u32));
77-
__uint(value_size, sizeof(__u32));
78-
__uint(max_entries, MAP_SIZE_OF_OUTTER_MAP);
79-
__uint(map_flags, 0);
80-
} outer_map SEC(".maps");
81-
82-
struct {
83-
__uint(type, BPF_MAP_TYPE_ARRAY);
84-
__uint(key_size, sizeof(__u32));
85-
__uint(value_size, BPF_INNER_MAP_DATA_LEN);
86-
__uint(max_entries, 1);
87-
__uint(map_flags, 0);
88-
} inner_map SEC(".maps");
89-
90-
typedef enum {
91-
KMESH_TAIL_CALL_LISTENER = 1,
92-
KMESH_TAIL_CALL_FILTER_CHAIN,
93-
KMESH_TAIL_CALL_FILTER,
94-
KMESH_TAIL_CALL_ROUTER,
95-
KMESH_TAIL_CALL_CLUSTER,
96-
KMESH_TAIL_CALL_ROUTER_CONFIG,
97-
} tail_call_index_t;
98-
9974
typedef Core__SocketAddress address_t;
10075

10176
// bpf return value

pkg/bpf/ads/loader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (sc *BpfAds) Detach() error {
142142
}
143143

144144
func (sc *BpfAds) GetClusterStatsMap() *ebpf.Map {
145-
return nil
145+
return sc.SockConn.KmeshCgroupSockMaps.KmeshClusterStats
146146
}
147147

148148
func AdsL7Enabled() bool {

pkg/bpf/ads/loader_enhanced.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (sc *BpfAds) Detach() error {
186186
}
187187

188188
func (sc *BpfAds) GetClusterStatsMap() *ebpf.Map {
189-
return sc.SockOps.KmeshSockopsMaps.MapOfClusterStats
189+
return sc.SockOps.KmeshSockopsMaps.KmeshClusterStats
190190
}
191191

192192
func AdsL7Enabled() bool {

0 commit comments

Comments
 (0)