Skip to content

agentk: round-robin load balancing for direct gRPC connections

Mikhail Mazurskiy requested to merge ash2k/agentk-round-robin-lb into master

Resolves #446 (closed).

Note the Channel #1, roundrobin, and balancer messages in the agentk log:

$ agentk --kas-address=grpc://gdk.test:8159 --token-file=/Users/mike/src/kas-stuff/token-gdk-a1.txt

{"level":"info","time":"2023-08-23T11:23:47.142+1000","msg":"[core] [Channel #1] Channel created"}
{"level":"info","time":"2023-08-23T11:23:47.142+1000","msg":"[core] [Channel #1] original dial target is: \"dns:gdk.test:8159\""}
{"level":"info","time":"2023-08-23T11:23:47.142+1000","msg":"[core] [Channel #1] parsed dial target is: {URL:{Scheme:dns Opaque:gdk.test:8159 User: Host: Path: RawPath: OmitHost:false ForceQuery:false RawQuery: Fragment: RawFragment:}}"}
{"level":"info","time":"2023-08-23T11:23:47.142+1000","msg":"[core] [Channel #1] Channel authority set to \"gdk.test:8159\""}
{"level":"info","time":"2023-08-23T11:23:47.142+1000","msg":"[core] [Channel #2] Channel created"}
{"level":"info","time":"2023-08-23T11:23:47.142+1000","msg":"[core] [Channel #2] original dial target is: \"passthrough:pipe\""}
{"level":"info","time":"2023-08-23T11:23:47.142+1000","msg":"[core] [Channel #2] parsed dial target is: {URL:{Scheme:passthrough Opaque:pipe User: Host: Path: RawPath: OmitHost:false ForceQuery:false RawQuery: Fragment: RawFragment:}}"}
{"level":"info","time":"2023-08-23T11:23:47.142+1000","msg":"[core] [Channel #2] Channel authority set to \"pipe\""}
{"level":"info","time":"2023-08-23T11:23:47.142+1000","msg":"[core] [Channel #2] Resolver state updated: {\n  \"Addresses\": [\n    {\n      \"Addr\": \"pipe\",\n      \"ServerName\": \"\",\n      \"Attributes\": null,\n      \"BalancerAttributes\": null,\n      \"Type\": 0,\n      \"Metadata\": null\n    }\n  ],\n  \"ServiceConfig\": null,\n  \"Attributes\": null\n} (resolver returned new addresses)"}
{"level":"info","time":"2023-08-23T11:23:47.142+1000","msg":"[core] [Channel #2] Channel switches to new LB policy \"pick_first\""}
{"level":"info","time":"2023-08-23T11:23:47.142+1000","msg":"[core] [Channel #2 SubChannel #3] Subchannel created"}
{"level":"info","time":"2023-08-23T11:23:47.142+1000","msg":"[core] [Channel #2] Channel Connectivity change to CONNECTING"}
{"level":"info","time":"2023-08-23T11:23:47.143+1000","msg":"[core] [Server #4] Server created"}
{"level":"info","time":"2023-08-23T11:23:47.143+1000","msg":"[core] [Channel #2 SubChannel #3] Subchannel Connectivity change to CONNECTING"}
{"level":"info","time":"2023-08-23T11:23:47.143+1000","msg":"[core] [Channel #2 SubChannel #3] Subchannel picks a new address \"pipe\" to connect"}
{"level":"info","time":"2023-08-23T11:23:47.143+1000","msg":"[core] pickfirstBalancer: UpdateSubConnState: 0x14000127e90, {CONNECTING <nil>}"}
{"level":"info","time":"2023-08-23T11:23:47.147+1000","msg":"[core] [Server #4 ListenSocket #5] ListenSocket created"}
{"level":"info","time":"2023-08-23T11:23:47.148+1000","msg":"[core] CPU time info is unavailable on non-linux environments."}
{"level":"info","time":"2023-08-23T11:23:47.148+1000","msg":"[core] [Channel #2 SubChannel #3] Subchannel Connectivity change to READY"}
{"level":"info","time":"2023-08-23T11:23:47.148+1000","msg":"[core] pickfirstBalancer: UpdateSubConnState: 0x14000127e90, {READY <nil>}"}
{"level":"info","time":"2023-08-23T11:23:47.148+1000","msg":"[core] [Channel #2] Channel Connectivity change to READY"}
{"level":"info","time":"2023-08-23T11:23:47.171+1000","msg":"[core] [Channel #1] Resolver state updated: {\n  \"Addresses\": [\n    {\n      \"Addr\": \"172.16.123.1:8159\",\n      \"ServerName\": \"\",\n      \"Attributes\": null,\n      \"BalancerAttributes\": null,\n      \"Type\": 0,\n      \"Metadata\": null\n    }\n  ],\n  \"ServiceConfig\": null,\n  \"Attributes\": null\n} (resolver returned new addresses)"}
{"level":"info","time":"2023-08-23T11:23:47.171+1000","msg":"[core] [Channel #1] Channel switches to new LB policy \"round_robin\""}
{"level":"info","time":"2023-08-23T11:23:47.171+1000","msg":"[balancer] base.baseBalancer: got new ClientConn state:  {{[{Addr: \"172.16.123.1:8159\", ServerName: \"\", }] <nil> <nil>} <nil>}"}
{"level":"info","time":"2023-08-23T11:23:47.171+1000","msg":"[core] [Channel #1 SubChannel #8] Subchannel created"}
{"level":"info","time":"2023-08-23T11:23:47.171+1000","msg":"[roundrobin] roundrobinPicker: Build called with info: {map[]}"}
{"level":"info","time":"2023-08-23T11:23:47.171+1000","msg":"[core] [Channel #1] Channel Connectivity change to CONNECTING"}
{"level":"info","time":"2023-08-23T11:23:47.171+1000","msg":"[core] [Channel #1 SubChannel #8] Subchannel Connectivity change to CONNECTING"}
{"level":"info","time":"2023-08-23T11:23:47.171+1000","msg":"[core] [Channel #1 SubChannel #8] Subchannel picks a new address \"172.16.123.1:8159\" to connect"}
{"level":"info","time":"2023-08-23T11:23:47.172+1000","msg":"[balancer] base.baseBalancer: handle SubConn state change: 0x140007f20c0, CONNECTING"}
{"level":"info","time":"2023-08-23T11:23:47.177+1000","msg":"[core] [Channel #1 SubChannel #8] Subchannel Connectivity change to READY"}
{"level":"info","time":"2023-08-23T11:23:47.177+1000","msg":"[balancer] base.baseBalancer: handle SubConn state change: 0x140007f20c0, READY"}
{"level":"info","time":"2023-08-23T11:23:47.177+1000","msg":"[roundrobin] roundrobinPicker: Build called with info: {map[SubConn(id:8):{{Addr: \"172.16.123.1:8159\", ServerName: \"\", }}]}"}
{"level":"info","time":"2023-08-23T11:23:47.177+1000","msg":"[core] [Channel #1] Channel Connectivity change to READY"}

Note that, although kas also uses the dns target name scheme, this MR does not change service config for those connections. This is because in kas' case it's only talking to a single IP kas, not to a multi-IP domain name.

Edited by Mikhail Mazurskiy

Merge request reports

Loading