Skip to content

Commit

Permalink
adding grpc-gateway to generate bff reporting definitions (#1006)
Browse files Browse the repository at this point in the history
This is to create the proto messages for gRPC-Gateway. gRPC-Gateway uses
a Go gateway, so these messages will be converted to Go. The Kotlin
messages will be added later when setting up the gRPC service (not the
gateway).

Right now the BFF proto messages are exactly the same as the Reporting
service v2alpha messages. This will surely change, but we're still
working out how the UI will look and not sure how to make those messages
yet. So for now, just going to use the existing proto definitions to put
something here.
  • Loading branch information
bdomen-ggl authored May 22, 2023
1 parent 5b78087 commit 0ded775
Show file tree
Hide file tree
Showing 9 changed files with 782 additions and 0 deletions.
9 changes: 9 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ maven_install(
],
)

load("@bazel_gazelle//:deps.bzl", "go_repository")

go_repository(
name = "org_golang_google_grpc_cmd_protoc_gen_go_grpc",
importpath = "google.golang.org/grpc/cmd/protoc-gen-go-grpc",
sum = "h1:TLkBREm4nIsEcexnCjgQd5GQWaHcqMzwQV0TX9pq8S0=",
version = "v1.2.0",
)

load("@wfa_common_jvm//build:common_jvm_extra_deps.bzl", "common_jvm_extra_deps")

common_jvm_extra_deps()
49 changes: 49 additions & 0 deletions build/grpc_gateway/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
load("@io_bazel_rules_go//proto:compiler.bzl", "go_proto_compiler")
load("@io_bazel_rules_go//proto/wkt:well_known_types.bzl", "PROTO_RUNTIME_DEPS", "WELL_KNOWN_TYPES_APIV2")

go_proto_compiler(
name = "go_apiv2",
options = [
"paths=source_relative",
],
plugin = "@org_golang_google_protobuf//cmd/protoc-gen-go",
suffix = ".pb.go",
visibility = ["//visibility:public"],
deps = PROTO_RUNTIME_DEPS + WELL_KNOWN_TYPES_APIV2,
)

go_proto_compiler(
name = "go_grpc",
options = [
"paths=source_relative",
"require_unimplemented_servers=false",
],
plugin = "@org_golang_google_grpc_cmd_protoc_gen_go_grpc//:protoc-gen-go-grpc",
suffix = "_grpc.pb.go",
visibility = ["//visibility:public"],
deps = PROTO_RUNTIME_DEPS + [
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//codes:go_default_library",
"@org_golang_google_grpc//status:go_default_library",
],
)

go_proto_compiler(
name = "go_grpc_gateway",
options = ["logtostderr=true"],
plugin = "@protoc_gen_grpc_gateway//file",
suffix = ".pb.gw.go",
visibility = ["//visibility:public"],
deps = [
"@com_github_golang_protobuf//descriptor:go_default_library_gen",
"@go_googleapis//google/api:annotations_go_proto",
"@grpc_ecosystem_grpc_gateway//runtime:go_default_library",
"@grpc_ecosystem_grpc_gateway//utilities:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//codes:go_default_library",
"@org_golang_google_grpc//grpclog:go_default_library",
"@org_golang_google_grpc//metadata:go_default_library",
"@org_golang_google_grpc//status:go_default_library",
"@org_golang_google_protobuf//proto:go_default_library",
],
)
29 changes: 29 additions & 0 deletions build/grpc_gateway/defs.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2020 The Cross-Media Measurement Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Build defs for gRPC Gateway."""

load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

def go_grpc_gateway_proto_library(name, visibility = None, **kwargs):
go_proto_library(
name = name,
compilers = [
"//build/grpc_gateway:go_apiv2",
"//build/grpc_gateway:go_grpc",
"//build/grpc_gateway:go_grpc_gateway",
],
visibility = visibility,
**kwargs
)
34 changes: 34 additions & 0 deletions build/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Adds external repos necessary for wfa_measurement_system.
"""

load("//build/wfa:repositories.bzl", "wfa_repo_archive")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")

MEASUREMENT_SYSTEM_REPO = "https://github.com/world-federation-of-advertisers/cross-media-measurement"

