mozilla / self-repair-server

This project is now EOL, replaced by Normandy Recipe Server.
6 stars 11 forks source link

Switch geo detection from geo.moz.org to MLS #239

Closed hannosch closed 8 years ago

hannosch commented 8 years ago

@gregglind this also references #181. We talked about various long term options to expose country data from a central place inside the browser. But for the short term we want to shut down geo.mozilla.org and switch everyone to MLS.

The MLS API is documented at https://mozilla.github.io/ichnaea/api/region.html, though the simplest way is to do a GET request, like:

curl https://location.services.mozilla.com/v1/country?key=fcce8909-53a6-4d26-83da-e822cdf4ac13

and get a status code 200 JSON response, with a body of:

{ "country_code": "US", "country_name": "United States", "fallback": "ipf" }

In failure cases 4xx and 5xx status codes can be returned, not all of them necessarily containing JSON in the body.

The API key here is only used to identify the consuming service/website, so we can collect metrics about their individual usage and attribute back problems to the right caller. The key in the curl example is meant to be used by self-repair. It can be put into a public repo and be shared across dev/stage/prod sites.

For another code example of the snippets service switching over see:

https://github.com/mozilla/snippets-service/pull/143/files#diff-3adb3669370af06c37adc916ba7b7c3cL398

gregglind commented 8 years ago

NEVER MIND, FIXED.

I am having some trouble:

var GEO_URL = 'https://location.services.mozilla.com/v1/country?key=fcce8909-53a6-4d26-83da-e822cdf4ac13';
fetch(GEO_URL).then((r)=>console.log(r.json))

The url seems to work fine. Maybe I don't understand fetch :)

FIX: r.json() is a promise.

gregglind commented 8 years ago

@hannosch, take a look over this. If you claim that this is ready for projection, I am happy to switch it over immediately.

gregglind commented 8 years ago

@hannosch

  1. (I am a little worried that 10m queries per day is Not Quite Enough. We cache for 30 days. Existing users should have a cached location. I hear that you will see if we are over using, and you will tell us if that happens)
  2. This is ready to switch over, if you are.
  3. This will be deprecated in Q2 when we switch to a central server.

Thanks for doing this!

GL

hannosch commented 8 years ago

@gregglind

  1. The country API is not actually rate-limited at this point. We have metrics to see how much traffic we are getting from each API key, but don't stop serving responses. The actual geolocation API (based on cell/wifi data) has rate limits, maybe someone confused the two.
  2. Nothing is blocking this from our end, feel free to switch.

As I said on IRC, we won't have a problem with taking the extra traffic. We took on snippets earlier this year which also all Firefox users and caches in local storage for 30 days. I'd expect the traffic from this to match snippets.

Hanno