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

add more geoip service urls #2015

Merged
merged 4 commits into from
Aug 9, 2023
Merged

add more geoip service urls #2015

merged 4 commits into from
Aug 9, 2023

Conversation

MarioBassem
Copy link
Contributor

Signed-off-by: mariobassem <mariobassem12@gmail.com>
return l, err
}
defer resp.Body.Close()
for i := 0; i < len(geoipURLs); i++ {
Copy link
Collaborator

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?

log.Err(err).Msgf("failed to make http call to geoip service %s. retrying...", geoipURLs[i])
continue
}
defer resp.Body.Close()
Copy link
Collaborator

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)

Copy link
Collaborator

@xmonader xmonader left a 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 Show resolved Hide resolved
pkg/geoip/geoip.go Outdated Show resolved Hide resolved
pkg/geoip/geoip.go Outdated Show resolved Hide resolved
xmonader
xmonader previously approved these changes Jul 31, 2023
@@ -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/"}
Copy link
Member

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{...}
)

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)
Copy link
Member

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>
Copy link
Member

@muhamadazmy muhamadazmy left a 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

@muhamadazmy muhamadazmy merged commit 5aabc89 into main Aug 9, 2023
@muhamadazmy muhamadazmy deleted the main_use_geoip_list branch August 9, 2023 11:53
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.

3 participants