-
Notifications
You must be signed in to change notification settings - Fork 44
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
Implement Ingress Service #515
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
This package provides interfaces for built-in services | ||
*/ | ||
syntax = "proto3"; | ||
|
||
package dev.restate; | ||
|
||
option java_multiple_files = true; | ||
option java_package = "dev.restate.generated"; | ||
option go_package = "restate.dev/sdk-go/pb"; | ||
|
||
service Ingress { | ||
// Invoke a service and don't wait for the response. | ||
// It is guaranteed that the service will be invoked after this method returns. | ||
rpc Invoke(InvokeRequest) returns (InvokeResponse); | ||
} | ||
|
||
message InvokeRequest { | ||
// Fully qualified name of the service, e.g. `counter.Counter` | ||
string service = 1; | ||
// Method name of the service to invoke, e.g. `Add` | ||
string method = 2; | ||
// Argument of the invocation. | ||
// When executing requests to the ingress using Protobuf, | ||
// this field must contain the serialized Protobuf matching the argument type of the target method. | ||
// When executing requests to the ingress using JSON, | ||
// this field must contain the JSON object representing the argument type of the target method. | ||
bytes argument = 3; | ||
} | ||
|
||
message InvokeResponse { | ||
// Generated unique invocation identifier. | ||
// It can be used to retrieve the status of the invocation and cancel it. | ||
string sid = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use once_cell::sync::Lazy; | ||
use prost_reflect::{DescriptorPool, MethodDescriptor}; | ||
use restate_service_metadata::MethodDescriptorRegistry; | ||
use std::collections::HashMap; | ||
use std::convert::AsRef; | ||
|
||
pub(crate) mod grpc { | ||
pub(crate) mod reflection { | ||
#![allow(warnings)] | ||
#![allow(clippy::all)] | ||
#![allow(unknown_lints)] | ||
include!(concat!(env!("OUT_DIR"), "/grpc.reflection.v1alpha.rs")); | ||
} | ||
} | ||
pub(crate) mod restate { | ||
pub(crate) mod services { | ||
#![allow(warnings)] | ||
#![allow(clippy::all)] | ||
#![allow(unknown_lints)] | ||
include!(concat!(env!("OUT_DIR"), "/dev.restate.rs")); | ||
} | ||
} | ||
|
||
pub(crate) static DEV_RESTATE_DESCRIPTOR_POOL: Lazy<DescriptorPool> = Lazy::new(|| { | ||
DescriptorPool::decode( | ||
include_bytes!(concat!(env!("OUT_DIR"), "/file_descriptor_set.bin")).as_ref(), | ||
) | ||
.expect("The built-in descriptor pool should be valid") | ||
}); | ||
|
||
// TODO this is a temporary solution until we have a schema registry where we can distinguish between ingress only services | ||
// see https://github.com/restatedev/restate/issues/43#issuecomment-1597174972 | ||
#[derive(Clone)] | ||
pub struct MethodDescriptorRegistryWithIngressService<MDR> { | ||
method_descriptor_registry: MDR, | ||
} | ||
|
||
impl<MDR> MethodDescriptorRegistryWithIngressService<MDR> { | ||
pub(crate) fn new(method_descriptor_registry: MDR) -> Self { | ||
Self { | ||
method_descriptor_registry, | ||
} | ||
} | ||
} | ||
|
||
impl<MDR: MethodDescriptorRegistry> MethodDescriptorRegistry | ||
for MethodDescriptorRegistryWithIngressService<MDR> | ||
{ | ||
fn resolve_method_descriptor( | ||
&self, | ||
svc_name: &str, | ||
method_name: &str, | ||
) -> Option<MethodDescriptor> { | ||
if svc_name.starts_with("dev.restate") { | ||
return DEV_RESTATE_DESCRIPTOR_POOL | ||
.get_service_by_name(svc_name) | ||
.and_then(|s| s.methods().find(|m| m.name() == method_name)); | ||
} | ||
self.method_descriptor_registry | ||
.resolve_method_descriptor(svc_name, method_name) | ||
} | ||
|
||
fn list_methods(&self, svc_name: &str) -> Option<HashMap<String, MethodDescriptor>> { | ||
if svc_name.starts_with("dev.restate") { | ||
return DEV_RESTATE_DESCRIPTOR_POOL | ||
.get_service_by_name(svc_name) | ||
.map(|s| s.methods().map(|m| (m.name().to_string(), m)).collect()); | ||
} | ||
self.method_descriptor_registry.list_methods(svc_name) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Where I stumbled upon a bit was where are we checking whether a protobuf invoked
dev.restate.Ingress/Invoke
call actually calls an existing service. When using connect, this happens in theread_json_invoke_request
method quite explicitly. For protobuf encodeddev.restate.Ingress/Invoke
requests it was not that obvious.It turns out that we are doing this check in the
invocation_factory.create
call where we try to extract the key. If the service is not registered, then it fails with anUnknownService
error.Due to the different checks, we do see different manifestations of the unknown service:
I think it is not a problem just that I tripped over the fact that I didn't find where the check for an existing method in the protobuf case is done.