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

Conversation

ChangedenCZD
Copy link
Contributor

What this PR does:
Hook Type:

  • BeforeShutdownHook
  • BeforeConsumerConnectHook
  • ConsumerConnectSuccessHook
  • ConsumerConnectFailHook
  • AllConsumerConnectCompleteHook
  • BeforeProviderConnectHook
  • ProviderConnectSuccessHook
  • ProviderConnectFailHook
  • AllProviderConnectCompleteHook

Create Instance:

  • NewBeforeShutdownHook(func() {})
  • NewBeforeConsumerConnectHook(func(info *ConsumerConnectInfo) {})
  • NewConsumerConnectSuccessHook(func(info *ConsumerConnectInfo) {})
  • NewConsumerConnectFailHook(func(info *ConsumerConnectFailInfo) {})
  • NewAllConsumersConnectCompleteHook(func() {})
  • NewBeforeProviderConnectHook(func(info *ProviderConnectInfo) {})
  • NewProviderConnectSuccessHook(func(info *ProviderConnectInfo) {})
  • NewProviderConnectFailHook(func(info *ProviderConnectFailInfo) {})
  • NewAllProvidersConnectCompleteHook(func() {})

Add/Remove Hooks:

  • config.AddLoaderHooks(...hooks)
  • config.RemoveLoaderHooks(...hooks)

Unit Test:

  • config_loader_test.TestLoadWithLoaderHooks
    Which issue(s) this PR fixes:

Fixes #1364

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

None

Changeden added 3 commits August 9, 2021 20:12
- BeforeShutdownHook
- BeforeConsumerConnectHook
- ConsumerConnectSuccessHook
- ConsumerConnectFailHook
- AllConsumerConnectCompleteHook
- BeforeProviderConnectHook
- ProviderConnectSuccessHook
- ProviderConnectFailHook
- AllProviderConnectCompleteHook

UT:
- config_loader_test.TestLoadWithLoaderHooks
@codecov-commenter
Copy link

codecov-commenter commented Aug 9, 2021

Codecov Report

Merging #1370 (fec318c) into 3.0 (c5802c5) will increase coverage by 0.23%.
The diff coverage is 75.55%.

Impacted file tree graph

@@            Coverage Diff             @@
##              3.0    #1370      +/-   ##
==========================================
+ Coverage   54.95%   55.19%   +0.23%     
==========================================
  Files         272      273       +1     
  Lines       14755    14934     +179     
==========================================
+ Hits         8109     8243     +134     
- Misses       5769     5812      +43     
- Partials      877      879       +2     
Impacted Files Coverage Δ
config/graceful_shutdown.go 72.63% <0.00%> (-1.57%) ⬇️
config/config_loader.go 52.52% <65.90%> (+2.52%) ⬆️
config/config_loader_hook.go 79.85% <79.85%> (ø)
remoting/etcdv3/listener.go 46.90% <0.00%> (-5.31%) ⬇️
remoting/kubernetes/listener.go 52.83% <0.00%> (ø)
remoting/kubernetes/watch.go 80.55% <0.00%> (+1.85%) ⬆️
remoting/kubernetes/client.go 78.04% <0.00%> (+2.43%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c5802c5...fec318c. Read the comment docs.

@LaurenceLiZhixin
Copy link
Contributor

  1. Could you pls shortly describe how your hooks work?
  2. Pls change base branch from 3.0 to 1.5, as our 3.0 config is in refactor progress and will add this feature later. @ChangedenCZD

@ChangedenCZD ChangedenCZD changed the title Ftr: Add config loader hooks Ftr: Add config loader hooks for 3.0 Aug 10, 2021
@ChangedenCZD
Copy link
Contributor Author

ChangedenCZD commented Aug 10, 2021

  1. Could you pls shortly describe how your hooks work?
  2. Pls change base branch from 3.0 to 1.5, as our 3.0 config is in refactor progress and will add this feature later. @ChangedenCZD

@LaurenceLiZhixin #1372

hooks = []LoaderHook{}
}
loaderHooks[hookType] = append(hooks, hook)
}
Copy link
Member

Choose a reason for hiding this comment

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

It seems that hooks is a useless variable in this case.

if _, ok := loaderHooks[hookType]; !ok {
   loaderHooks[hookType] = make([]LoaderHook)
}
loaderHooks[hookType] = append(loaderHooks[hookType], hook)

@@ -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.

} else {
loaderHooks[hookType] = newHooks
}
break
Copy link
Member

@justxuewei justxuewei Aug 20, 2021

Choose a reason for hiding this comment

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

if len(loaderHooks[hookType]) == 1 {
  delete(loaderHooks, hookType)
} else {
  loaderHooks[hookType] = append(loaderHooks[hookType][:index], loaderHooks[hookType][index+1:]...)
}

)

const (
hookParams = constant.HookParams
Copy link
Member

Choose a reason for hiding this comment

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

use constant.HookParams directly please

@ChangedenCZD
Copy link
Contributor Author

暂时先关闭,后期改进

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants