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

Ftr: Add config loader hooks for 3.0 #1370

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,9 @@ const (
//GenericSerializationProtobuf = "protobuf-json"
GenericSerializationGson = "gson"
)

// Loader Hook

const (
HookParams = "HookParams"
)
49 changes: 48 additions & 1 deletion config/config_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ var (
confBaseFile string
uniformVirtualServiceConfigPath string
uniformDestRuleConfigPath string

loaderHooks map[string][]LoaderHook
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not initializes loaderHooks here? If not initializes, you should handle the case that loaderHooks is empty in AddLoaderHooks and RemoveLoaderHooks method.

)

// loaded consumer & provider config from xxx.yml, and log config from xxx.xml
Expand Down Expand Up @@ -190,6 +192,17 @@ func loadConsumerConfig() {
for {
checkok := true
for _, refconfig := range consumerConfig.References {
consumerConnectHookInfo := &ConsumerConnectInfo{
id: refconfig.id,
protocol: refconfig.Protocol,
registry: refconfig.Registry,
interfaceName: refconfig.InterfaceName,
group: refconfig.Group,
version: refconfig.Version,
}
emitHook(&beforeConsumerConnectHook{
HookParams: consumerConnectHookInfo,
})
if (refconfig.Check != nil && *refconfig.Check) ||
(refconfig.Check == nil && consumerConfig.Check != nil && *consumerConfig.Check) ||
(refconfig.Check == nil && consumerConfig.Check == nil) { // default to true
Expand All @@ -200,20 +213,31 @@ func loadConsumerConfig() {
if count > maxWait {
errMsg := fmt.Sprintf("Failed to check the status of the service %v. No provider available for the service to the consumer use dubbo version %v", refconfig.InterfaceName, constant.Version)
logger.Error(errMsg)
emitHook(&consumerConnectFailHook{
HookParams: &ConsumerConnectFailInfo{
ConsumerConnectInfo: *consumerConnectHookInfo,
message: errMsg,
},
})
panic(errMsg)
}
time.Sleep(time.Second * 1)
break
}
if refconfig.invoker == nil {
logger.Warnf("The interface %s invoker not exist, may you should check your interface config.", refconfig.InterfaceName)
continue
}
}
emitHook(&consumerConnectSuccessHook{
HookParams: consumerConnectHookInfo,
})
}
if checkok {
break
}
}
emitHook(&allConsumersConnectCompleteHook{})
}

func loadProviderConfig() {
Expand Down Expand Up @@ -268,11 +292,34 @@ func loadProviderConfig() {
svs.id = key
svs.Implement(rpcService)
svs.Protocols = providerConfig.Protocols
providerConnectHookInfo := &ProviderConnectInfo{
id: svs.id,
protocol: svs.Protocol,
registry: svs.Registry,
interfaceName: svs.InterfaceName,
group: svs.Group,
version: svs.Version,
}
emitHook(&beforeProviderConnectHook{
HookParams: providerConnectHookInfo,
})
if err := svs.Export(); err != nil {
panic(fmt.Sprintf("service %s export failed! err: %#v", key, err))
errMsg := fmt.Sprintf("service %s export failed! err: %#v", key, err)
emitHook(&providerConnectFailHook{
HookParams: &ProviderConnectFailInfo{
ProviderConnectInfo: *providerConnectHookInfo,
message: errMsg,
},
})
panic(errMsg)
} else {
emitHook(&providerConnectSuccessHook{
HookParams: providerConnectHookInfo,
})
}
}
registerServiceInstance()
emitHook(&allProvidersConnectCompleteHook{})
}

// registerServiceInstance register service instance
Expand Down
Loading