-
Notifications
You must be signed in to change notification settings - Fork 438
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
Implement consul datasource #116
Conversation
please pause the merge, more detail testing is in progress. Is there any way to switch to draft PR? |
Can not. |
By the way, The CI failed, could you please fix it? Thanks. |
16e01c2
to
d00e82f
Compare
Could you please rebase the code? |
f19f896
to
842529e
Compare
842529e
to
90a8d99
Compare
Codecov Report
@@ Coverage Diff @@
## master #116 +/- ##
==========================================
+ Coverage 44.62% 44.66% +0.04%
==========================================
Files 76 78 +2
Lines 4112 4218 +106
==========================================
+ Hits 1835 1884 +49
- Misses 2077 2126 +49
- Partials 200 208 +8
Continue to review full report at Codecov.
|
} | ||
|
||
func (c *consulDataSource) Close() error { | ||
if c.cancel != nil { |
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.
I run the test:
func Test_consulDatasource_CustomizeClient(t *testing.T) {
client, err := api.NewClient(&api.Config{
Address: "127.0.0.1:8500",
})
if err != nil {
// todo something
}
ds, err := NewDatasource("property_key",
// customize consul client
WithConsulClient(client),
// disable dynamic datasource watch
WithDisableWatch(false),
// preset property handlers
WithPropertyHandlers(),
// reset queryOptions, defaultQueryOptions as default
WithQueryOptions(&api.QueryOptions{}),
)
if err != nil {
// todo something
}
if err := ds.Initialize(); err != nil {
// todo something
}
time.Sleep(time.Second * 10)
ds.Close()
time.Sleep(time.Second * 1000)
}
But the cancel don't work as expected.
Is there anything wrong in my test?
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.
Maybe the lastest code line time.Sleep(time.Second*1000)
causes you to think that there is no cancel.
I'll improve the unit test case later.
|
||
type consulDataSource struct { | ||
datasource.Base | ||
*options |
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.
It seems this field is useless for datasource,
Deleting this field makes more sense.
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.
We may also add some logs (when the data-source has been initialized) so that users could identify which key is being watched.
// customize consul client | ||
WithConsulClient(client), | ||
// disable dynamic datasource watch | ||
WithDisableWatch(true), |
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.
Maybe setting false is better here?
@louyuting We may also need to add out-of-box demo for various data-sources in |
I think so too. We might need to add those demo into |
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.
Thanks for nice work
I will polish related code later
Describe what this PR does / why we need it
implement consul datasource
Does this pull request fix one issue?
Describe how you did it
adapter consul client api;
read the configuration immediately after connecting to consul server,
then start polling.
Describe how to verify it
Special notes for reviews