Skip to content

Commit

Permalink
Use GET for service discovery (#1613)
Browse files Browse the repository at this point in the history
  • Loading branch information
slinkydeveloper authored and tillrohrmann committed Jun 11, 2024
1 parent 3f48115 commit bd9fa51
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use restate_invoker_api::{EagerState, EntryEnricher, JournalMetadata};
use restate_schema_api::deployment::{
Deployment, DeploymentMetadata, DeploymentType, ProtocolType,
};
use restate_service_client::{Endpoint, Parts, Request, ServiceClientError};
use restate_service_client::{Endpoint, Method, Parts, Request, ServiceClientError};
use restate_service_protocol::message::{
Decoder, Encoder, MessageHeader, MessageType, ProtocolMessage,
};
Expand Down Expand Up @@ -234,7 +234,7 @@ where

(
http_stream_tx,
Request::new(Parts::new(address, path, headers), req_body),
Request::new(Parts::new(Method::POST, address, path, headers), req_body),
)
}

Expand Down
3 changes: 1 addition & 2 deletions crates/service-client/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,11 @@ impl HttpClient {
&self,
uri: Uri,
version: Version,
method: Method,
body: Body,
path: PathAndQuery,
headers: HeaderMap<HeaderValue>,
) -> impl Future<Output = Result<Response<Body>, HttpError>> + Send + 'static {
let method = Method::POST;

let request = match Self::build_request(uri, version, body, method, path, headers) {
Ok(request) => request,
Err(err) => return future::ready(Err(err.into())).right_future(),
Expand Down
3 changes: 2 additions & 1 deletion crates/service-client/src/lambda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ impl LambdaClient {
pub fn invoke(
&self,
arn: LambdaARN,
method: Method,
assume_role_arn: Option<ByteString>,
body: Body,
path: PathAndQuery,
Expand All @@ -189,7 +190,7 @@ impl LambdaClient {

let payload = ApiGatewayProxyRequest {
path: Some(path.path().to_string()),
http_method: Method::POST,
http_method: method,
headers,
body: body?,
is_base64_encoded: true,
Expand Down
48 changes: 41 additions & 7 deletions crates/service-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,25 @@ impl ServiceClient {

match parts.address {
Endpoint::Http(uri, version) => {
let fut = self
.http
.request(uri, version, body, parts.path, parts.headers);
let fut = self.http.request(
uri,
version,
parts.method.into(),
body,
parts.path,
parts.headers,
);
async move { Ok(fut.await?) }.left_future()
}
Endpoint::Lambda(arn, assume_role_arn) => {
let fut = self
.lambda
.invoke(arn, assume_role_arn, body, parts.path, parts.headers);
let fut = self.lambda.invoke(
arn,
parts.method.into(),
assume_role_arn,
body,
parts.path,
parts.headers,
);
async move { Ok(fut.await?) }.right_future()
}
}
Expand Down Expand Up @@ -175,8 +185,26 @@ impl<B> Request<B> {
}
}

#[derive(Clone, Copy, Debug)]
pub enum Method {
POST,
GET,
}

impl From<Method> for hyper::http::Method {
fn from(value: Method) -> Self {
match value {
Method::POST => hyper::http::Method::POST,
Method::GET => hyper::http::Method::GET,
}
}
}

#[derive(Clone, Debug)]
pub struct Parts {
/// The method to use
method: Method,

/// The request's target address
address: Endpoint,

Expand All @@ -188,8 +216,14 @@ pub struct Parts {
}

impl Parts {
pub fn new(address: Endpoint, path: PathAndQuery, headers: HeaderMap<HeaderValue>) -> Self {
pub fn new(
method: Method,
address: Endpoint,
path: PathAndQuery,
headers: HeaderMap<HeaderValue>,
) -> Self {
Self {
method,
address,
path,
headers,
Expand Down
7 changes: 5 additions & 2 deletions crates/service-protocol/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use itertools::Itertools;
use once_cell::sync::Lazy;
use restate_errors::{META0003, META0012, META0013};
use restate_schema_api::deployment::ProtocolType;
use restate_service_client::{Endpoint, Parts, Request, ServiceClient, ServiceClientError};
use restate_service_client::{Endpoint, Method, Parts, Request, ServiceClient, ServiceClientError};
use restate_types::endpoint_manifest;
use restate_types::retries::{RetryIter, RetryPolicy};
use restate_types::service_discovery::{
Expand Down Expand Up @@ -96,7 +96,10 @@ impl DiscoverEndpoint {
)]);
headers.extend(self.1.clone());
let path = PathAndQuery::from_static(DISCOVER_PATH);
Request::new(Parts::new(self.0.clone(), path, headers), Body::empty())
Request::new(
Parts::new(Method::GET, self.0.clone(), path, headers),
Body::empty(),
)
}
}

Expand Down

0 comments on commit bd9fa51

Please sign in to comment.