Expand Down Expand Up @@ -78,3 +79,36 @@ def wfa_measurement_system_repositories():
sha256 = "0261b7797fa9083183536667958b1094fc732725fc48fca5cb68e6f731cdce2f",
version = "0.3.0",
)

http_archive(
name = "io_bazel_rules_go",
sha256 = "6b65cb7917b4d1709f9410ffe00ecf3e160edf674b78c54a894471320862184f",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.39.0/rules_go-v0.39.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.39.0/rules_go-v0.39.0.zip",
],
)

http_archive(
name = "bazel_gazelle",
sha256 = "ecba0f04f96b4960a5b250c8e8eeec42281035970aa8852dda73098274d14a1d",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.29.0/bazel-gazelle-v0.29.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.29.0/bazel-gazelle-v0.29.0.tar.gz",
],
)

http_file(
name = "protoc_gen_grpc_gateway",
sha256 = "d60028423c44b85c0bfbcf6393c35be7c53d439bc74b2e6f6caca863ad6df812",
urls = ["https://github.com/grpc-ecosystem/grpc-gateway/releases/download/v2.15.2/protoc-gen-grpc-gateway-v2.15.2-linux-x86_64"],
executable = True,
downloaded_file_path = "protoc-gen-grpc-gateway",
)

http_archive(
name = "grpc_ecosystem_grpc_gateway",
sha256 = "0675f7f8300f659a23e7ea4b8be5b38726c173b506a4d25c4309e93b4f1616ae",
strip_prefix = "grpc-gateway-2.15.2",
urls = ["https://github.com/grpc-ecosystem/grpc-gateway/archive/refs/tags/v2.15.2.tar.gz"],
)
90 changes: 90 additions & 0 deletions src/main/proto/wfa/measurement/reporting/bff/v1alpha/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//build/grpc_gateway:defs.bzl", "go_grpc_gateway_proto_library")

package(default_visibility = ["//visibility:public"])

IMPORT_PREFIX = "/src/main/proto"

GO_IMPORT_PATH = "wfa/measurement/reporting/bff/v1alpha/reportingpb"

proto_library(
name = "metric_proto",
srcs = [
"metric.proto",
],
strip_import_prefix = IMPORT_PREFIX,
deps = [
":time_interval_proto",
"@com_google_googleapis//google/api:field_behavior_proto",
"@com_google_googleapis//google/api:resource_proto",
"@com_google_protobuf//:timestamp_proto",
],
)

proto_library(
name = "time_interval_proto",
srcs = [
"time_interval.proto",
],
strip_import_prefix = IMPORT_PREFIX,
deps = [
"@com_google_googleapis//google/api:field_behavior_proto",
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:timestamp_proto",
],
)

proto_library(
name = "report_proto",
srcs = [
"report.proto",
],
strip_import_prefix = IMPORT_PREFIX,
deps = [
":metric_proto",
":time_interval_proto",
"@com_google_googleapis//google/api:field_behavior_proto",
"@com_google_googleapis//google/api:resource_proto",
"@com_google_protobuf//:timestamp_proto",
],
)

proto_library(
name = "reports_service_proto",
srcs = ["reports_service.proto"],
strip_import_prefix = IMPORT_PREFIX,
deps = [
":report_proto",
"@com_google_googleapis//google/api:annotations_proto",
"@com_google_googleapis//google/api:client_proto",
"@com_google_googleapis//google/api:field_behavior_proto",
"@com_google_googleapis//google/api:resource_proto",
],
)

go_grpc_gateway_proto_library(
name = "metric_go_proto",
embed = [":time_interval_go_proto"],
importpath = GO_IMPORT_PATH,
protos = [":metric_proto"],
)

go_grpc_gateway_proto_library(
name = "time_interval_go_proto",
importpath = GO_IMPORT_PATH,
protos = [":time_interval_proto"],
)

go_grpc_gateway_proto_library(
name = "report_go_proto",
embed = [":metric_go_proto"],
importpath = GO_IMPORT_PATH,
protos = [":report_proto"],
)

go_grpc_gateway_proto_library(
name = "reports_service_go_proto",
embed = [":report_go_proto"],
importpath = GO_IMPORT_PATH,
protos = [":reports_service_proto"],
)
Loading

0 comments on commit 0ded775

Please sign in to comment.