-
Notifications
You must be signed in to change notification settings - Fork 930
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
Istio/XDS support #1804
Merged
Merged
Istio/XDS support #1804
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6937c5f
init xds client, balancer from grpc
zhshw 193d021
xds server from grpc
zhshw 6dd55e7
xds csds from grpc
zhshw ad7a530
xds bootstrap from grpc
zhshw 339db08
Fix: init test client
24ae453
Fix: init xds registry
c8aed72
Fix: init xds registry
226d8a9
Ftr: xds registry support
LaurenceLiZhixin 2a1ec24
Fix: conflict
LaurenceLiZhixin 55374e7
fix: support router
LaurenceLiZhixin c73695f
add comments
LaurenceLiZhixin 9838ce9
Fix: delete unused file
LaurenceLiZhixin c24faa0
i This is a combination of 2 commits.
227b4ab
Enhancement XDS ut. (#7)
LaurenceLiZhixin 67f6ed0
Fix: merge 3.0
LaurenceLiZhixin eb7230a
fix: grpc copyright
LaurenceLiZhixin 8602128
fix: xds comments
LaurenceLiZhixin aba60ca
Fix: compatiable to go 1.15
LaurenceLiZhixin e41ea18
fix: change cluster Id to ID
LaurenceLiZhixin 53a86dd
fix: rename to host addr
LaurenceLiZhixin abd851a
Fix: import formatter
LaurenceLiZhixin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package meshrouter | ||
|
||
import ( | ||
"dubbo.apache.org/dubbo-go/v3/cluster/router" | ||
"dubbo.apache.org/dubbo-go/v3/common/constant" | ||
"dubbo.apache.org/dubbo-go/v3/common/extension" | ||
) | ||
|
||
func init() { | ||
extension.SetRouterFactory(constant.MeshRouterFactoryKey, NewMeshRouterFactory) | ||
} | ||
|
||
// UniformRouteFactory is uniform router's factory | ||
type MeshRouterFactory struct{} | ||
|
||
// NewMeshRouterFactory constructs a new PriorityRouterFactory | ||
func NewMeshRouterFactory() router.PriorityRouterFactory { | ||
return &MeshRouterFactory{} | ||
} | ||
|
||
// NewPriorityRouter construct a new UniformRouteFactory as PriorityRouter | ||
func (f *MeshRouterFactory) NewPriorityRouter() (router.PriorityRouter, error) { | ||
return NewMeshRouter() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package meshrouter | ||
|
||
import ( | ||
"bytes" | ||
"math/rand" | ||
"strings" | ||
) | ||
|
||
import ( | ||
"dubbo.apache.org/dubbo-go/v3/cluster/router" | ||
"dubbo.apache.org/dubbo-go/v3/common" | ||
"dubbo.apache.org/dubbo-go/v3/common/constant" | ||
"dubbo.apache.org/dubbo-go/v3/common/logger" | ||
"dubbo.apache.org/dubbo-go/v3/config_center" | ||
"dubbo.apache.org/dubbo-go/v3/protocol" | ||
"dubbo.apache.org/dubbo-go/v3/remoting/xds" | ||
"dubbo.apache.org/dubbo-go/v3/xds/client/resource" | ||
"dubbo.apache.org/dubbo-go/v3/xds/utils/resolver" | ||
) | ||
|
||
const ( | ||
name = "mesh-router" | ||
) | ||
|
||
// MeshRouter have | ||
type MeshRouter struct { | ||
client *xds.WrappedClientImpl | ||
} | ||
|
||
// NewMeshRouter construct an NewConnCheckRouter via url | ||
func NewMeshRouter() (router.PriorityRouter, error) { | ||
xdsWrappedClient := xds.GetXDSWrappedClient() | ||
if xdsWrappedClient == nil { | ||
logger.Debugf("[Mesh Router] xds wrapped client is not created.") | ||
} | ||
return &MeshRouter{ | ||
client: xdsWrappedClient, | ||
}, nil | ||
} | ||
|
||
// Route gets a list of routed invoker | ||
func (r *MeshRouter) Route(invokers []protocol.Invoker, url *common.URL, invocation protocol.Invocation) []protocol.Invoker { | ||
if r.client == nil { | ||
return invokers | ||
} | ||
hostAddr, err := r.client.GetHostAddrByServiceUniqueKey(getSubscribeName(url)) | ||
if err != nil { | ||
// todo deal with error | ||
return nil | ||
} | ||
rconf := r.client.GetRouterConfig(hostAddr) | ||
|
||
clusterInvokerMap := make(map[string][]protocol.Invoker) | ||
for _, v := range invokers { | ||
meshClusterId := v.GetURL().GetParam(constant.MeshClusterIDKey, "") | ||
if _, ok := clusterInvokerMap[meshClusterId]; !ok { | ||
clusterInvokerMap[meshClusterId] = make([]protocol.Invoker, 0) | ||
} | ||
clusterInvokerMap[meshClusterId] = append(clusterInvokerMap[meshClusterId], v) | ||
} | ||
|
||
if len(rconf.VirtualHosts) != 0 { | ||
// try to route to sub virtual host | ||
for _, vh := range rconf.VirtualHosts { | ||
// 1. match domain | ||
//vh.Domains == ["*"] | ||
|
||
// 2. match http route | ||
for _, r := range vh.Routes { | ||
//route. | ||
ctx := invocation.ToContext() | ||
matcher, err := resource.RouteToMatcher(r) | ||
if err != nil { | ||
panic(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. panic 不能随便用,这里确实有必要使用 panic 吗? |
||
} | ||
if matcher.Match(resolver.RPCInfo{ | ||
Context: ctx, | ||
Method: "/" + invocation.MethodName(), | ||
}) { | ||
// Loop through routes in order and select first match. | ||
if r == nil || r.WeightedClusters == nil { | ||
panic("cluster notfound") | ||
} | ||
invokersWeightPairs := make(invokerWeightPairs, 0) | ||
|
||
for clusterId, weight := range r.WeightedClusters { | ||
// cluster -> invokers | ||
targetInvokers := clusterInvokerMap[clusterId] | ||
invokersWeightPairs = append(invokersWeightPairs, invokerWeightPair{ | ||
invokers: targetInvokers, | ||
weight: weight.Weight, | ||
}) | ||
} | ||
return invokersWeightPairs.GetInvokers() | ||
} | ||
} | ||
} | ||
} | ||
return invokers | ||
} | ||
|
||
// Process there is no process needs for uniform Router, as it upper struct RouterChain has done it | ||
func (r *MeshRouter) Process(event *config_center.ConfigChangeEvent) { | ||
} | ||
|
||
// Name get name of ConnCheckerRouter | ||
func (r *MeshRouter) Name() string { | ||
return name | ||
} | ||
|
||
// Priority get Router priority level | ||
func (r *MeshRouter) Priority() int64 { | ||
return 0 | ||
} | ||
|
||
// URL Return URL in router | ||
func (r *MeshRouter) URL() *common.URL { | ||
return nil | ||
} | ||
|
||
// Notify the router the invoker list | ||
func (r *MeshRouter) Notify(invokers []protocol.Invoker) { | ||
} | ||
|
||
type invokerWeightPair struct { | ||
invokers []protocol.Invoker | ||
weight uint32 | ||
} | ||
|
||
type invokerWeightPairs []invokerWeightPair | ||
|
||
func (i *invokerWeightPairs) GetInvokers() []protocol.Invoker { | ||
if len(*i) == 0 { | ||
return nil | ||
} | ||
totalWeight := uint32(0) | ||
tempWeight := uint32(0) | ||
for _, v := range *i { | ||
totalWeight += v.weight | ||
} | ||
randFloat := rand.Float64() | ||
for _, v := range *i { | ||
tempWeight += v.weight | ||
tempPercent := float64(tempWeight) / float64(totalWeight) | ||
if tempPercent >= randFloat { | ||
return v.invokers | ||
} | ||
} | ||
return (*i)[0].invokers | ||
} | ||
|
||
func getSubscribeName(url *common.URL) string { | ||
var buffer bytes.Buffer | ||
|
||
buffer.Write([]byte(common.DubboNodes[common.PROVIDER])) | ||
appendParam(&buffer, url, constant.InterfaceKey) | ||
appendParam(&buffer, url, constant.VersionKey) | ||
appendParam(&buffer, url, constant.GroupKey) | ||
return buffer.String() | ||
} | ||
|
||
func appendParam(target *bytes.Buffer, url *common.URL, key string) { | ||
value := url.GetParam(key, "") | ||
target.Write([]byte(constant.NacosServiceNameSeparator)) | ||
if strings.TrimSpace(value) != "" { | ||
target.Write([]byte(value)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package constant | ||
|
||
const ( | ||
MeshClusterIDKey = "meshClusterId" | ||
MeshHostAddrKey = "meshHostAddr" | ||
MeshSubsetKey = "meshSubset" | ||
|
||
MeshDeleteClusterPrefix = "-" | ||
MeshAnyAddrMatcher = "*" | ||
) | ||
|
||
const ( | ||
XDSMetadataClusterIDKey = "CLUSTER_ID" | ||
XDSMetadataLabelsKey = "LABELS" | ||
|
||
XDSMetadataDefaultDomainName = "Kubernetes" | ||
|
||
XDSMetadataDubboGoMapperKey = "DUBBO_GO" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我们要升级这个版本吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我认为升级吧。
1.15 版本不支持一些基础函数,比如os.ReadFile
开发者本地如果使用高版本,ci的时候会报错
@zhaoyunxing92
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯嗯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we discussed yesterday night, pls recover the go version.