Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(selector/global.go, selector/selector_test.go, transport/http/cl… #3473

Closed
wants to merge 1 commit into from

Conversation

chencheng8888
Copy link

@chencheng8888 chencheng8888 commented Nov 26, 2024

…ient.go, transport/http/client_test.go): add an option to choose the load balancing algorithm for HTTP

  • In selector/global.go, add function NewSelector to create a selector.Builder
  • In selector/selector_test.go, add a test for NewSelector
  • In transport/http/client.go, add 'selectBuilder' (selector.Builder) in clientOptions, and add function 'WithSelectBuilder' to set it. Also, adjust the function 'NewClient'
  • In transport/http/client_test.go, add a test for WithSelectBuilder

Description (what this PR does / why we need it):

给http添加能够自主选择负载均衡算法,而不借助全局的selectBuilder。其实是因为在我想使用kratos的负载均衡的时候,看官方文档的示例,其实不太清楚具体如何去使用,也是看了源码才知道,kratos是通过全局变量来设置的,所以我就想像通过向http.NewClient添加选择项(option)来设置要使用哪个负载均衡算法,如

// new http client
	hConn, err := http.NewClient(
		context.Background(),
		http.WithMiddleware(
			recovery.Recovery(),
		),
		http.WithEndpoint("discovery:///helloworld"),
		http.WithDiscovery(r),
		http.WithNodeFilter(filter.Version("2.0.0")),
		selector.WithSelectorBuilder(wrr.New()),
	)

Which issue(s) this PR fixes (resolves / be part of):

Other special notes for the reviewers:

…ient.go, transport/http/client_test.go): add an option to choose the load balancing algorithm for HTTP

* In selector/global.go, add function NewSelector to create a selector.Builder
* In selector/selector_test.go, add a test for NewSelector
* In transport/http/client.go, add 'selectBuilder' (selector.Builder) in clientOptions, and add function 'WithSelectBuilder' to set it. Also, adjust the function 'NewClient'
* In transport/http/client_test.go, add a test for WithSelectBuilder
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant