-
Notifications
You must be signed in to change notification settings - Fork 14
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
Opt #8
Opt #8
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,8 @@ func convertServiceEntry(service string, endpoints []*api.CatalogService) *istio | |
for _, endpoint := range endpoints { | ||
name = endpoint.ServiceName | ||
|
||
port := convertPort(endpoint.ServicePort, endpoint.ServiceMeta[protocolTagName]) | ||
protoName := getProtoValFromServiceTagsOrMeta(endpoint.ServiceTags, endpoint.ServiceMeta[protocolTagName]) | ||
port := convertPort(endpoint.ServicePort, protoName) | ||
|
||
if svcPort, exists := ports[port.Number]; exists && svcPort.Protocol != port.Protocol { | ||
log.Warnf("Service %v has two instances on same port %v but different protocols (%v, %v)", | ||
|
@@ -83,7 +84,9 @@ func convertWorkloadEntry(endpoint *api.CatalogService) *istio.WorkloadEntry { | |
if addr == "" { | ||
addr = endpoint.Address | ||
} | ||
port := convertPort(endpoint.ServicePort, endpoint.ServiceMeta[protocolTagName]) | ||
|
||
protoName := getProtoValFromServiceTagsOrMeta(endpoint.ServiceTags, endpoint.ServiceMeta[protocolTagName]) | ||
port := convertPort(endpoint.ServicePort, protoName) | ||
|
||
return &istio.WorkloadEntry{ | ||
Address: addr, | ||
|
@@ -135,3 +138,27 @@ func convertProtocol(name string) string { | |
} | ||
return string(p) | ||
} | ||
|
||
//get the protocol value:get from meta first, otherwise get from tags | ||
func getProtoValFromServiceTagsOrMeta(serviceTags []string, serviceMetaProtocol string) string { | ||
if len(serviceMetaProtocol) > 0 { | ||
log.Debugf("getProtoValFromServiceTagsOrMeta,serviceMetaProtocol:%v", serviceMetaProtocol) | ||
return serviceMetaProtocol | ||
} | ||
defaultProto := "http" | ||
if len(serviceTags) == 0 { | ||
return defaultProto | ||
} | ||
for _, v := range serviceTags { | ||
isExist := strings.Contains(v, "proto") | ||
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. 建议使用 protocol, proto 是 “原型” 的意思 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. ok |
||
if isExist { | ||
strs := strings.Split(v, "=") | ||
if len(strs) == 2 { | ||
return strs[1] | ||
} else { | ||
log.Warnf("service tags proto is invalid") | ||
} | ||
} | ||
} | ||
return defaultProto | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,10 @@ type consulMonitor struct { | |
ServiceChangeHandlers []ServiceChangeHandler | ||
} | ||
|
||
const blockQueryWaitTime time.Duration = 10 * time.Minute | ||
const ( | ||
blockQueryWaitTime time.Duration = 10 * time.Minute | ||
updateServiceRecordWaitTime time.Duration = 10 * time.Second | ||
) | ||
|
||
// NewConsulMonitor watches for changes in Consul services and CatalogServices | ||
func NewConsulMonitor(client *api.Client) Monitor { | ||
|
@@ -72,6 +75,7 @@ func (m *consulMonitor) watchConsul(stop <-chan struct{}) { | |
} else if consulWaitIndex != queryMeta.LastIndex { | ||
consulWaitIndex = queryMeta.LastIndex | ||
m.updateServiceRecord() | ||
time.Sleep(updateServiceRecordWaitTime) | ||
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. 这个应该是在 consul 端修复吧? 对于正常的服务变化来说,每次变化后等待 10 分钟再同步会不会延迟太大了? 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. 是的 |
||
} | ||
} | ||
} | ||
|
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.
重试是否应该保留?