-
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
add more geoip service urls #2015
Conversation
Signed-off-by: mariobassem <mariobassem12@gmail.com>
pkg/geoip/geoip.go
Outdated
return l, err | ||
} | ||
defer resp.Body.Close() | ||
for i := 0; i < len(geoipURLs); i++ { |
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 not a for range?
pkg/geoip/geoip.go
Outdated
log.Err(err).Msgf("failed to make http call to geoip service %s. retrying...", geoipURLs[i]) | ||
continue | ||
} | ||
defer resp.Body.Close() |
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.
this won't be properly handled (you're calling the defer within a for-loop)
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 was expecting that we would fire up multiple requests in the background against the 3 geoip services and as soon one of the returns a healthy result we can use it, but @muhamadazmy can decide how to approach it properly
Signed-off-by: mariobassem <mariobassem12@gmail.com>
pkg/geoip/geoip.go
Outdated
@@ -18,6 +20,22 @@ type Location struct { | |||
|
|||
// Fetch retrieves the location of the system calling this function | |||
func Fetch() (Location, error) { | |||
geoipURLs := []string{"https://geoip.grid.tf/", "https://02.geoip.grid.tf/", "https://03.geoip.grid.tf/"} |
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.
can this be defined in the global scope (outside the function body) not on the stack. it's more of a constant than a variable. like
var (
geoipURLs = []string{...}
)
pkg/geoip/geoip.go
Outdated
for _, url := range geoipURLs { | ||
l, err := getLocation(url) | ||
if err != nil { | ||
log.Err(err).Msgf("failed to fetch location from geoip service %s. retrying...", url) |
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.
the log here is kinda misleading, we are not retrying
instead we are trying a completely different url. Instead the error should show which url is not working + the cause. Also please use the structured logs correctly. Use the available, Str, Int, etc.. not formatting as much as possiblel
log.Err(err).Str("url", url).Msg("failed to fetch location from geoip service")
Is more correct form than the one in code
Signed-off-by: mariobassem <mariobassem12@gmail.com>
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.
Please merge only after testing
Related issues: