-
Notifications
You must be signed in to change notification settings - Fork 18
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
Pull groups configuration from content-service #26
Conversation
config.toml
Outdated
@@ -11,3 +11,4 @@ enable_cors = false | |||
[services] | |||
aggregator = "http://localhost:8080/api/v1/" | |||
content = "http://localhost:8082/api/v1/" | |||
groups_poll_time = 60 |
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.
Why do we need to poll?
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 want to update the group configuration periodically to cache it. If we don't poll, we can miss groups configuration changes on the content service
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.
LGTM in overall but - don't we need mutex to sync group writes?
@tisnik good point, I didn't think about it. Do you mean to avoid collisions between reading the configuration and updating it from the content service? |
@tisnik but we have only 1 writing goroutine, don't we? |
Codecov Report
@@ Coverage Diff @@
## master #26 +/- ##
==========================================
+ Coverage 20.31% 21.07% +0.75%
==========================================
Files 9 9
Lines 507 541 +34
==========================================
+ Hits 103 114 +11
- Misses 391 413 +22
- Partials 13 14 +1
Continue to review full report at Codecov.
|
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.
LGTM - just the clarification might be needed please
I don't really understand why we need to put the same data to the channel in a loop. How is it better than just using a pointer? |
server/server.go
Outdated
@@ -241,6 +245,28 @@ func (server HTTPServer) proxyTo(baseURL string) func(http.ResponseWriter, *http | |||
} | |||
} | |||
|
|||
// getGroups retrives the groups configuration from a channel to get the latest valid one and send the response back to the client | |||
func (server *HTTPServer) getGroups(writer http.ResponseWriter, request *http.Request) { | |||
select { |
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.
What's the purpose of this select
? It's reading only from one channel, isn't it?
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.
You are right, I don't remember why I put it, but it is not needed at all. TYVM!
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.
Fixed in the last commit
@Sergey1011010 the channel is used to pass the groups configuration from the "writer" goroutine ( |
@joselsegura, yes, but why do you need such a complicated mechanism when you can just replace an array at once in writing goroutine and you won't have any race conditions. |
After talking with @Sergey1011010, he convinced me that there is no possibility of having problems using a simple array mechanism, due to there will only be a goroutine writing the array, and given that the slice update operation is atomic, it cannot be possible to have a "readers/writer" problem here. So, what do you think to returning back to the first proposal instead of using a channel? |
it's up to you (don't know about the discussion), but the official rule is simple:
And also according to spec:
Re atomicity: it's just slightly related to concurrent R/W operations. |
Apparently we are exactly matching the rule statement: we have several goroutines and one (and only one of them) is writing the values. So, I will keep the current version until you find anything more to comment. P.S. Plase, resolve the requests for change if you are ok with the updates |
@tisnik but slice stores a pointer to an array and updating this pointer(setting new array to a slice) is atomic, isn't it? |
Indeed it might be on most architectures as max.capacity is equal to max |
Wow, this scaled quickly :-D Golang internals! Poor Python guy |
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 a lot @joselsegura, LGTM
Description
This PR includes pulling the groups configuration from the content service and serving that configuration as an smart proxy endpoint.
It also includes a mechanism to periodically update the group configuration.
Fixes #18
Type of change
Testing steps
Regular CI. Increased UT threshold from 0 to 23