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 location endpoint #2481

Merged
merged 3 commits into from
Jan 15, 2025
Merged

add location endpoint #2481

merged 3 commits into from
Jan 15, 2025

Conversation

Omarabdul3ziz
Copy link
Contributor

Description

  • write node location info on a file while registering
  • add location endpoint to get this file info

Related Issues

Checklist

  • Tests included
  • Build pass
  • Documentation
  • Code format and docstring

- add location endpoint to get this file info
@@ -231,3 +237,13 @@ func ensureTwin(ctx context.Context, substrateGateway *stubs.SubstrateGatewayStu

return twinID, nil
}

func writeLocationOnFile(loc geoip.Location, filepath string) error {
file, err := os.OpenFile(filepath, os.O_RDWR|os.O_CREATE, 0644)
Copy link
Member

Choose a reason for hiding this comment

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

is it possible for the file to already exists?
If possible, what is the default behavior? Is truncate or append?

)

func (g *ZosAPI) locationGet(ctx context.Context, payload []byte) (interface{}, error) {
if _, err := os.Stat(geoip.LocationFile); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

is it needed?

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.

This should be addressed differently, I don't see a problem calling that function from the api and returning its result to the user

var loc geoip.Location
err = json.NewDecoder(f).Decode(&loc)
return loc, err
return geoip.Fetch()
Copy link
Collaborator

Choose a reason for hiding this comment

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

at this point you can add caching if needed

Copy link
Member

Choose a reason for hiding this comment

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

I agree, the node location should be updated like once per day and then cached for full day before it's fetched again.

@Omarabdul3ziz Omarabdul3ziz marked this pull request as draft November 13, 2024 08:47
@Omarabdul3ziz
Copy link
Contributor Author

i will draft until we finish releasing today

@Omarabdul3ziz Omarabdul3ziz marked this pull request as ready for review December 8, 2024 10:22
muhamadazmy
muhamadazmy previously approved these changes Dec 8, 2024
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.

Thank @Omarabdul3ziz for implementing this. It looks good to me. It's yet a good idea to cache the location of the node to avoid un-necessary load on the location service as per @xmonader comment

@Omarabdul3ziz Omarabdul3ziz merged commit e6667ae into main Jan 15, 2025
24 checks passed
@Omarabdul3ziz Omarabdul3ziz deleted the main_addLocationEndpoint branch January 15, 2025 16:25
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.

5 participants