-
Notifications
You must be signed in to change notification settings - Fork 230
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
Rework remote settings server URL #6429
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6429 +/- ##
==========================================
- Coverage 21.78% 21.76% -0.02%
==========================================
Files 344 344
Lines 31028 31053 +25
==========================================
Hits 6759 6759
- Misses 24269 24294 +25 ☔ View full report in Codecov by Sentry. |
4837c02
to
966b7da
Compare
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'm sorry if it wasn't ultra clear in other messages, but our convention is to not put the trailing /
in the server url and build paths with {server-url}/buckets/...
(Note: I didn't put comments everywhere this has to be adjusted)
@@ -122,24 +122,29 @@ pub trait ApiClient { | |||
|
|||
/// Client for Remote settings API requests | |||
pub struct ViaductApiClient { | |||
/// Server base URL | |||
/// | |||
/// This is something like `https://[domain]/v1/`. It's what's normally called the `base_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.
Our convention is to not put the trailing /
/// Base URL for requests to a collections endpoint | ||
/// | ||
/// This is something like | ||
/// `https://[server-url]/v1/buckets/[bucket-name]/collections/[collection-name]/" | ||
/// `https://[server-url]/buckets/[bucket-name]/collections/[collection-name]/` |
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 is correct (only if no trailing slash in server-url
)
collection_url: Url, | ||
remote_state: RemoteState, | ||
} | ||
|
||
impl ViaductApiClient { | ||
fn new(server_url: Url, bucket_name: &str, collection_name: &str) -> Result<Self> { | ||
let collection_url = server_url.join(&format!( | ||
"v1/buckets/{bucket_name}/collections/{collection_name}/" | ||
"buckets/{bucket_name}/collections/{collection_name}/" |
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.
"buckets/{bucket_name}/collections/{collection_name}/" | |
"/buckets/{bucket_name}/collections/{collection_name}/" |
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 avoided this because it's going to break the join. Without the trailing slash, then join treats the last component as a file rather than a directory and removes it. However, there is the path_segments_mut()
method. Let me try that and see how it comes out.
a181293
to
2a80bc1
Compare
let mut server_url = base_url.clone(); | ||
// Push the empty string to add a trailing slash. This avoids a redirect when we hit | ||
// the server. | ||
Self::path_segments_mut(&mut server_url)?.push(""); |
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.
Using https://firefox.settings.services.mozilla.com/v1/
instead of https://firefox.settings.services.mozilla.com/v1
seems right to me. I always try to avoid hitting a redirect when I make an API call. But tell me if that's a bad idea.
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.
There should not be any redirect, we don't call the server_url
directly (without trailing slash)
Your |
2a80bc1
to
0cbe484
Compare
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 looks good, and approved to avoid blocking you longer.
Nevertheless, in order to avoid confusion between the different implementations, I would like to insist that we shouldn't put any trailing slash to the server URL.
I agree with you, it would be ugly to hit a redirect, but we don't because we consider /
as the root endpoint.
So I think that with your PR, if we just add a root
endpoint to your struct, we should be aligned with the other implementations 😊
Examples in kinto-http.py:
class Endpoints(object):
endpoints = {
"root": "{root}/",
"batch": "{root}/batch",
"buckets": "{root}/buckets",
"bucket": "{root}/buckets/{bucket}",
"history": "{root}/buckets/{bucket}/history",
"groups": "{root}/buckets/{bucket}/groups",
"group": "{root}/buckets/{bucket}/groups/{group}",
"collections": "{root}/buckets/{bucket}/collections",
"collection": "{root}/buckets/{bucket}/collections/{collection}",
"records": "{root}/buckets/{bucket}/collections/{collection}/records", # NOQA
"record": "{root}/buckets/{bucket}/collections/{collection}/records/{id}", # NOQA
}
or kinto.js
const ENDPOINTS = {
root: () => "/",
bucket: (bucket?: string) => "/buckets" + (bucket ? `/${bucket}` : ""),
collection: (bucket: string, coll?: string) =>
`${ENDPOINTS.bucket(bucket)}/collections` + (coll ? `/${coll}` : ""),
record: (bucket: string, coll: string, id?: string) =>
`${ENDPOINTS.collection(bucket, coll)}/records` + (id ? `/${id}` : ""),
// ...
// ...
};
let collection_url = self.collection_url.clone(); | ||
let server_info = self.make_request(collection_url)?.json::<ServerInfo>()?; | ||
let server_info = self | ||
.make_request(self.endpoints.server_url.clone())? |
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 would call it root_url
/// Top-level URL for Remote Settings server | ||
/// | ||
/// This has the form `https://[domain]/v1/`. It's where we get the attachment base url from. | ||
server_url: 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.
In other implementations, we call this the root URL and it has the form of {server_url}/
let mut server_url = base_url.clone(); | ||
// Push the empty string to add a trailing slash. This avoids a redirect when we hit | ||
// the server. | ||
Self::path_segments_mut(&mut server_url)?.push(""); |
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.
There should not be any redirect, we don't call the server_url
directly (without trailing slash)
0cbe484
to
781b59c
Compare
Let's update these to match the JS client: https://github.com/mozilla-extensions/remote-settings-devtools/blob/15245fdb8e4fb5875a7866c7328ded6671ab466c/extension/experiments/remotesettings/api.js#L8-L11 This is a breaking change to the public API, but this API is not exposed via UniFFI and it's only used in 1 place: https://github.com/mozilla/application-services/blob/50bf235b9a3a62a6b6749cd0bd7358d7b96a42e4/components/nimbus/src/stateful/client/mod.rs#L24-L35. AFAICT, the only affect this will have is that the error message will change slightly. Fixed an error when downloading attachments in the new client code. I think I broke it with my last commit. Also removed the `.unwrap()` calls. It shouldn't matter because there's no way for `.join()` to fail, but it feels silly calling `unwrap()` from a function that returns a result.
781b59c
to
f807f09
Compare
That makes sense. I updated the terminology to be |
Let's update these to match the JS client:
https://github.com/mozilla-extensions/remote-settings-devtools/blob/15245fdb8e4fb5875a7866c7328ded6671ab466c/extension/experiments/remotesettings/api.js#L8-L11
This is a breaking change to the public API, but this API is not exposed via UniFFI and it's only used in 1 place:
application-services/components/nimbus/src/stateful/client/mod.rs
Lines 24 to 35 in 50bf235
Also removed the
.unwrap()
calls. It shouldn't matter because there's no way for.join()
to fail, but it feels silly callingunwrap()
from a function that returns a result.Pull Request checklist
[ci full]
to the PR title.Branch builds: add
[firefox-android: branch-name]
to the PR title.