1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-10 09:50:43 +00:00
v2fly/main/commands/all/api/balancer_info.go

134 lines
3.3 KiB
Go
Raw Normal View History

v5: Health Check & LeastLoad Strategy (#589) * generate .pb.go * health checker conf * check logic * implement ping * fix check interval * improve check results * health check on add outbounds * fix tests * fix ping handler * fix min rtt < 0 * random alive * fix check all on add outbounds * least load strategy * conf codes optimize * improve least load strategy * improve health check on AddOutboundHandler * cleanup results with scheduler code optimize * health ping timeout default 5s * remove config of health ping round round 1 seems to be good enough * fix TestSimpleBalancer * add TestLeastLoadBalancer * add todos * lint and test fix * balancer fallback * api health stats command * add hc cmd to perform health checks * rename 'health stats' cmd to hci * many code optimizations * fix typo * select none if no match for baselines only config > prev 'select 1' behavior can achieved by baselines+expected=1 * add LeastLoadStrategy tests * don't select alive on no match, go to fallback * api hci refactor * more detailed info * ready for future new strategies * apply lint style * refactor: strategies don't need ref of balancer * change check interval unit to seconds > to reduce influence caused by what is described by new added FIXME * fix test * RouterService->RoutingService * Revert "generate .pb.go" This reverts commit 0e6fa1be889470d0ad9692f7279da45c030e1919. * make checks distributed > but `api hc` is the exception * BalancingStrategy interface optimize * fix random selects unchecked * upgrade cmd hci to bi & rename hc to bc * bi shows all balancers, while hci shows only heath-check-enabled ones * shows more info * fix test * api bi sort output * update according to review * remove checks on add outbound * refactor: move health checker inside to strategy * enables rounds setting for health ping * restore the random behavior, no ping, no pick alive > if future strategy based on HealthPing, just embed it like what LeastLoad does * apply lint style * code optimize * fix typo * update desc of bc bi * ping with head code optimize * force rouds to 1 if checks not distributed * leatload: select by standard deviations * health ping refactor * continuously applying results * config is easier to understand * checker interfaces simplifying * add maxRTT config to filter away high delay nodes * apply lint * cost for leastload * api bo to override balancer selecting * fix health ping statistics & fix test * check connectivity if ping fail * add tolerance setting & more detailed bi output * fix connectivity check * optimize bi output * should not put results when network is down * fixes @_@ * mux optimize * remove pause option of selecting overriding > it causes data racing * update bo desc * fix potential racing * simplify locking * switch sync.Mutex to avoid potential racing * add more tests * code optimize * code optimize * fix connectivity check when url not set
2021-01-30 00:31:11 +00:00
package api
import (
"fmt"
"os"
"sort"
"strings"
2021-02-17 00:07:12 +00:00
routerService "github.com/v2fly/v2ray-core/v4/app/router/command"
"github.com/v2fly/v2ray-core/v4/main/commands/base"
v5: Health Check & LeastLoad Strategy (#589) * generate .pb.go * health checker conf * check logic * implement ping * fix check interval * improve check results * health check on add outbounds * fix tests * fix ping handler * fix min rtt < 0 * random alive * fix check all on add outbounds * least load strategy * conf codes optimize * improve least load strategy * improve health check on AddOutboundHandler * cleanup results with scheduler code optimize * health ping timeout default 5s * remove config of health ping round round 1 seems to be good enough * fix TestSimpleBalancer * add TestLeastLoadBalancer * add todos * lint and test fix * balancer fallback * api health stats command * add hc cmd to perform health checks * rename 'health stats' cmd to hci * many code optimizations * fix typo * select none if no match for baselines only config > prev 'select 1' behavior can achieved by baselines+expected=1 * add LeastLoadStrategy tests * don't select alive on no match, go to fallback * api hci refactor * more detailed info * ready for future new strategies * apply lint style * refactor: strategies don't need ref of balancer * change check interval unit to seconds > to reduce influence caused by what is described by new added FIXME * fix test * RouterService->RoutingService * Revert "generate .pb.go" This reverts commit 0e6fa1be889470d0ad9692f7279da45c030e1919. * make checks distributed > but `api hc` is the exception * BalancingStrategy interface optimize * fix random selects unchecked * upgrade cmd hci to bi & rename hc to bc * bi shows all balancers, while hci shows only heath-check-enabled ones * shows more info * fix test * api bi sort output * update according to review * remove checks on add outbound * refactor: move health checker inside to strategy * enables rounds setting for health ping * restore the random behavior, no ping, no pick alive > if future strategy based on HealthPing, just embed it like what LeastLoad does * apply lint style * code optimize * fix typo * update desc of bc bi * ping with head code optimize * force rouds to 1 if checks not distributed * leatload: select by standard deviations * health ping refactor * continuously applying results * config is easier to understand * checker interfaces simplifying * add maxRTT config to filter away high delay nodes * apply lint * cost for leastload * api bo to override balancer selecting * fix health ping statistics & fix test * check connectivity if ping fail * add tolerance setting & more detailed bi output * fix connectivity check * optimize bi output * should not put results when network is down * fixes @_@ * mux optimize * remove pause option of selecting overriding > it causes data racing * update bo desc * fix potential racing * simplify locking * switch sync.Mutex to avoid potential racing * add more tests * code optimize * code optimize * fix connectivity check when url not set
2021-01-30 00:31:11 +00:00
)
// TODO: support "-json" flag for json output
v5: Health Check & LeastLoad Strategy (#589) * generate .pb.go * health checker conf * check logic * implement ping * fix check interval * improve check results * health check on add outbounds * fix tests * fix ping handler * fix min rtt < 0 * random alive * fix check all on add outbounds * least load strategy * conf codes optimize * improve least load strategy * improve health check on AddOutboundHandler * cleanup results with scheduler code optimize * health ping timeout default 5s * remove config of health ping round round 1 seems to be good enough * fix TestSimpleBalancer * add TestLeastLoadBalancer * add todos * lint and test fix * balancer fallback * api health stats command * add hc cmd to perform health checks * rename 'health stats' cmd to hci * many code optimizations * fix typo * select none if no match for baselines only config > prev 'select 1' behavior can achieved by baselines+expected=1 * add LeastLoadStrategy tests * don't select alive on no match, go to fallback * api hci refactor * more detailed info * ready for future new strategies * apply lint style * refactor: strategies don't need ref of balancer * change check interval unit to seconds > to reduce influence caused by what is described by new added FIXME * fix test * RouterService->RoutingService * Revert "generate .pb.go" This reverts commit 0e6fa1be889470d0ad9692f7279da45c030e1919. * make checks distributed > but `api hc` is the exception * BalancingStrategy interface optimize * fix random selects unchecked * upgrade cmd hci to bi & rename hc to bc * bi shows all balancers, while hci shows only heath-check-enabled ones * shows more info * fix test * api bi sort output * update according to review * remove checks on add outbound * refactor: move health checker inside to strategy * enables rounds setting for health ping * restore the random behavior, no ping, no pick alive > if future strategy based on HealthPing, just embed it like what LeastLoad does * apply lint style * code optimize * fix typo * update desc of bc bi * ping with head code optimize * force rouds to 1 if checks not distributed * leatload: select by standard deviations * health ping refactor * continuously applying results * config is easier to understand * checker interfaces simplifying * add maxRTT config to filter away high delay nodes * apply lint * cost for leastload * api bo to override balancer selecting * fix health ping statistics & fix test * check connectivity if ping fail * add tolerance setting & more detailed bi output * fix connectivity check * optimize bi output * should not put results when network is down * fixes @_@ * mux optimize * remove pause option of selecting overriding > it causes data racing * update bo desc * fix potential racing * simplify locking * switch sync.Mutex to avoid potential racing * add more tests * code optimize * code optimize * fix connectivity check when url not set
2021-01-30 00:31:11 +00:00
var cmdBalancerInfo = &base.Command{
CustomFlags: true,
UsageLine: "{{.Exec}} api bi [--server=127.0.0.1:8080] [balancer]...",
Short: "balancer information",
Long: `
Get information of specified balancers, including health, strategy
and selecting. If no balancer tag specified, get information of
all balancers.
> Make sure you have "RoutingService" set in "config.api.services"
of server config.
Arguments:
-json
Use json output.
-s, -server <server:port>
v5: Health Check & LeastLoad Strategy (#589) * generate .pb.go * health checker conf * check logic * implement ping * fix check interval * improve check results * health check on add outbounds * fix tests * fix ping handler * fix min rtt < 0 * random alive * fix check all on add outbounds * least load strategy * conf codes optimize * improve least load strategy * improve health check on AddOutboundHandler * cleanup results with scheduler code optimize * health ping timeout default 5s * remove config of health ping round round 1 seems to be good enough * fix TestSimpleBalancer * add TestLeastLoadBalancer * add todos * lint and test fix * balancer fallback * api health stats command * add hc cmd to perform health checks * rename 'health stats' cmd to hci * many code optimizations * fix typo * select none if no match for baselines only config > prev 'select 1' behavior can achieved by baselines+expected=1 * add LeastLoadStrategy tests * don't select alive on no match, go to fallback * api hci refactor * more detailed info * ready for future new strategies * apply lint style * refactor: strategies don't need ref of balancer * change check interval unit to seconds > to reduce influence caused by what is described by new added FIXME * fix test * RouterService->RoutingService * Revert "generate .pb.go" This reverts commit 0e6fa1be889470d0ad9692f7279da45c030e1919. * make checks distributed > but `api hc` is the exception * BalancingStrategy interface optimize * fix random selects unchecked * upgrade cmd hci to bi & rename hc to bc * bi shows all balancers, while hci shows only heath-check-enabled ones * shows more info * fix test * api bi sort output * update according to review * remove checks on add outbound * refactor: move health checker inside to strategy * enables rounds setting for health ping * restore the random behavior, no ping, no pick alive > if future strategy based on HealthPing, just embed it like what LeastLoad does * apply lint style * code optimize * fix typo * update desc of bc bi * ping with head code optimize * force rouds to 1 if checks not distributed * leatload: select by standard deviations * health ping refactor * continuously applying results * config is easier to understand * checker interfaces simplifying * add maxRTT config to filter away high delay nodes * apply lint * cost for leastload * api bo to override balancer selecting * fix health ping statistics & fix test * check connectivity if ping fail * add tolerance setting & more detailed bi output * fix connectivity check * optimize bi output * should not put results when network is down * fixes @_@ * mux optimize * remove pause option of selecting overriding > it causes data racing * update bo desc * fix potential racing * simplify locking * switch sync.Mutex to avoid potential racing * add more tests * code optimize * code optimize * fix connectivity check when url not set
2021-01-30 00:31:11 +00:00
The API server address. Default 127.0.0.1:8080
-t, -timeout <seconds>
v5: Health Check & LeastLoad Strategy (#589) * generate .pb.go * health checker conf * check logic * implement ping * fix check interval * improve check results * health check on add outbounds * fix tests * fix ping handler * fix min rtt < 0 * random alive * fix check all on add outbounds * least load strategy * conf codes optimize * improve least load strategy * improve health check on AddOutboundHandler * cleanup results with scheduler code optimize * health ping timeout default 5s * remove config of health ping round round 1 seems to be good enough * fix TestSimpleBalancer * add TestLeastLoadBalancer * add todos * lint and test fix * balancer fallback * api health stats command * add hc cmd to perform health checks * rename 'health stats' cmd to hci * many code optimizations * fix typo * select none if no match for baselines only config > prev 'select 1' behavior can achieved by baselines+expected=1 * add LeastLoadStrategy tests * don't select alive on no match, go to fallback * api hci refactor * more detailed info * ready for future new strategies * apply lint style * refactor: strategies don't need ref of balancer * change check interval unit to seconds > to reduce influence caused by what is described by new added FIXME * fix test * RouterService->RoutingService * Revert "generate .pb.go" This reverts commit 0e6fa1be889470d0ad9692f7279da45c030e1919. * make checks distributed > but `api hc` is the exception * BalancingStrategy interface optimize * fix random selects unchecked * upgrade cmd hci to bi & rename hc to bc * bi shows all balancers, while hci shows only heath-check-enabled ones * shows more info * fix test * api bi sort output * update according to review * remove checks on add outbound * refactor: move health checker inside to strategy * enables rounds setting for health ping * restore the random behavior, no ping, no pick alive > if future strategy based on HealthPing, just embed it like what LeastLoad does * apply lint style * code optimize * fix typo * update desc of bc bi * ping with head code optimize * force rouds to 1 if checks not distributed * leatload: select by standard deviations * health ping refactor * continuously applying results * config is easier to understand * checker interfaces simplifying * add maxRTT config to filter away high delay nodes * apply lint * cost for leastload * api bo to override balancer selecting * fix health ping statistics & fix test * check connectivity if ping fail * add tolerance setting & more detailed bi output * fix connectivity check * optimize bi output * should not put results when network is down * fixes @_@ * mux optimize * remove pause option of selecting overriding > it causes data racing * update bo desc * fix potential racing * simplify locking * switch sync.Mutex to avoid potential racing * add more tests * code optimize * code optimize * fix connectivity check when url not set
2021-01-30 00:31:11 +00:00
Timeout seconds to call API. Default 3
Example:
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 balancer1 balancer2
`,
Run: executeBalancerInfo,
}
func executeBalancerInfo(cmd *base.Command, args []string) {
setSharedFlags(cmd)
cmd.Flag.Parse(args)
conn, ctx, close := dialAPIServer()
defer close()
client := routerService.NewRoutingServiceClient(conn)
r := &routerService.GetBalancersRequest{BalancerTags: cmd.Flag.Args()}
resp, err := client.GetBalancers(ctx, r)
if err != nil {
base.Fatalf("failed to get health information: %s", err)
}
sort.Slice(resp.Balancers, func(i, j int) bool {
return resp.Balancers[i].Tag < resp.Balancers[j].Tag
})
if apiJSON {
showJSONResponse(resp)
return
}
v5: Health Check & LeastLoad Strategy (#589) * generate .pb.go * health checker conf * check logic * implement ping * fix check interval * improve check results * health check on add outbounds * fix tests * fix ping handler * fix min rtt < 0 * random alive * fix check all on add outbounds * least load strategy * conf codes optimize * improve least load strategy * improve health check on AddOutboundHandler * cleanup results with scheduler code optimize * health ping timeout default 5s * remove config of health ping round round 1 seems to be good enough * fix TestSimpleBalancer * add TestLeastLoadBalancer * add todos * lint and test fix * balancer fallback * api health stats command * add hc cmd to perform health checks * rename 'health stats' cmd to hci * many code optimizations * fix typo * select none if no match for baselines only config > prev 'select 1' behavior can achieved by baselines+expected=1 * add LeastLoadStrategy tests * don't select alive on no match, go to fallback * api hci refactor * more detailed info * ready for future new strategies * apply lint style * refactor: strategies don't need ref of balancer * change check interval unit to seconds > to reduce influence caused by what is described by new added FIXME * fix test * RouterService->RoutingService * Revert "generate .pb.go" This reverts commit 0e6fa1be889470d0ad9692f7279da45c030e1919. * make checks distributed > but `api hc` is the exception * BalancingStrategy interface optimize * fix random selects unchecked * upgrade cmd hci to bi & rename hc to bc * bi shows all balancers, while hci shows only heath-check-enabled ones * shows more info * fix test * api bi sort output * update according to review * remove checks on add outbound * refactor: move health checker inside to strategy * enables rounds setting for health ping * restore the random behavior, no ping, no pick alive > if future strategy based on HealthPing, just embed it like what LeastLoad does * apply lint style * code optimize * fix typo * update desc of bc bi * ping with head code optimize * force rouds to 1 if checks not distributed * leatload: select by standard deviations * health ping refactor * continuously applying results * config is easier to understand * checker interfaces simplifying * add maxRTT config to filter away high delay nodes * apply lint * cost for leastload * api bo to override balancer selecting * fix health ping statistics & fix test * check connectivity if ping fail * add tolerance setting & more detailed bi output * fix connectivity check * optimize bi output * should not put results when network is down * fixes @_@ * mux optimize * remove pause option of selecting overriding > it causes data racing * update bo desc * fix potential racing * simplify locking * switch sync.Mutex to avoid potential racing * add more tests * code optimize * code optimize * fix connectivity check when url not set
2021-01-30 00:31:11 +00:00
for _, b := range resp.Balancers {
showBalancerInfo(b)
}
}
func showBalancerInfo(b *routerService.BalancerMsg) {
const tableIndent = 4
v5: Health Check & LeastLoad Strategy (#589) * generate .pb.go * health checker conf * check logic * implement ping * fix check interval * improve check results * health check on add outbounds * fix tests * fix ping handler * fix min rtt < 0 * random alive * fix check all on add outbounds * least load strategy * conf codes optimize * improve least load strategy * improve health check on AddOutboundHandler * cleanup results with scheduler code optimize * health ping timeout default 5s * remove config of health ping round round 1 seems to be good enough * fix TestSimpleBalancer * add TestLeastLoadBalancer * add todos * lint and test fix * balancer fallback * api health stats command * add hc cmd to perform health checks * rename 'health stats' cmd to hci * many code optimizations * fix typo * select none if no match for baselines only config > prev 'select 1' behavior can achieved by baselines+expected=1 * add LeastLoadStrategy tests * don't select alive on no match, go to fallback * api hci refactor * more detailed info * ready for future new strategies * apply lint style * refactor: strategies don't need ref of balancer * change check interval unit to seconds > to reduce influence caused by what is described by new added FIXME * fix test * RouterService->RoutingService * Revert "generate .pb.go" This reverts commit 0e6fa1be889470d0ad9692f7279da45c030e1919. * make checks distributed > but `api hc` is the exception * BalancingStrategy interface optimize * fix random selects unchecked * upgrade cmd hci to bi & rename hc to bc * bi shows all balancers, while hci shows only heath-check-enabled ones * shows more info * fix test * api bi sort output * update according to review * remove checks on add outbound * refactor: move health checker inside to strategy * enables rounds setting for health ping * restore the random behavior, no ping, no pick alive > if future strategy based on HealthPing, just embed it like what LeastLoad does * apply lint style * code optimize * fix typo * update desc of bc bi * ping with head code optimize * force rouds to 1 if checks not distributed * leatload: select by standard deviations * health ping refactor * continuously applying results * config is easier to understand * checker interfaces simplifying * add maxRTT config to filter away high delay nodes * apply lint * cost for leastload * api bo to override balancer selecting * fix health ping statistics & fix test * check connectivity if ping fail * add tolerance setting & more detailed bi output * fix connectivity check * optimize bi output * should not put results when network is down * fixes @_@ * mux optimize * remove pause option of selecting overriding > it causes data racing * update bo desc * fix potential racing * simplify locking * switch sync.Mutex to avoid potential racing * add more tests * code optimize * code optimize * fix connectivity check when url not set
2021-01-30 00:31:11 +00:00
sb := new(strings.Builder)
// Balancer
sb.WriteString(fmt.Sprintf("Balancer: %s\n", b.Tag))
// Strategy
sb.WriteString(" - Strategy:\n")
for _, v := range b.StrategySettings {
sb.WriteString(fmt.Sprintf(" %s\n", v))
}
// Override
if b.Override != nil {
sb.WriteString(" - Selecting Override:\n")
until := fmt.Sprintf("until: %s", b.Override.Until)
writeRow(sb, tableIndent, 0, []string{until}, nil)
v5: Health Check & LeastLoad Strategy (#589) * generate .pb.go * health checker conf * check logic * implement ping * fix check interval * improve check results * health check on add outbounds * fix tests * fix ping handler * fix min rtt < 0 * random alive * fix check all on add outbounds * least load strategy * conf codes optimize * improve least load strategy * improve health check on AddOutboundHandler * cleanup results with scheduler code optimize * health ping timeout default 5s * remove config of health ping round round 1 seems to be good enough * fix TestSimpleBalancer * add TestLeastLoadBalancer * add todos * lint and test fix * balancer fallback * api health stats command * add hc cmd to perform health checks * rename 'health stats' cmd to hci * many code optimizations * fix typo * select none if no match for baselines only config > prev 'select 1' behavior can achieved by baselines+expected=1 * add LeastLoadStrategy tests * don't select alive on no match, go to fallback * api hci refactor * more detailed info * ready for future new strategies * apply lint style * refactor: strategies don't need ref of balancer * change check interval unit to seconds > to reduce influence caused by what is described by new added FIXME * fix test * RouterService->RoutingService * Revert "generate .pb.go" This reverts commit 0e6fa1be889470d0ad9692f7279da45c030e1919. * make checks distributed > but `api hc` is the exception * BalancingStrategy interface optimize * fix random selects unchecked * upgrade cmd hci to bi & rename hc to bc * bi shows all balancers, while hci shows only heath-check-enabled ones * shows more info * fix test * api bi sort output * update according to review * remove checks on add outbound * refactor: move health checker inside to strategy * enables rounds setting for health ping * restore the random behavior, no ping, no pick alive > if future strategy based on HealthPing, just embed it like what LeastLoad does * apply lint style * code optimize * fix typo * update desc of bc bi * ping with head code optimize * force rouds to 1 if checks not distributed * leatload: select by standard deviations * health ping refactor * continuously applying results * config is easier to understand * checker interfaces simplifying * add maxRTT config to filter away high delay nodes * apply lint * cost for leastload * api bo to override balancer selecting * fix health ping statistics & fix test * check connectivity if ping fail * add tolerance setting & more detailed bi output * fix connectivity check * optimize bi output * should not put results when network is down * fixes @_@ * mux optimize * remove pause option of selecting overriding > it causes data racing * update bo desc * fix potential racing * simplify locking * switch sync.Mutex to avoid potential racing * add more tests * code optimize * code optimize * fix connectivity check when url not set
2021-01-30 00:31:11 +00:00
for i, s := range b.Override.Selects {
writeRow(sb, tableIndent, i+1, []string{s}, nil)
v5: Health Check & LeastLoad Strategy (#589) * generate .pb.go * health checker conf * check logic * implement ping * fix check interval * improve check results * health check on add outbounds * fix tests * fix ping handler * fix min rtt < 0 * random alive * fix check all on add outbounds * least load strategy * conf codes optimize * improve least load strategy * improve health check on AddOutboundHandler * cleanup results with scheduler code optimize * health ping timeout default 5s * remove config of health ping round round 1 seems to be good enough * fix TestSimpleBalancer * add TestLeastLoadBalancer * add todos * lint and test fix * balancer fallback * api health stats command * add hc cmd to perform health checks * rename 'health stats' cmd to hci * many code optimizations * fix typo * select none if no match for baselines only config > prev 'select 1' behavior can achieved by baselines+expected=1 * add LeastLoadStrategy tests * don't select alive on no match, go to fallback * api hci refactor * more detailed info * ready for future new strategies * apply lint style * refactor: strategies don't need ref of balancer * change check interval unit to seconds > to reduce influence caused by what is described by new added FIXME * fix test * RouterService->RoutingService * Revert "generate .pb.go" This reverts commit 0e6fa1be889470d0ad9692f7279da45c030e1919. * make checks distributed > but `api hc` is the exception * BalancingStrategy interface optimize * fix random selects unchecked * upgrade cmd hci to bi & rename hc to bc * bi shows all balancers, while hci shows only heath-check-enabled ones * shows more info * fix test * api bi sort output * update according to review * remove checks on add outbound * refactor: move health checker inside to strategy * enables rounds setting for health ping * restore the random behavior, no ping, no pick alive > if future strategy based on HealthPing, just embed it like what LeastLoad does * apply lint style * code optimize * fix typo * update desc of bc bi * ping with head code optimize * force rouds to 1 if checks not distributed * leatload: select by standard deviations * health ping refactor * continuously applying results * config is easier to understand * checker interfaces simplifying * add maxRTT config to filter away high delay nodes * apply lint * cost for leastload * api bo to override balancer selecting * fix health ping statistics & fix test * check connectivity if ping fail * add tolerance setting & more detailed bi output * fix connectivity check * optimize bi output * should not put results when network is down * fixes @_@ * mux optimize * remove pause option of selecting overriding > it causes data racing * update bo desc * fix potential racing * simplify locking * switch sync.Mutex to avoid potential racing * add more tests * code optimize * code optimize * fix connectivity check when url not set
2021-01-30 00:31:11 +00:00
}
}
b.Titles = append(b.Titles, "Tag")
v5: Health Check & LeastLoad Strategy (#589) * generate .pb.go * health checker conf * check logic * implement ping * fix check interval * improve check results * health check on add outbounds * fix tests * fix ping handler * fix min rtt < 0 * random alive * fix check all on add outbounds * least load strategy * conf codes optimize * improve least load strategy * improve health check on AddOutboundHandler * cleanup results with scheduler code optimize * health ping timeout default 5s * remove config of health ping round round 1 seems to be good enough * fix TestSimpleBalancer * add TestLeastLoadBalancer * add todos * lint and test fix * balancer fallback * api health stats command * add hc cmd to perform health checks * rename 'health stats' cmd to hci * many code optimizations * fix typo * select none if no match for baselines only config > prev 'select 1' behavior can achieved by baselines+expected=1 * add LeastLoadStrategy tests * don't select alive on no match, go to fallback * api hci refactor * more detailed info * ready for future new strategies * apply lint style * refactor: strategies don't need ref of balancer * change check interval unit to seconds > to reduce influence caused by what is described by new added FIXME * fix test * RouterService->RoutingService * Revert "generate .pb.go" This reverts commit 0e6fa1be889470d0ad9692f7279da45c030e1919. * make checks distributed > but `api hc` is the exception * BalancingStrategy interface optimize * fix random selects unchecked * upgrade cmd hci to bi & rename hc to bc * bi shows all balancers, while hci shows only heath-check-enabled ones * shows more info * fix test * api bi sort output * update according to review * remove checks on add outbound * refactor: move health checker inside to strategy * enables rounds setting for health ping * restore the random behavior, no ping, no pick alive > if future strategy based on HealthPing, just embed it like what LeastLoad does * apply lint style * code optimize * fix typo * update desc of bc bi * ping with head code optimize * force rouds to 1 if checks not distributed * leatload: select by standard deviations * health ping refactor * continuously applying results * config is easier to understand * checker interfaces simplifying * add maxRTT config to filter away high delay nodes * apply lint * cost for leastload * api bo to override balancer selecting * fix health ping statistics & fix test * check connectivity if ping fail * add tolerance setting & more detailed bi output * fix connectivity check * optimize bi output * should not put results when network is down * fixes @_@ * mux optimize * remove pause option of selecting overriding > it causes data racing * update bo desc * fix potential racing * simplify locking * switch sync.Mutex to avoid potential racing * add more tests * code optimize * code optimize * fix connectivity check when url not set
2021-01-30 00:31:11 +00:00
formats := getColumnFormats(b.Titles)
// Selects
sb.WriteString(" - Selects:\n")
writeRow(sb, tableIndent, 0, b.Titles, formats)
v5: Health Check & LeastLoad Strategy (#589) * generate .pb.go * health checker conf * check logic * implement ping * fix check interval * improve check results * health check on add outbounds * fix tests * fix ping handler * fix min rtt < 0 * random alive * fix check all on add outbounds * least load strategy * conf codes optimize * improve least load strategy * improve health check on AddOutboundHandler * cleanup results with scheduler code optimize * health ping timeout default 5s * remove config of health ping round round 1 seems to be good enough * fix TestSimpleBalancer * add TestLeastLoadBalancer * add todos * lint and test fix * balancer fallback * api health stats command * add hc cmd to perform health checks * rename 'health stats' cmd to hci * many code optimizations * fix typo * select none if no match for baselines only config > prev 'select 1' behavior can achieved by baselines+expected=1 * add LeastLoadStrategy tests * don't select alive on no match, go to fallback * api hci refactor * more detailed info * ready for future new strategies * apply lint style * refactor: strategies don't need ref of balancer * change check interval unit to seconds > to reduce influence caused by what is described by new added FIXME * fix test * RouterService->RoutingService * Revert "generate .pb.go" This reverts commit 0e6fa1be889470d0ad9692f7279da45c030e1919. * make checks distributed > but `api hc` is the exception * BalancingStrategy interface optimize * fix random selects unchecked * upgrade cmd hci to bi & rename hc to bc * bi shows all balancers, while hci shows only heath-check-enabled ones * shows more info * fix test * api bi sort output * update according to review * remove checks on add outbound * refactor: move health checker inside to strategy * enables rounds setting for health ping * restore the random behavior, no ping, no pick alive > if future strategy based on HealthPing, just embed it like what LeastLoad does * apply lint style * code optimize * fix typo * update desc of bc bi * ping with head code optimize * force rouds to 1 if checks not distributed * leatload: select by standard deviations * health ping refactor * continuously applying results * config is easier to understand * checker interfaces simplifying * add maxRTT config to filter away high delay nodes * apply lint * cost for leastload * api bo to override balancer selecting * fix health ping statistics & fix test * check connectivity if ping fail * add tolerance setting & more detailed bi output * fix connectivity check * optimize bi output * should not put results when network is down * fixes @_@ * mux optimize * remove pause option of selecting overriding > it causes data racing * update bo desc * fix potential racing * simplify locking * switch sync.Mutex to avoid potential racing * add more tests * code optimize * code optimize * fix connectivity check when url not set
2021-01-30 00:31:11 +00:00
for i, o := range b.Selects {
o.Values = append(o.Values, o.Tag)
writeRow(sb, tableIndent, i+1, o.Values, formats)
v5: Health Check & LeastLoad Strategy (#589) * generate .pb.go * health checker conf * check logic * implement ping * fix check interval * improve check results * health check on add outbounds * fix tests * fix ping handler * fix min rtt < 0 * random alive * fix check all on add outbounds * least load strategy * conf codes optimize * improve least load strategy * improve health check on AddOutboundHandler * cleanup results with scheduler code optimize * health ping timeout default 5s * remove config of health ping round round 1 seems to be good enough * fix TestSimpleBalancer * add TestLeastLoadBalancer * add todos * lint and test fix * balancer fallback * api health stats command * add hc cmd to perform health checks * rename 'health stats' cmd to hci * many code optimizations * fix typo * select none if no match for baselines only config > prev 'select 1' behavior can achieved by baselines+expected=1 * add LeastLoadStrategy tests * don't select alive on no match, go to fallback * api hci refactor * more detailed info * ready for future new strategies * apply lint style * refactor: strategies don't need ref of balancer * change check interval unit to seconds > to reduce influence caused by what is described by new added FIXME * fix test * RouterService->RoutingService * Revert "generate .pb.go" This reverts commit 0e6fa1be889470d0ad9692f7279da45c030e1919. * make checks distributed > but `api hc` is the exception * BalancingStrategy interface optimize * fix random selects unchecked * upgrade cmd hci to bi & rename hc to bc * bi shows all balancers, while hci shows only heath-check-enabled ones * shows more info * fix test * api bi sort output * update according to review * remove checks on add outbound * refactor: move health checker inside to strategy * enables rounds setting for health ping * restore the random behavior, no ping, no pick alive > if future strategy based on HealthPing, just embed it like what LeastLoad does * apply lint style * code optimize * fix typo * update desc of bc bi * ping with head code optimize * force rouds to 1 if checks not distributed * leatload: select by standard deviations * health ping refactor * continuously applying results * config is easier to understand * checker interfaces simplifying * add maxRTT config to filter away high delay nodes * apply lint * cost for leastload * api bo to override balancer selecting * fix health ping statistics & fix test * check connectivity if ping fail * add tolerance setting & more detailed bi output * fix connectivity check * optimize bi output * should not put results when network is down * fixes @_@ * mux optimize * remove pause option of selecting overriding > it causes data racing * update bo desc * fix potential racing * simplify locking * switch sync.Mutex to avoid potential racing * add more tests * code optimize * code optimize * fix connectivity check when url not set
2021-01-30 00:31:11 +00:00
}
// Others
scnt := len(b.Selects)
if len(b.Others) > 0 {
sb.WriteString(" - Others:\n")
writeRow(sb, tableIndent, 0, b.Titles, formats)
v5: Health Check & LeastLoad Strategy (#589) * generate .pb.go * health checker conf * check logic * implement ping * fix check interval * improve check results * health check on add outbounds * fix tests * fix ping handler * fix min rtt < 0 * random alive * fix check all on add outbounds * least load strategy * conf codes optimize * improve least load strategy * improve health check on AddOutboundHandler * cleanup results with scheduler code optimize * health ping timeout default 5s * remove config of health ping round round 1 seems to be good enough * fix TestSimpleBalancer * add TestLeastLoadBalancer * add todos * lint and test fix * balancer fallback * api health stats command * add hc cmd to perform health checks * rename 'health stats' cmd to hci * many code optimizations * fix typo * select none if no match for baselines only config > prev 'select 1' behavior can achieved by baselines+expected=1 * add LeastLoadStrategy tests * don't select alive on no match, go to fallback * api hci refactor * more detailed info * ready for future new strategies * apply lint style * refactor: strategies don't need ref of balancer * change check interval unit to seconds > to reduce influence caused by what is described by new added FIXME * fix test * RouterService->RoutingService * Revert "generate .pb.go" This reverts commit 0e6fa1be889470d0ad9692f7279da45c030e1919. * make checks distributed > but `api hc` is the exception * BalancingStrategy interface optimize * fix random selects unchecked * upgrade cmd hci to bi & rename hc to bc * bi shows all balancers, while hci shows only heath-check-enabled ones * shows more info * fix test * api bi sort output * update according to review * remove checks on add outbound * refactor: move health checker inside to strategy * enables rounds setting for health ping * restore the random behavior, no ping, no pick alive > if future strategy based on HealthPing, just embed it like what LeastLoad does * apply lint style * code optimize * fix typo * update desc of bc bi * ping with head code optimize * force rouds to 1 if checks not distributed * leatload: select by standard deviations * health ping refactor * continuously applying results * config is easier to understand * checker interfaces simplifying * add maxRTT config to filter away high delay nodes * apply lint * cost for leastload * api bo to override balancer selecting * fix health ping statistics & fix test * check connectivity if ping fail * add tolerance setting & more detailed bi output * fix connectivity check * optimize bi output * should not put results when network is down * fixes @_@ * mux optimize * remove pause option of selecting overriding > it causes data racing * update bo desc * fix potential racing * simplify locking * switch sync.Mutex to avoid potential racing * add more tests * code optimize * code optimize * fix connectivity check when url not set
2021-01-30 00:31:11 +00:00
for i, o := range b.Others {
o.Values = append(o.Values, o.Tag)
writeRow(sb, tableIndent, scnt+i+1, o.Values, formats)
v5: Health Check & LeastLoad Strategy (#589) * generate .pb.go * health checker conf * check logic * implement ping * fix check interval * improve check results * health check on add outbounds * fix tests * fix ping handler * fix min rtt < 0 * random alive * fix check all on add outbounds * least load strategy * conf codes optimize * improve least load strategy * improve health check on AddOutboundHandler * cleanup results with scheduler code optimize * health ping timeout default 5s * remove config of health ping round round 1 seems to be good enough * fix TestSimpleBalancer * add TestLeastLoadBalancer * add todos * lint and test fix * balancer fallback * api health stats command * add hc cmd to perform health checks * rename 'health stats' cmd to hci * many code optimizations * fix typo * select none if no match for baselines only config > prev 'select 1' behavior can achieved by baselines+expected=1 * add LeastLoadStrategy tests * don't select alive on no match, go to fallback * api hci refactor * more detailed info * ready for future new strategies * apply lint style * refactor: strategies don't need ref of balancer * change check interval unit to seconds > to reduce influence caused by what is described by new added FIXME * fix test * RouterService->RoutingService * Revert "generate .pb.go" This reverts commit 0e6fa1be889470d0ad9692f7279da45c030e1919. * make checks distributed > but `api hc` is the exception * BalancingStrategy interface optimize * fix random selects unchecked * upgrade cmd hci to bi & rename hc to bc * bi shows all balancers, while hci shows only heath-check-enabled ones * shows more info * fix test * api bi sort output * update according to review * remove checks on add outbound * refactor: move health checker inside to strategy * enables rounds setting for health ping * restore the random behavior, no ping, no pick alive > if future strategy based on HealthPing, just embed it like what LeastLoad does * apply lint style * code optimize * fix typo * update desc of bc bi * ping with head code optimize * force rouds to 1 if checks not distributed * leatload: select by standard deviations * health ping refactor * continuously applying results * config is easier to understand * checker interfaces simplifying * add maxRTT config to filter away high delay nodes * apply lint * cost for leastload * api bo to override balancer selecting * fix health ping statistics & fix test * check connectivity if ping fail * add tolerance setting & more detailed bi output * fix connectivity check * optimize bi output * should not put results when network is down * fixes @_@ * mux optimize * remove pause option of selecting overriding > it causes data racing * update bo desc * fix potential racing * simplify locking * switch sync.Mutex to avoid potential racing * add more tests * code optimize * code optimize * fix connectivity check when url not set
2021-01-30 00:31:11 +00:00
}
}
os.Stdout.WriteString(sb.String())
}
func getColumnFormats(titles []string) []string {
w := make([]string, len(titles))
for i, t := range titles {
w[i] = fmt.Sprintf("%%-%ds ", len(t))
}
return w
}
func writeRow(sb *strings.Builder, indent, index int, values, formats []string) {
v5: Health Check & LeastLoad Strategy (#589) * generate .pb.go * health checker conf * check logic * implement ping * fix check interval * improve check results * health check on add outbounds * fix tests * fix ping handler * fix min rtt < 0 * random alive * fix check all on add outbounds * least load strategy * conf codes optimize * improve least load strategy * improve health check on AddOutboundHandler * cleanup results with scheduler code optimize * health ping timeout default 5s * remove config of health ping round round 1 seems to be good enough * fix TestSimpleBalancer * add TestLeastLoadBalancer * add todos * lint and test fix * balancer fallback * api health stats command * add hc cmd to perform health checks * rename 'health stats' cmd to hci * many code optimizations * fix typo * select none if no match for baselines only config > prev 'select 1' behavior can achieved by baselines+expected=1 * add LeastLoadStrategy tests * don't select alive on no match, go to fallback * api hci refactor * more detailed info * ready for future new strategies * apply lint style * refactor: strategies don't need ref of balancer * change check interval unit to seconds > to reduce influence caused by what is described by new added FIXME * fix test * RouterService->RoutingService * Revert "generate .pb.go" This reverts commit 0e6fa1be889470d0ad9692f7279da45c030e1919. * make checks distributed > but `api hc` is the exception * BalancingStrategy interface optimize * fix random selects unchecked * upgrade cmd hci to bi & rename hc to bc * bi shows all balancers, while hci shows only heath-check-enabled ones * shows more info * fix test * api bi sort output * update according to review * remove checks on add outbound * refactor: move health checker inside to strategy * enables rounds setting for health ping * restore the random behavior, no ping, no pick alive > if future strategy based on HealthPing, just embed it like what LeastLoad does * apply lint style * code optimize * fix typo * update desc of bc bi * ping with head code optimize * force rouds to 1 if checks not distributed * leatload: select by standard deviations * health ping refactor * continuously applying results * config is easier to understand * checker interfaces simplifying * add maxRTT config to filter away high delay nodes * apply lint * cost for leastload * api bo to override balancer selecting * fix health ping statistics & fix test * check connectivity if ping fail * add tolerance setting & more detailed bi output * fix connectivity check * optimize bi output * should not put results when network is down * fixes @_@ * mux optimize * remove pause option of selecting overriding > it causes data racing * update bo desc * fix potential racing * simplify locking * switch sync.Mutex to avoid potential racing * add more tests * code optimize * code optimize * fix connectivity check when url not set
2021-01-30 00:31:11 +00:00
if index == 0 {
// title line
sb.WriteString(strings.Repeat(" ", indent+4))
v5: Health Check & LeastLoad Strategy (#589) * generate .pb.go * health checker conf * check logic * implement ping * fix check interval * improve check results * health check on add outbounds * fix tests * fix ping handler * fix min rtt < 0 * random alive * fix check all on add outbounds * least load strategy * conf codes optimize * improve least load strategy * improve health check on AddOutboundHandler * cleanup results with scheduler code optimize * health ping timeout default 5s * remove config of health ping round round 1 seems to be good enough * fix TestSimpleBalancer * add TestLeastLoadBalancer * add todos * lint and test fix * balancer fallback * api health stats command * add hc cmd to perform health checks * rename 'health stats' cmd to hci * many code optimizations * fix typo * select none if no match for baselines only config > prev 'select 1' behavior can achieved by baselines+expected=1 * add LeastLoadStrategy tests * don't select alive on no match, go to fallback * api hci refactor * more detailed info * ready for future new strategies * apply lint style * refactor: strategies don't need ref of balancer * change check interval unit to seconds > to reduce influence caused by what is described by new added FIXME * fix test * RouterService->RoutingService * Revert "generate .pb.go" This reverts commit 0e6fa1be889470d0ad9692f7279da45c030e1919. * make checks distributed > but `api hc` is the exception * BalancingStrategy interface optimize * fix random selects unchecked * upgrade cmd hci to bi & rename hc to bc * bi shows all balancers, while hci shows only heath-check-enabled ones * shows more info * fix test * api bi sort output * update according to review * remove checks on add outbound * refactor: move health checker inside to strategy * enables rounds setting for health ping * restore the random behavior, no ping, no pick alive > if future strategy based on HealthPing, just embed it like what LeastLoad does * apply lint style * code optimize * fix typo * update desc of bc bi * ping with head code optimize * force rouds to 1 if checks not distributed * leatload: select by standard deviations * health ping refactor * continuously applying results * config is easier to understand * checker interfaces simplifying * add maxRTT config to filter away high delay nodes * apply lint * cost for leastload * api bo to override balancer selecting * fix health ping statistics & fix test * check connectivity if ping fail * add tolerance setting & more detailed bi output * fix connectivity check * optimize bi output * should not put results when network is down * fixes @_@ * mux optimize * remove pause option of selecting overriding > it causes data racing * update bo desc * fix potential racing * simplify locking * switch sync.Mutex to avoid potential racing * add more tests * code optimize * code optimize * fix connectivity check when url not set
2021-01-30 00:31:11 +00:00
} else {
sb.WriteString(fmt.Sprintf("%s%-4d", strings.Repeat(" ", indent), index))
v5: Health Check & LeastLoad Strategy (#589) * generate .pb.go * health checker conf * check logic * implement ping * fix check interval * improve check results * health check on add outbounds * fix tests * fix ping handler * fix min rtt < 0 * random alive * fix check all on add outbounds * least load strategy * conf codes optimize * improve least load strategy * improve health check on AddOutboundHandler * cleanup results with scheduler code optimize * health ping timeout default 5s * remove config of health ping round round 1 seems to be good enough * fix TestSimpleBalancer * add TestLeastLoadBalancer * add todos * lint and test fix * balancer fallback * api health stats command * add hc cmd to perform health checks * rename 'health stats' cmd to hci * many code optimizations * fix typo * select none if no match for baselines only config > prev 'select 1' behavior can achieved by baselines+expected=1 * add LeastLoadStrategy tests * don't select alive on no match, go to fallback * api hci refactor * more detailed info * ready for future new strategies * apply lint style * refactor: strategies don't need ref of balancer * change check interval unit to seconds > to reduce influence caused by what is described by new added FIXME * fix test * RouterService->RoutingService * Revert "generate .pb.go" This reverts commit 0e6fa1be889470d0ad9692f7279da45c030e1919. * make checks distributed > but `api hc` is the exception * BalancingStrategy interface optimize * fix random selects unchecked * upgrade cmd hci to bi & rename hc to bc * bi shows all balancers, while hci shows only heath-check-enabled ones * shows more info * fix test * api bi sort output * update according to review * remove checks on add outbound * refactor: move health checker inside to strategy * enables rounds setting for health ping * restore the random behavior, no ping, no pick alive > if future strategy based on HealthPing, just embed it like what LeastLoad does * apply lint style * code optimize * fix typo * update desc of bc bi * ping with head code optimize * force rouds to 1 if checks not distributed * leatload: select by standard deviations * health ping refactor * continuously applying results * config is easier to understand * checker interfaces simplifying * add maxRTT config to filter away high delay nodes * apply lint * cost for leastload * api bo to override balancer selecting * fix health ping statistics & fix test * check connectivity if ping fail * add tolerance setting & more detailed bi output * fix connectivity check * optimize bi output * should not put results when network is down * fixes @_@ * mux optimize * remove pause option of selecting overriding > it causes data racing * update bo desc * fix potential racing * simplify locking * switch sync.Mutex to avoid potential racing * add more tests * code optimize * code optimize * fix connectivity check when url not set
2021-01-30 00:31:11 +00:00
}
for i, v := range values {
format := "%-14s"
if i < len(formats) {
format = formats[i]
}
sb.WriteString(fmt.Sprintf(format, v))
}
sb.WriteByte('\n')
}