Skip to content

Commit

Permalink
feat: Add BYOB UDF interface proto spec generator
Browse files Browse the repository at this point in the history
Bug: b/357877119
Change-Id: Ic6a748cfd7c3f88dd40905f793fbe73193c0964e
GitOrigin-RevId: 7a25b57a45ea243caafe7f2af75e653a7473991f
  • Loading branch information
Privacy Sandbox Team authored and copybara-github committed Oct 4, 2024
1 parent 2eb48c8 commit 8e66824
Show file tree
Hide file tree
Showing 49 changed files with 446 additions and 273 deletions.
2 changes: 1 addition & 1 deletion docs/roma/host_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ for an example of a service defined with an RPC, `NativeMethod`. Notice that `Te
`cpp_host_process_callback_includes` contains
[src/roma/native_function_grpc_server/proto/test_service_native_functions.h](/src/roma/native_function_grpc_server/proto/test_service_native_functions.h),
and test_service_native_functions.h has the fully qualified name to the C++ hook function that
should be invoked for NativeMethod in JS, `::privacysandbox::test_host_server::HandleNativeMethod`,
should be invoked for NativeMethod in JS, `::privacy_sandbox::test_host_server::HandleNativeMethod`,
which is found in NativeMethod's `cpp_host_process_callback` property. The corresponding BUILD file,
found [here](/src/roma/native_function_grpc_server/proto/BUILD) gives an example of how to use the
new build rules to build the Host Api for your proto.
Expand Down
5 changes: 3 additions & 2 deletions src/roma/benchmark/host_api_grpc_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ void SetupDeclarativeApiGrpcServer(const benchmark::State& state) {
config.enable_native_function_grpc_server = true;
config.RegisterRpcHandler(
"TestHostServer.NativeMethod",
privacysandbox::test_host_server::NativeMethodHandler<DefaultMetadata>());
privacy_sandbox::test_host_server::NativeMethodHandler<
DefaultMetadata>());
DoSetup(std::move(config));
}

Expand All @@ -83,7 +84,7 @@ void SetupDeclarativeApiNativeFunctionHandler(const benchmark::State& state) {
std::make_unique<FunctionBindingObjectV2<>>(FunctionBindingObjectV2<>{
.function_name = "TestHostServer.NativeMethod",
.function =
privacysandbox::test_host_server::NativeMethodFunctionBinding<
privacy_sandbox::test_host_server::NativeMethodFunctionBinding<
DefaultMetadata>,
}));
DoSetup(std::move(config));
Expand Down
4 changes: 2 additions & 2 deletions src/roma/benchmark/serde/benchmark_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

syntax = "proto3";

package privacy_sandbox.server_common;
package privacy_sandbox.benchmark;

import "apis/privacysandbox/apis/roma/app_api/v1/options.proto";

Expand All @@ -26,7 +26,7 @@ service BenchmarkService {
name: 'Benchmark',
code_id: "app_api_roma_app_benchmark_v1",
description: 'Benchmark',
cpp_namespace: 'privacysandbox::benchmark',
cpp_namespace: 'privacy_sandbox::benchmark',
roma_app_name: 'BenchmarkServer',
};

Expand Down
2 changes: 1 addition & 1 deletion src/roma/benchmark/serde/deserialize_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

namespace google::scp::roma::benchmark::proto {

using privacy_sandbox::server_common::BenchmarkRequest;
using privacy_sandbox::benchmark::BenchmarkRequest;

void DeserializeProtobufBenchmark(::benchmark::State& state,
std::string_view path) {
Expand Down
2 changes: 1 addition & 1 deletion src/roma/benchmark/serde/json_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int main(int argc, char* argv[]) {
std::string jsonStr((std::istreambuf_iterator<char>(inputFile)),
std::istreambuf_iterator<char>());

privacy_sandbox::server_common::BenchmarkRequest request;
privacy_sandbox::benchmark::BenchmarkRequest request;
if (!google::protobuf::util::JsonStringToMessage(jsonStr, &request).ok()) {
std::cerr << "Failed to parse to protobuf.\n";
return -1;
Expand Down
4 changes: 2 additions & 2 deletions src/roma/benchmark/serde/serde_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ namespace google::scp::roma::benchmark::proto {
using google::scp::roma::InvocationStrRequest;
using google::scp::roma::ResponseObject;
using google::scp::roma::sandbox::js_engine::v8_js_engine::V8JsEngine;
using privacy_sandbox::server_common::BenchmarkRequest;
using privacysandbox::benchmark::V8BenchmarkService;
using privacy_sandbox::benchmark::BenchmarkRequest;
using privacy_sandbox::benchmark::V8BenchmarkService;

constexpr auto kTimeout = absl::Seconds(10);
constexpr std::string_view kCodeVersion = "v1";
Expand Down
2 changes: 1 addition & 1 deletion src/roma/benchmark/serde/serialize_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

namespace google::scp::roma::benchmark::proto {

using privacy_sandbox::server_common::BenchmarkRequest;
using privacy_sandbox::benchmark::BenchmarkRequest;

void SerializeProtobufBenchmark(::benchmark::State& state,
std::string_view path) {
Expand Down
4 changes: 2 additions & 2 deletions src/roma/byob/benchmark/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ cc_binary(
name = "roma_byob_benchmark",
srcs = ["roma_byob_benchmark.cc"],
deps = [
"//src/roma/byob/udf:sample_byob_sdk_cc_proto",
"//src/roma/byob/udf:sample_byob_sdk_roma_cc_lib",
"//src/roma/byob/udf:sample_callback_cc_proto",
"//src/roma/byob/udf:sample_cc_proto",
"//src/roma/byob/udf:sample_roma_api",
"//src/roma/byob/utility:utils",
"@com_github_grpc_grpc//:grpc++",
"@com_google_absl//absl/log",
Expand Down
56 changes: 28 additions & 28 deletions src/roma/byob/benchmark/roma_byob_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,37 @@
#include "absl/strings/str_join.h"
#include "absl/synchronization/notification.h"
#include "absl/time/time.h"
#include "src/roma/byob/udf/sample.pb.h"
#include "src/roma/byob/udf/sample_callback.pb.h"
#include "src/roma/byob/udf/sample_roma_byob_app_service.h"
#include "src/roma/byob/udf/sample_udf_interface.pb.h"
#include "src/roma/byob/utility/utils.h"
#include "src/roma/config/function_binding_object_v2.h"

namespace {
using ::google::scp::roma::FunctionBindingObjectV2;
using ::privacy_sandbox::sample_server::roma_app_api::ByobSampleService;
using ::privacy_sandbox::sample_server::roma_app_api::SampleService;
using ::privacy_sandbox::roma_byob::example::ByobSampleService;
using ::privacy_sandbox::roma_byob::example::FUNCTION_CALLBACK;
using ::privacy_sandbox::roma_byob::example::FUNCTION_HELLO_WORLD;
using ::privacy_sandbox::roma_byob::example::FUNCTION_PRIME_SIEVE;
using ::privacy_sandbox::roma_byob::example::FUNCTION_TEN_CALLBACK_INVOCATIONS;
// using ::privacy_sandbox::roma_byob::example::ReadCallbackPayloadRequest;
// using ::privacy_sandbox::roma_byob::example::ReadCallbackPayloadResponse;
using ::privacy_sandbox::roma_byob::example::FunctionType;
using ::privacy_sandbox::roma_byob::example::RunPrimeSieveRequest;
using ::privacy_sandbox::roma_byob::example::RunPrimeSieveResponse;
using ::privacy_sandbox::roma_byob::example::SampleRequest;
using ::privacy_sandbox::roma_byob::example::SampleResponse;
using ::privacy_sandbox::roma_byob::example::SampleService;
using ::privacy_sandbox::roma_byob::example::SortListRequest;
using ::privacy_sandbox::roma_byob::example::SortListResponse;
using ::privacy_sandbox::roma_byob::example::WriteCallbackPayloadRequest;
using ::privacy_sandbox::roma_byob::example::WriteCallbackPayloadResponse;
using ::privacy_sandbox::server_common::byob::CallbackReadRequest;
using ::privacy_sandbox::server_common::byob::CallbackReadResponse;
using ::privacy_sandbox::server_common::byob::CallbackWriteRequest;
using ::privacy_sandbox::server_common::byob::CallbackWriteResponse;
using ::privacy_sandbox::server_common::byob::FUNCTION_CALLBACK;
using ::privacy_sandbox::server_common::byob::FUNCTION_HELLO_WORLD;
using ::privacy_sandbox::server_common::byob::FUNCTION_PRIME_SIEVE;
using ::privacy_sandbox::server_common::byob::FUNCTION_TEN_CALLBACK_INVOCATIONS;
using ::privacy_sandbox::server_common::byob::FunctionType;
using ::privacy_sandbox::server_common::byob::HasClonePermissionsByobWorker;
using ::privacy_sandbox::server_common::byob::Mode;
using ::privacy_sandbox::server_common::byob::ReadCallbackPayloadRequest;
using ::privacy_sandbox::server_common::byob::ReadCallbackPayloadResponse;
using ::privacy_sandbox::server_common::byob::RunPrimeSieveRequest;
using ::privacy_sandbox::server_common::byob::RunPrimeSieveResponse;
using ::privacy_sandbox::server_common::byob::SampleRequest;
using ::privacy_sandbox::server_common::byob::SampleResponse;
using ::privacy_sandbox::server_common::byob::SortListRequest;
using ::privacy_sandbox::server_common::byob::SortListResponse;
using ::privacy_sandbox::server_common::byob::WriteCallbackPayloadRequest;
using ::privacy_sandbox::server_common::byob::WriteCallbackPayloadResponse;

const std::filesystem::path kUdfPath = "/udf";
const std::filesystem::path kGoLangBinaryFilename = "sample_go_udf";
Expand Down Expand Up @@ -89,7 +89,7 @@ enum class Language {

SampleResponse SendRequestAndGetResponse(
ByobSampleService<>& roma_service,
::privacy_sandbox::server_common::byob::FunctionType func_type,
::privacy_sandbox::roma_byob::example::FunctionType func_type,
std::string_view code_token) {
// Data we are sending to the server.
SampleRequest bin_request;
Expand Down Expand Up @@ -408,7 +408,7 @@ void BM_ExecuteBinaryRequestPayload(benchmark::State& state) {
const auto rpc = [&roma_service](const auto& request,
std::string_view code_token) {
absl::StatusOr<std::unique_ptr<
::privacy_sandbox::server_common::byob::ReadPayloadResponse>>
::privacy_sandbox::roma_byob::example::ReadPayloadResponse>>
response;
absl::Notification notif;
CHECK_OK(roma_service.ReadPayload(notif, request, response,
Expand All @@ -417,7 +417,7 @@ void BM_ExecuteBinaryRequestPayload(benchmark::State& state) {
return response;
};

::privacy_sandbox::server_common::byob::ReadPayloadRequest request;
::privacy_sandbox::roma_byob::example::ReadPayloadRequest request;
std::string payload(elem_size, char(10));
auto payloads = request.mutable_payloads();
payloads->Reserve(elem_count);
Expand Down Expand Up @@ -454,7 +454,7 @@ void BM_ExecuteBinaryResponsePayload(benchmark::State& state) {
const auto rpc = [&roma_service](const auto& request,
std::string_view code_token) {
absl::StatusOr<std::unique_ptr<
::privacy_sandbox::server_common::byob::GeneratePayloadResponse>>
::privacy_sandbox::roma_byob::example::GeneratePayloadResponse>>
response;
absl::Notification notif;
CHECK_OK(roma_service.GeneratePayload(notif, request, response,
Expand All @@ -463,7 +463,7 @@ void BM_ExecuteBinaryResponsePayload(benchmark::State& state) {
return response;
};

::privacy_sandbox::server_common::byob::GeneratePayloadRequest request;
::privacy_sandbox::roma_byob::example::GeneratePayloadRequest request;
request.set_element_size(elem_size);
request.set_element_count(elem_count);
const int64_t req_payload_size = elem_size * elem_count;
Expand Down Expand Up @@ -510,7 +510,7 @@ void BM_ExecuteBinaryCallbackRequestPayload(benchmark::State& state) {
const auto rpc = [&roma_service](std::string_view code_token,
const auto& request) {
absl::StatusOr<std::unique_ptr<
::privacy_sandbox::server_common::byob::ReadCallbackPayloadResponse>>
::privacy_sandbox::roma_byob::example::ReadCallbackPayloadResponse>>
response;
absl::Notification notif;
CHECK_OK(roma_service.ReadCallbackPayload(notif, request, response,
Expand All @@ -519,7 +519,7 @@ void BM_ExecuteBinaryCallbackRequestPayload(benchmark::State& state) {
return response;
};

::privacy_sandbox::server_common::byob::ReadCallbackPayloadRequest request;
::privacy_sandbox::roma_byob::example::ReadCallbackPayloadRequest request;
request.set_element_size(elem_size);
request.set_element_count(elem_count);
const int64_t payload_size = elem_size * elem_count;
Expand Down Expand Up @@ -562,7 +562,7 @@ void BM_ExecuteBinaryCallbackResponsePayload(benchmark::State& state) {
const auto rpc = [&roma_service](std::string_view code_token,
const auto& request) {
absl::StatusOr<std::unique_ptr<
::privacy_sandbox::server_common::byob::WriteCallbackPayloadResponse>>
::privacy_sandbox::roma_byob::example::WriteCallbackPayloadResponse>>
response;
absl::Notification notif;
CHECK_OK(roma_service.WriteCallbackPayload(notif, request, response,
Expand All @@ -571,7 +571,7 @@ void BM_ExecuteBinaryCallbackResponsePayload(benchmark::State& state) {
return response;
};

::privacy_sandbox::server_common::byob::WriteCallbackPayloadRequest request;
::privacy_sandbox::roma_byob::example::WriteCallbackPayloadRequest request;
request.set_element_size(elem_size);
request.set_element_count(elem_count);
const int64_t payload_size = elem_size * elem_count;
Expand Down Expand Up @@ -615,7 +615,7 @@ void BM_ExecuteBinaryPrimeSieve(benchmark::State& state) {
notif.WaitForNotification();
return response;
};
::privacy_sandbox::server_common::byob::RunPrimeSieveRequest request;
::privacy_sandbox::roma_byob::example::RunPrimeSieveRequest request;
request.set_prime_count(state.range(1));
const std::string code_tok = LoadCode(
roma_service, std::filesystem::path(kUdfPath) / "prime_sieve_udf");
Expand Down
4 changes: 2 additions & 2 deletions src/roma/byob/dispatcher/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ cc_test(
":dispatcher",
":dispatcher_cc_proto",
"//src/roma/byob/host:callback_cc_proto",
"//src/roma/byob/udf:sample_cc_proto",
"//src/roma/byob/udf:sample_byob_sdk_cc_proto",
"//src/roma/config",
"@com_google_absl//absl/cleanup",
"@com_google_absl//absl/container:flat_hash_map",
Expand Down Expand Up @@ -83,7 +83,7 @@ cc_test(
],
deps = [
":dispatcher",
"//src/roma/byob/udf:sample_cc_proto",
"//src/roma/byob/udf:sample_byob_sdk_cc_proto",
"//src/roma/config",
"@com_google_absl//absl/cleanup",
"@com_google_absl//absl/container:flat_hash_map",
Expand Down
12 changes: 7 additions & 5 deletions src/roma/byob/dispatcher/dispatcher_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "google/protobuf/util/delimited_message_util.h"
#include "src/roma/byob/dispatcher/dispatcher.pb.h"
#include "src/roma/byob/host/callback.pb.h"
#include "src/roma/byob/udf/sample.pb.h"
#include "src/roma/byob/udf/sample_udf_interface.pb.h"
#include "src/roma/config/function_binding_object_v2.h"

namespace privacy_sandbox::server_common::byob {
Expand All @@ -47,10 +47,12 @@ using ::google::protobuf::io::FileInputStream;
using ::google::protobuf::util::ParseDelimitedFromZeroCopyStream;
using ::google::protobuf::util::SerializeDelimitedToFileDescriptor;
using ::google::scp::roma::FunctionBindingPayload;
using ::privacy_sandbox::server_common::byob::FUNCTION_CALLBACK;
using ::privacy_sandbox::server_common::byob::FUNCTION_HELLO_WORLD;
using ::privacy_sandbox::server_common::byob::FUNCTION_PRIME_SIEVE;
using ::privacy_sandbox::server_common::byob::FUNCTION_TEN_CALLBACK_INVOCATIONS;
using ::privacy_sandbox::roma_byob::example::FUNCTION_CALLBACK;
using ::privacy_sandbox::roma_byob::example::FUNCTION_HELLO_WORLD;
using ::privacy_sandbox::roma_byob::example::FUNCTION_PRIME_SIEVE;
using ::privacy_sandbox::roma_byob::example::FUNCTION_TEN_CALLBACK_INVOCATIONS;
using ::privacy_sandbox::roma_byob::example::SampleRequest;
using ::privacy_sandbox::roma_byob::example::SampleResponse;
using ::testing::Contains;
using ::testing::StrEq;
using ::testing::UnorderedElementsAre;
Expand Down
12 changes: 7 additions & 5 deletions src/roma/byob/dispatcher/dispatcher_udf_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@
#include "absl/synchronization/notification.h"
#include "google/protobuf/any.pb.h"
#include "src/roma/byob/dispatcher/dispatcher.h"
#include "src/roma/byob/udf/sample.pb.h"
#include "src/roma/byob/udf/sample_udf_interface.pb.h"
#include "src/roma/config/function_binding_object_v2.h"

namespace privacy_sandbox::server_common::byob {
namespace {
using ::google::scp::roma::FunctionBindingPayload;
using ::privacy_sandbox::server_common::byob::FUNCTION_CALLBACK;
using ::privacy_sandbox::server_common::byob::FUNCTION_HELLO_WORLD;
using ::privacy_sandbox::server_common::byob::FUNCTION_PRIME_SIEVE;
using ::privacy_sandbox::server_common::byob::FUNCTION_TEN_CALLBACK_INVOCATIONS;
using ::privacy_sandbox::roma_byob::example::FUNCTION_CALLBACK;
using ::privacy_sandbox::roma_byob::example::FUNCTION_HELLO_WORLD;
using ::privacy_sandbox::roma_byob::example::FUNCTION_PRIME_SIEVE;
using ::privacy_sandbox::roma_byob::example::FUNCTION_TEN_CALLBACK_INVOCATIONS;
using ::privacy_sandbox::roma_byob::example::SampleRequest;
using ::privacy_sandbox::roma_byob::example::SampleResponse;
using ::testing::Contains;
using ::testing::StrEq;

Expand Down
4 changes: 2 additions & 2 deletions src/roma/byob/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ cc_binary(
name = "roma_byob_test",
srcs = ["roma_byob_test.cc"],
deps = [
"//src/roma/byob/udf:sample_byob_sdk_cc_proto",
"//src/roma/byob/udf:sample_byob_sdk_roma_cc_lib",
"//src/roma/byob/udf:sample_callback_cc_proto",
"//src/roma/byob/udf:sample_cc_proto",
"//src/roma/byob/udf:sample_roma_api",
"//src/roma/byob/utility:udf_blob",
"//src/roma/byob/utility:utils",
"@com_google_absl//absl/strings",
Expand Down
27 changes: 13 additions & 14 deletions src/roma/byob/test/roma_byob_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

#include "absl/strings/str_cat.h"
#include "absl/synchronization/notification.h"
#include "src/roma/byob/udf/sample.pb.h"
#include "src/roma/byob/udf/sample_callback.pb.h"
#include "src/roma/byob/udf/sample_roma_byob_app_service.h"
#include "src/roma/byob/udf/sample_udf_interface.pb.h"
#include "src/roma/byob/utility/udf_blob.h"
#include "src/roma/byob/utility/utils.h"
#include "src/roma/config/function_binding_object_v2.h"
Expand All @@ -35,20 +35,21 @@ namespace privacy_sandbox::server_common::byob::test {

namespace {
using ::google::scp::roma::FunctionBindingObjectV2;
using ::privacy_sandbox::sample_server::roma_app_api::ByobSampleService;
using ::privacy_sandbox::sample_server::roma_app_api::SampleService;
using ::privacy_sandbox::roma_byob::example::ByobSampleService;
using ::privacy_sandbox::roma_byob::example::FUNCTION_CALLBACK;
using ::privacy_sandbox::roma_byob::example::FUNCTION_HELLO_WORLD;
using ::privacy_sandbox::roma_byob::example::FUNCTION_PRIME_SIEVE;
using ::privacy_sandbox::roma_byob::example::FUNCTION_TEN_CALLBACK_INVOCATIONS;
using ::privacy_sandbox::roma_byob::example::FunctionType;
using ::privacy_sandbox::roma_byob::example::ReadCallbackPayloadRequest;
using ::privacy_sandbox::roma_byob::example::ReadCallbackPayloadResponse;
using ::privacy_sandbox::roma_byob::example::SampleRequest;
using ::privacy_sandbox::roma_byob::example::SampleResponse;
using ::privacy_sandbox::roma_byob::example::SampleService;
using ::privacy_sandbox::server_common::byob::CallbackReadRequest;
using ::privacy_sandbox::server_common::byob::CallbackReadResponse;
using ::privacy_sandbox::server_common::byob::FUNCTION_CALLBACK;
using ::privacy_sandbox::server_common::byob::FUNCTION_HELLO_WORLD;
using ::privacy_sandbox::server_common::byob::FUNCTION_PRIME_SIEVE;
using ::privacy_sandbox::server_common::byob::FUNCTION_TEN_CALLBACK_INVOCATIONS;
using ::privacy_sandbox::server_common::byob::FunctionType;
using ::privacy_sandbox::server_common::byob::HasClonePermissionsByobWorker;
using ::privacy_sandbox::server_common::byob::Mode;
using ::privacy_sandbox::server_common::byob::ReadCallbackPayloadRequest;
using ::privacy_sandbox::server_common::byob::SampleRequest;
using ::privacy_sandbox::server_common::byob::SampleResponse;

const std::filesystem::path kUdfPath = "/udf";
const std::filesystem::path kGoLangBinaryFilename = "sample_go_udf";
Expand Down Expand Up @@ -271,9 +272,7 @@ TEST(RomaByobTest, ExecuteCppBinaryWithHostCallbackInSandboxMode) {

std::string code_token =
LoadCode(roma_service, kUdfPath / kCallbackPayloadReadUdfFilename);
absl::StatusOr<std::unique_ptr<
privacy_sandbox::server_common::byob::ReadCallbackPayloadResponse>>
response;
absl::StatusOr<std::unique_ptr<ReadCallbackPayloadResponse>> response;
absl::Notification notif;
CHECK_OK(roma_service.ReadCallbackPayload(notif, request, response,
/*metadata=*/{}, code_token));
Expand Down
Loading

0 comments on commit 8e66824

Please sign in to comment.