From 707b671c3b4d5b02d7c66b7c3243315d2fec162c Mon Sep 17 00:00:00 2001 From: George Barnett Date: Sat, 21 Sep 2024 11:55:40 +0100 Subject: [PATCH 1/5] Make examples standalone packages Motivation: Standalone packages for examples are an easier on-ramp for newcomers as they only see the details they care about and it can act as a starting point which they can develop from. Modifications: - Turn each example into a standalone package and add a README to each - Update the generate and fetch scripts and re-run them Result: Better examples --- .github/workflows/ci.yaml | 14 ++++ Examples/echo/.gitignore | 8 +++ Examples/echo/Package.swift | 38 +++++++++++ Examples/echo/README.md | 46 +++++++++++++ Examples/{v2/echo => echo/Sources}/Echo.swift | 1 - .../Sources}/Generated/echo.grpc.swift | 0 .../Sources}/Generated/echo.pb.swift | 0 .../Subcommands/ClientArguments.swift | 2 +- .../Sources}/Subcommands/Collect.swift | 4 +- .../Sources}/Subcommands/Expand.swift | 4 +- .../Sources}/Subcommands/Get.swift | 4 +- .../Sources}/Subcommands/Serve.swift | 4 +- .../Sources}/Subcommands/Update.swift | 4 +- Examples/hello-world/.gitignore | 8 +++ Examples/hello-world/Package.swift | 38 +++++++++++ Examples/hello-world/Protos | 37 +++++++++++ Examples/hello-world/README.md | 34 ++++++++++ .../Sources}/Generated/helloworld.grpc.swift | 0 .../Sources}/Generated/helloworld.pb.swift | 0 .../Sources}/HelloWorld.swift | 1 - .../Sources}/Subcommands/Greet.swift | 3 +- .../Sources}/Subcommands/Serve.swift | 4 +- Examples/route-guide/.gitignore | 8 +++ Examples/route-guide/Package.swift | 41 ++++++++++++ Examples/route-guide/README.md | 44 +++++++++++++ .../Sources}/Generated/route_guide.grpc.swift | 0 .../Sources}/Generated/route_guide.pb.swift | 0 .../Sources}/RouteGuide.swift | 0 .../Sources}/Subcommands/GetFeature.swift | 3 +- .../Sources}/Subcommands/ListFeatures.swift | 3 +- .../Sources}/Subcommands/RecordRoute.swift | 3 +- .../Sources}/Subcommands/RouteChat.swift | 3 +- .../Sources}/Subcommands/Serve.swift | 11 ++-- .../Sources}/route_guide_db.json | 0 Examples/v2/hello-world/HelloWorld.proto | 1 - dev/Protos/fetch.sh | 4 +- dev/Protos/generate.sh | 64 +++++++++++++++++-- dev/build-examples.sh | 39 +++++++++++ dev/format.sh | 3 +- dev/license-check.sh | 2 +- 40 files changed, 435 insertions(+), 48 deletions(-) create mode 100644 Examples/echo/.gitignore create mode 100644 Examples/echo/Package.swift create mode 100644 Examples/echo/README.md rename Examples/{v2/echo => echo/Sources}/Echo.swift (92%) rename Examples/{v2/echo => echo/Sources}/Generated/echo.grpc.swift (100%) rename Examples/{v2/echo => echo/Sources}/Generated/echo.pb.swift (100%) rename Examples/{v2/echo => echo/Sources}/Subcommands/ClientArguments.swift (97%) rename Examples/{v2/echo => echo/Sources}/Subcommands/Collect.swift (92%) rename Examples/{v2/echo => echo/Sources}/Subcommands/Expand.swift (92%) rename Examples/{v2/echo => echo/Sources}/Subcommands/Get.swift (92%) rename Examples/{v2/echo => echo/Sources}/Subcommands/Serve.swift (95%) rename Examples/{v2/echo => echo/Sources}/Subcommands/Update.swift (93%) create mode 100644 Examples/hello-world/.gitignore create mode 100644 Examples/hello-world/Package.swift create mode 100644 Examples/hello-world/Protos create mode 100644 Examples/hello-world/README.md rename Examples/{v2/hello-world => hello-world/Sources}/Generated/helloworld.grpc.swift (100%) rename Examples/{v2/hello-world => hello-world/Sources}/Generated/helloworld.pb.swift (100%) rename Examples/{v2/hello-world => hello-world/Sources}/HelloWorld.swift (92%) rename Examples/{v2/hello-world => hello-world/Sources}/Subcommands/Greet.swift (93%) rename Examples/{v2/hello-world => hello-world/Sources}/Subcommands/Serve.swift (91%) create mode 100644 Examples/route-guide/.gitignore create mode 100644 Examples/route-guide/Package.swift create mode 100644 Examples/route-guide/README.md rename Examples/{v2/route-guide => route-guide/Sources}/Generated/route_guide.grpc.swift (100%) rename Examples/{v2/route-guide => route-guide/Sources}/Generated/route_guide.pb.swift (100%) rename Examples/{v2/route-guide => route-guide/Sources}/RouteGuide.swift (100%) rename Examples/{v2/route-guide => route-guide/Sources}/Subcommands/GetFeature.swift (95%) rename Examples/{v2/route-guide => route-guide/Sources}/Subcommands/ListFeatures.swift (96%) rename Examples/{v2/route-guide => route-guide/Sources}/Subcommands/RecordRoute.swift (95%) rename Examples/{v2/route-guide => route-guide/Sources}/Subcommands/RouteChat.swift (95%) rename Examples/{v2/route-guide => route-guide/Sources}/Subcommands/Serve.swift (96%) rename Examples/{v2/route-guide => route-guide/Sources}/route_guide_db.json (100%) delete mode 120000 Examples/v2/hello-world/HelloWorld.proto create mode 100755 dev/build-examples.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d795e9681..248d19ba4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -65,3 +65,17 @@ jobs: working-directory: "./IntegrationTests/Benchmarks" run: swift package benchmark baseline check --no-progress --check-absolute-path Thresholds/${{ matrix.swift-version }}/ timeout-minutes: 20 + examples: + strategy: + matrix: + include: + - image: swiftlang/swift:nightly-jammy + - image: swift:6.0-jammy + name: Build examples using ${{ matrix.image }} + runs-on: ubuntu-latest + container: + image: ${{ matrix.image }} + steps: + - uses: actions/checkout@v4 + - name: Build examples + run: ./dev/build-examples.sh diff --git a/Examples/echo/.gitignore b/Examples/echo/.gitignore new file mode 100644 index 000000000..0023a5340 --- /dev/null +++ b/Examples/echo/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +/.build +/Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/Examples/echo/Package.swift b/Examples/echo/Package.swift new file mode 100644 index 000000000..4070fa1fe --- /dev/null +++ b/Examples/echo/Package.swift @@ -0,0 +1,38 @@ +// swift-tools-version:6.0 +/* + * Copyright 2024, gRPC Authors All rights reserved. + * + * 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. + */ + +import PackageDescription + +let package = Package( + name: "echo", + platforms: [.macOS(.v15)], + dependencies: [ + .package(url: "https://github.com/grpc/grpc-swift-protobuf", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport", branch: "main"), + .package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"), + ], + targets: [ + .executableTarget( + name: "echo", + dependencies: [ + .product(name: "GRPCNIOTransportHTTP2", package: "grpc-swift-nio-transport"), + .product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), + .product(name: "ArgumentParser", package: "swift-argument-parser"), + ] + ) + ] +) diff --git a/Examples/echo/README.md b/Examples/echo/README.md new file mode 100644 index 000000000..bea921190 --- /dev/null +++ b/Examples/echo/README.md @@ -0,0 +1,46 @@ +# Echo + +This example demonstrates all four RPC types using a simple 'echo' service and +client and the Swift NIO based HTTP/2 transport. + +## Overview + +An "echo" command line tool that uses generated stubs for an 'echo' service +which allows you to start a server and to make requests against it for each of +the four RPC types. + +The tool uses the [SwiftNIO](https://github.com/grpc/grpc-swift-nio-transport) +HTTP/2 transport. + +## Usage + +Build and run the server using the CLI: + +```console +$ swift run echo serve +Echo listening on [ipv4]127.0.0.1:1234 +``` + +Use the CLI to make a unary 'Get' request against it: + +```console +$ swift run echo get --message "Hello" +get → Hello +get ← Hello +``` + +Use the CLI to make a bidirectional streaming 'Update' request: + +```console +$ swift run echo update --message "Hello World" +update → Hello +update → World +update ← Hello +update ← World +``` + +Get help with the CLI by running: + +```console +$ swift run echo --help +``` diff --git a/Examples/v2/echo/Echo.swift b/Examples/echo/Sources/Echo.swift similarity index 92% rename from Examples/v2/echo/Echo.swift rename to Examples/echo/Sources/Echo.swift index 8ff07f420..edbe8d12f 100644 --- a/Examples/v2/echo/Echo.swift +++ b/Examples/echo/Sources/Echo.swift @@ -17,7 +17,6 @@ import ArgumentParser @main -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) struct Echo: AsyncParsableCommand { static let configuration = CommandConfiguration( commandName: "echo", diff --git a/Examples/v2/echo/Generated/echo.grpc.swift b/Examples/echo/Sources/Generated/echo.grpc.swift similarity index 100% rename from Examples/v2/echo/Generated/echo.grpc.swift rename to Examples/echo/Sources/Generated/echo.grpc.swift diff --git a/Examples/v2/echo/Generated/echo.pb.swift b/Examples/echo/Sources/Generated/echo.pb.swift similarity index 100% rename from Examples/v2/echo/Generated/echo.pb.swift rename to Examples/echo/Sources/Generated/echo.pb.swift diff --git a/Examples/v2/echo/Subcommands/ClientArguments.swift b/Examples/echo/Sources/Subcommands/ClientArguments.swift similarity index 97% rename from Examples/v2/echo/Subcommands/ClientArguments.swift rename to Examples/echo/Sources/Subcommands/ClientArguments.swift index 7dea8e59f..afa8cbd46 100644 --- a/Examples/v2/echo/Subcommands/ClientArguments.swift +++ b/Examples/echo/Sources/Subcommands/ClientArguments.swift @@ -15,7 +15,7 @@ */ import ArgumentParser -import GRPCHTTP2Core +import GRPCNIOTransportHTTP2 struct ClientArguments: ParsableArguments { @Option(help: "The server's listening port") diff --git a/Examples/v2/echo/Subcommands/Collect.swift b/Examples/echo/Sources/Subcommands/Collect.swift similarity index 92% rename from Examples/v2/echo/Subcommands/Collect.swift rename to Examples/echo/Sources/Subcommands/Collect.swift index 3a61915df..6022d8a2d 100644 --- a/Examples/v2/echo/Subcommands/Collect.swift +++ b/Examples/echo/Sources/Subcommands/Collect.swift @@ -16,10 +16,8 @@ import ArgumentParser import GRPCCore -import GRPCHTTP2Core -import GRPCHTTP2TransportNIOPosix +import GRPCNIOTransportHTTP2 -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) struct Collect: AsyncParsableCommand { static let configuration = CommandConfiguration( abstract: "Makes a client streaming RPC to the echo server." diff --git a/Examples/v2/echo/Subcommands/Expand.swift b/Examples/echo/Sources/Subcommands/Expand.swift similarity index 92% rename from Examples/v2/echo/Subcommands/Expand.swift rename to Examples/echo/Sources/Subcommands/Expand.swift index 1d06bdd99..d2e48bbf3 100644 --- a/Examples/v2/echo/Subcommands/Expand.swift +++ b/Examples/echo/Sources/Subcommands/Expand.swift @@ -16,10 +16,8 @@ import ArgumentParser import GRPCCore -import GRPCHTTP2Core -import GRPCHTTP2TransportNIOPosix +import GRPCNIOTransportHTTP2 -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) struct Expand: AsyncParsableCommand { static let configuration = CommandConfiguration( abstract: "Makes a server streaming RPC to the echo server." diff --git a/Examples/v2/echo/Subcommands/Get.swift b/Examples/echo/Sources/Subcommands/Get.swift similarity index 92% rename from Examples/v2/echo/Subcommands/Get.swift rename to Examples/echo/Sources/Subcommands/Get.swift index 0dd551002..ea69bc5f3 100644 --- a/Examples/v2/echo/Subcommands/Get.swift +++ b/Examples/echo/Sources/Subcommands/Get.swift @@ -16,10 +16,8 @@ import ArgumentParser import GRPCCore -import GRPCHTTP2Core -import GRPCHTTP2TransportNIOPosix +import GRPCNIOTransportHTTP2 -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) struct Get: AsyncParsableCommand { static let configuration = CommandConfiguration(abstract: "Makes a unary RPC to the echo server.") diff --git a/Examples/v2/echo/Subcommands/Serve.swift b/Examples/echo/Sources/Subcommands/Serve.swift similarity index 95% rename from Examples/v2/echo/Subcommands/Serve.swift rename to Examples/echo/Sources/Subcommands/Serve.swift index 5bfa1772f..6ea8648cb 100644 --- a/Examples/v2/echo/Subcommands/Serve.swift +++ b/Examples/echo/Sources/Subcommands/Serve.swift @@ -16,10 +16,8 @@ import ArgumentParser import GRPCCore -import GRPCHTTP2Core -import GRPCHTTP2TransportNIOPosix +import GRPCNIOTransportHTTP2 -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) struct Serve: AsyncParsableCommand { static let configuration = CommandConfiguration(abstract: "Starts an echo server.") diff --git a/Examples/v2/echo/Subcommands/Update.swift b/Examples/echo/Sources/Subcommands/Update.swift similarity index 93% rename from Examples/v2/echo/Subcommands/Update.swift rename to Examples/echo/Sources/Subcommands/Update.swift index 1c189caa8..1b4c81d00 100644 --- a/Examples/v2/echo/Subcommands/Update.swift +++ b/Examples/echo/Sources/Subcommands/Update.swift @@ -16,10 +16,8 @@ import ArgumentParser import GRPCCore -import GRPCHTTP2Core -import GRPCHTTP2TransportNIOPosix +import GRPCNIOTransportHTTP2 -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) struct Update: AsyncParsableCommand { static let configuration = CommandConfiguration( abstract: "Makes a bidirectional server streaming RPC to the echo server." diff --git a/Examples/hello-world/.gitignore b/Examples/hello-world/.gitignore new file mode 100644 index 000000000..0023a5340 --- /dev/null +++ b/Examples/hello-world/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +/.build +/Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/Examples/hello-world/Package.swift b/Examples/hello-world/Package.swift new file mode 100644 index 000000000..2c207cb83 --- /dev/null +++ b/Examples/hello-world/Package.swift @@ -0,0 +1,38 @@ +// swift-tools-version:6.0 +/* + * Copyright 2024, gRPC Authors All rights reserved. + * + * 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. + */ + +import PackageDescription + +let package = Package( + name: "hello-world", + platforms: [.macOS(.v15)], + dependencies: [ + .package(url: "https://github.com/grpc/grpc-swift-protobuf", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport", branch: "main"), + .package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"), + ], + targets: [ + .executableTarget( + name: "hello-world", + dependencies: [ + .product(name: "GRPCNIOTransportHTTP2", package: "grpc-swift-nio-transport"), + .product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), + .product(name: "ArgumentParser", package: "swift-argument-parser"), + ] + ) + ] +) diff --git a/Examples/hello-world/Protos b/Examples/hello-world/Protos new file mode 100644 index 000000000..2be480c2f --- /dev/null +++ b/Examples/hello-world/Protos @@ -0,0 +1,37 @@ +// Copyright 2015 gRPC 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. +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "io.grpc.examples.helloworld"; +option java_outer_classname = "HelloWorldProto"; +option objc_class_prefix = "HLW"; + +package helloworld; + +// The greeting service definition. +service Greeter { + // Sends a greeting + rpc SayHello (HelloRequest) returns (HelloReply) {} +} + +// The request message containing the user's name. +message HelloRequest { + string name = 1; +} + +// The response message containing the greetings +message HelloReply { + string message = 1; +} diff --git a/Examples/hello-world/README.md b/Examples/hello-world/README.md new file mode 100644 index 000000000..9a1ff32ce --- /dev/null +++ b/Examples/hello-world/README.md @@ -0,0 +1,34 @@ +# Hello World + +This example demonstrates the canonical "Hello World" in gRPC. + +## Overview + +A "hello-world" command line tool that uses generated stubs for the 'Greeter' +service which allows you to start a server and to make requests against it. + +The tool uses the [SwiftNIO](https://github.com/grpc/grpc-swift-nio-transport) +HTTP/2 transport. + +## Usage + +Build and run the server using the CLI: + +```console +$ swift run hello-world serve +Greeter listening on [ipv4]127.0.0.1:31415 +``` + +Use the CLI to send a request to the service: + +```console +$ swift run hello-world greet +Hello, stranger +``` + +Send the name of the greetee in the request by specifying a `--name`: + +```console +$ swift run hello-world greet --name "PanCakes 🐶" +Hello, PanCakes 🐶 +``` diff --git a/Examples/v2/hello-world/Generated/helloworld.grpc.swift b/Examples/hello-world/Sources/Generated/helloworld.grpc.swift similarity index 100% rename from Examples/v2/hello-world/Generated/helloworld.grpc.swift rename to Examples/hello-world/Sources/Generated/helloworld.grpc.swift diff --git a/Examples/v2/hello-world/Generated/helloworld.pb.swift b/Examples/hello-world/Sources/Generated/helloworld.pb.swift similarity index 100% rename from Examples/v2/hello-world/Generated/helloworld.pb.swift rename to Examples/hello-world/Sources/Generated/helloworld.pb.swift diff --git a/Examples/v2/hello-world/HelloWorld.swift b/Examples/hello-world/Sources/HelloWorld.swift similarity index 92% rename from Examples/v2/hello-world/HelloWorld.swift rename to Examples/hello-world/Sources/HelloWorld.swift index 8d467670a..6877b055f 100644 --- a/Examples/v2/hello-world/HelloWorld.swift +++ b/Examples/hello-world/Sources/HelloWorld.swift @@ -17,7 +17,6 @@ import ArgumentParser @main -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) struct HelloWorld: AsyncParsableCommand { static let configuration = CommandConfiguration( commandName: "hello-world", diff --git a/Examples/v2/hello-world/Subcommands/Greet.swift b/Examples/hello-world/Sources/Subcommands/Greet.swift similarity index 93% rename from Examples/v2/hello-world/Subcommands/Greet.swift rename to Examples/hello-world/Sources/Subcommands/Greet.swift index 069b8faee..940a1c9cb 100644 --- a/Examples/v2/hello-world/Subcommands/Greet.swift +++ b/Examples/hello-world/Sources/Subcommands/Greet.swift @@ -15,10 +15,9 @@ */ import ArgumentParser -import GRPCHTTP2Transport +import GRPCNIOTransportHTTP2 import GRPCProtobuf -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) struct Greet: AsyncParsableCommand { static let configuration = CommandConfiguration(abstract: "Sends a request to the greeter server") diff --git a/Examples/v2/hello-world/Subcommands/Serve.swift b/Examples/hello-world/Sources/Subcommands/Serve.swift similarity index 91% rename from Examples/v2/hello-world/Subcommands/Serve.swift rename to Examples/hello-world/Sources/Subcommands/Serve.swift index a9dd178ec..75f083ece 100644 --- a/Examples/v2/hello-world/Subcommands/Serve.swift +++ b/Examples/hello-world/Sources/Subcommands/Serve.swift @@ -15,10 +15,9 @@ */ import ArgumentParser -import GRPCHTTP2Transport +import GRPCNIOTransportHTTP2 import GRPCProtobuf -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) struct Serve: AsyncParsableCommand { static let configuration = CommandConfiguration(abstract: "Starts a greeter server.") @@ -43,7 +42,6 @@ struct Serve: AsyncParsableCommand { } } -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) struct Greeter: Helloworld_GreeterServiceProtocol { func sayHello( request: ServerRequest.Single, diff --git a/Examples/route-guide/.gitignore b/Examples/route-guide/.gitignore new file mode 100644 index 000000000..0023a5340 --- /dev/null +++ b/Examples/route-guide/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +/.build +/Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/Examples/route-guide/Package.swift b/Examples/route-guide/Package.swift new file mode 100644 index 000000000..ce45593cf --- /dev/null +++ b/Examples/route-guide/Package.swift @@ -0,0 +1,41 @@ +// swift-tools-version:6.0 +/* + * Copyright 2024, gRPC Authors All rights reserved. + * + * 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. + */ + +import PackageDescription + +let package = Package( + name: "route-guide", + platforms: [.macOS(.v15)], + dependencies: [ + .package(url: "https://github.com/grpc/grpc-swift-protobuf", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport", branch: "main"), + .package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"), + ], + targets: [ + .executableTarget( + name: "route-guide", + dependencies: [ + .product(name: "GRPCNIOTransportHTTP2", package: "grpc-swift-nio-transport"), + .product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), + .product(name: "ArgumentParser", package: "swift-argument-parser"), + ], + resources: [ + .copy("route_guide_db.json") + ] + ) + ] +) diff --git a/Examples/route-guide/README.md b/Examples/route-guide/README.md new file mode 100644 index 000000000..a1c0a282a --- /dev/null +++ b/Examples/route-guide/README.md @@ -0,0 +1,44 @@ +# Route Guide + +This example demonstrates all four RPC types using a 'Route Guide' service and +client. + +## Overview + +A "rouge-guide" command line tool that uses generated stubs for an 'Route Guide' +service allows you to start a server and to make requests against it for +each of the four RPC types. + +The tool uses the [SwiftNIO](https://github.com/grpc/grpc-swift-nio-transport) +HTTP/2 transport. + +This example has an accompanying tutorial hosted on the [Swift Package +Index](https://swiftpackageindex.com/grpc/grpc-swift/main/tutorials/grpccore/route-guide). + +## Usage + +Build and run the server using the CLI: + +```console +$ swift run route-guide serve +server listening on [ipv4]127.0.0.1:31415 +``` + +Use the CLI to interrogate the different RPCs you can call: + +```console +$ swift run route-guide --help +USAGE: route-guide + +OPTIONS: + -h, --help Show help information. + +SUBCOMMANDS: + serve Starts a route-guide server. + get-feature Gets a feature at a given location. + list-features List all features within a bounding rectangle. + record-route Records a route by visiting N randomly selected points and prints a summary of it. + route-chat Visits a few points and records a note at each, and prints all notes previously recorded at each point. + + See 'route-guide help ' for detailed help. +``` diff --git a/Examples/v2/route-guide/Generated/route_guide.grpc.swift b/Examples/route-guide/Sources/Generated/route_guide.grpc.swift similarity index 100% rename from Examples/v2/route-guide/Generated/route_guide.grpc.swift rename to Examples/route-guide/Sources/Generated/route_guide.grpc.swift diff --git a/Examples/v2/route-guide/Generated/route_guide.pb.swift b/Examples/route-guide/Sources/Generated/route_guide.pb.swift similarity index 100% rename from Examples/v2/route-guide/Generated/route_guide.pb.swift rename to Examples/route-guide/Sources/Generated/route_guide.pb.swift diff --git a/Examples/v2/route-guide/RouteGuide.swift b/Examples/route-guide/Sources/RouteGuide.swift similarity index 100% rename from Examples/v2/route-guide/RouteGuide.swift rename to Examples/route-guide/Sources/RouteGuide.swift diff --git a/Examples/v2/route-guide/Subcommands/GetFeature.swift b/Examples/route-guide/Sources/Subcommands/GetFeature.swift similarity index 95% rename from Examples/v2/route-guide/Subcommands/GetFeature.swift rename to Examples/route-guide/Sources/Subcommands/GetFeature.swift index 1c42ec6da..b3110e0c9 100644 --- a/Examples/v2/route-guide/Subcommands/GetFeature.swift +++ b/Examples/route-guide/Sources/Subcommands/GetFeature.swift @@ -15,9 +15,8 @@ */ import ArgumentParser -import GRPCHTTP2Transport +import GRPCNIOTransportHTTP2 -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) struct GetFeature: AsyncParsableCommand { static let configuration = CommandConfiguration(abstract: "Gets a feature at a given location.") diff --git a/Examples/v2/route-guide/Subcommands/ListFeatures.swift b/Examples/route-guide/Sources/Subcommands/ListFeatures.swift similarity index 96% rename from Examples/v2/route-guide/Subcommands/ListFeatures.swift rename to Examples/route-guide/Sources/Subcommands/ListFeatures.swift index 887a944e2..383eda154 100644 --- a/Examples/v2/route-guide/Subcommands/ListFeatures.swift +++ b/Examples/route-guide/Sources/Subcommands/ListFeatures.swift @@ -15,9 +15,8 @@ */ import ArgumentParser -import GRPCHTTP2Transport +import GRPCNIOTransportHTTP2 -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) struct ListFeatures: AsyncParsableCommand { static let configuration = CommandConfiguration( abstract: "List all features within a bounding rectangle." diff --git a/Examples/v2/route-guide/Subcommands/RecordRoute.swift b/Examples/route-guide/Sources/Subcommands/RecordRoute.swift similarity index 95% rename from Examples/v2/route-guide/Subcommands/RecordRoute.swift rename to Examples/route-guide/Sources/Subcommands/RecordRoute.swift index cd443230b..c3fcce361 100644 --- a/Examples/v2/route-guide/Subcommands/RecordRoute.swift +++ b/Examples/route-guide/Sources/Subcommands/RecordRoute.swift @@ -15,9 +15,8 @@ */ import ArgumentParser -import GRPCHTTP2Transport +import GRPCNIOTransportHTTP2 -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) struct RecordRoute: AsyncParsableCommand { static let configuration = CommandConfiguration( abstract: "Records a route by visiting N randomly selected points and prints a summary of it." diff --git a/Examples/v2/route-guide/Subcommands/RouteChat.swift b/Examples/route-guide/Sources/Subcommands/RouteChat.swift similarity index 95% rename from Examples/v2/route-guide/Subcommands/RouteChat.swift rename to Examples/route-guide/Sources/Subcommands/RouteChat.swift index 81cb5c3e2..23266e3bf 100644 --- a/Examples/v2/route-guide/Subcommands/RouteChat.swift +++ b/Examples/route-guide/Sources/Subcommands/RouteChat.swift @@ -15,9 +15,8 @@ */ import ArgumentParser -import GRPCHTTP2Transport +import GRPCNIOTransportHTTP2 -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) struct RouteChat: AsyncParsableCommand { static let configuration = CommandConfiguration( abstract: """ diff --git a/Examples/v2/route-guide/Subcommands/Serve.swift b/Examples/route-guide/Sources/Subcommands/Serve.swift similarity index 96% rename from Examples/v2/route-guide/Subcommands/Serve.swift rename to Examples/route-guide/Sources/Subcommands/Serve.swift index f9b942876..5bfdc200e 100644 --- a/Examples/v2/route-guide/Subcommands/Serve.swift +++ b/Examples/route-guide/Sources/Subcommands/Serve.swift @@ -16,11 +16,10 @@ import ArgumentParser import Foundation -import GRPCHTTP2Transport +import GRPCNIOTransportHTTP2 import GRPCProtobuf import Synchronization -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) struct Serve: AsyncParsableCommand { static let configuration = CommandConfiguration(abstract: "Starts a route-guide server.") @@ -52,7 +51,6 @@ struct Serve: AsyncParsableCommand { } } -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) struct RouteGuideService { /// Known features. private let features: [Routeguide_Feature] @@ -100,7 +98,6 @@ struct RouteGuideService { } } -@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) extension RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { func getFeature( request: ServerRequest.Single, @@ -131,7 +128,7 @@ extension RouteGuideService: Routeguide_RouteGuide.ServiceProtocol { context: ServerContext ) async throws -> ServerResponse.Stream { return ServerResponse.Stream { writer in - let featuresWithinBounds = self.features.filter { feature in + let featuresWithinBounds = self.features.filter { feature in !feature.name.isEmpty && feature.isContained(by: request.message) } @@ -223,8 +220,8 @@ private func greatCircleDistance( let phi1 = radians(degreesInE7: point1.latitude) let lambda2 = radians(degreesInE7: point2.longitude) let phi2 = radians(degreesInE7: point2.latitude) - - // Δλ = λ2 - λ1 + + // Δλ = λ2 - λ1 let deltaLambda = lambda2 - lambda1 // Δφ = φ2 - φ1 let deltaPhi = phi2 - phi1 diff --git a/Examples/v2/route-guide/route_guide_db.json b/Examples/route-guide/Sources/route_guide_db.json similarity index 100% rename from Examples/v2/route-guide/route_guide_db.json rename to Examples/route-guide/Sources/route_guide_db.json diff --git a/Examples/v2/hello-world/HelloWorld.proto b/Examples/v2/hello-world/HelloWorld.proto deleted file mode 120000 index f746c2066..000000000 --- a/Examples/v2/hello-world/HelloWorld.proto +++ /dev/null @@ -1 +0,0 @@ -../../../Protos/upstream/grpc/examples/helloworld.proto \ No newline at end of file diff --git a/dev/Protos/fetch.sh b/dev/Protos/fetch.sh index e68ce6531..01bf4d780 100755 --- a/dev/Protos/fetch.sh +++ b/dev/Protos/fetch.sh @@ -18,6 +18,7 @@ set -eu here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" upstream="$here/upstream" +root="$here/../.." # Create a temporary directory for the repo checkouts. checkouts="$(mktemp -d)" @@ -33,11 +34,12 @@ rm -rf "$upstream" # rather than source repository name. mkdir -p "$upstream/google" mkdir -p "$upstream/grpc/core" +mkdir -p "$upstream/grpc/examples" # Copy over the grpc-proto protos. cp -rp "$checkouts/grpc-proto/grpc/service_config" "$upstream/grpc/service_config" cp -rp "$checkouts/grpc-proto/grpc/lookup" "$upstream/grpc/lookup" -cp -rp "$checkouts/grpc-proto/grpc/examples" "$upstream/grpc/examples" +cp "$checkouts/grpc-proto/grpc/examples/helloworld.proto" "$upstream/grpc/examples/helloworld.proto" # Copy over the googleapis protos. mkdir -p "$upstream/google/rpc" diff --git a/dev/Protos/generate.sh b/dev/Protos/generate.sh index 17cad9ec1..666e87c49 100755 --- a/dev/Protos/generate.sh +++ b/dev/Protos/generate.sh @@ -20,12 +20,33 @@ here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" root="$here/../.." protoc=$(which protoc) -# Build the protoc plugins. -swift build -c release --product protoc-gen-swift +# Checkout and build the plugins. +build_dir=$(mktemp -d) +git clone https://github.com/grpc/grpc-swift-protobuf --depth 1 "$build_dir" +swift build --package-path "$build_dir" --product protoc-gen-swift +swift build --package-path "$build_dir" --product protoc-gen-grpc-swift # Grab the plugin paths. -bin_path=$(swift build -c release --show-bin-path) +bin_path=$(swift build --package-path "$build_dir" --show-bin-path) protoc_gen_swift="$bin_path/protoc-gen-swift" +protoc_gen_grpc_swift="$bin_path/protoc-gen-grpc-swift" + +# Generates gRPC by invoking protoc with the gRPC Swift plugin. +# Parameters: +# - $1: .proto file +# - $2: proto path +# - $3: output path +# - $4 onwards: options to forward to the plugin +function generate_grpc { + local proto=$1 + local args=("--plugin=$protoc_gen_grpc_swift" "--proto_path=${2}" "--grpc-swift_out=${3}") + + for option in "${@:4}"; do + args+=("--grpc-swift_opt=$option") + done + + invoke_protoc "${args[@]}" "$proto" +} # Generates messages by invoking protoc with the Swift plugin. # Parameters: @@ -51,9 +72,35 @@ function invoke_protoc { "$protoc" "$@" } -#------------------------------------------------------------------------------ +#- EXAMPLES ------------------------------------------------------------------- + +function generate_echo_example { + local proto="$here/examples/echo/echo.proto" + local output="$root/Examples/echo/Sources/Generated" + + generate_message "$proto" "$(dirname "$proto")" "$output" "Visibility=Internal" + generate_grpc "$proto" "$(dirname "$proto")" "$output" "Visibility=Internal" +} + +function generate_helloworld_example { + local proto="$here/upstream/grpc/examples/helloworld.proto" + local output="$root/Examples/hello-world/Sources/Generated" + + generate_message "$proto" "$(dirname "$proto")" "$output" "Visibility=Internal" + generate_grpc "$proto" "$(dirname "$proto")" "$output" "Visibility=Internal" +} + +function generate_routeguide_example { + local proto="$here/examples/route_guide/route_guide.proto" + local output="$root/Examples/route-guide/Sources/Generated" + + generate_message "$proto" "$(dirname "$proto")" "$output" "Visibility=Internal" + generate_grpc "$proto" "$(dirname "$proto")" "$output" "Visibility=Internal" +} + +#- TESTS ---------------------------------------------------------------------- -function generate_rpc_code_for_tests { +function generate_service_config_for_tests { local protos=( "$here/upstream/grpc/service_config/service_config.proto" "$here/upstream/grpc/lookup/v1/rls.proto" @@ -69,5 +116,10 @@ function generate_rpc_code_for_tests { #------------------------------------------------------------------------------ +# Generate examples +generate_echo_example +generate_helloworld_example +generate_routeguide_example + # Tests -generate_rpc_code_for_tests +generate_service_config_for_tests diff --git a/dev/build-examples.sh b/dev/build-examples.sh new file mode 100755 index 000000000..e44a8f5c6 --- /dev/null +++ b/dev/build-examples.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# Copyright 2024, gRPC Authors All rights reserved. +# +# 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. + +set -euo pipefail + +log() { printf -- "** %s\n" "$*" >&2; } +error() { printf -- "** ERROR: %s\n" "$*" >&2; } +fatal() { error "$@"; exit 1; } + +here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +examples="$here/../Examples" + +for dir in "$examples"/*/ ; do + if [[ -f "$dir/Package.swift" ]]; then + example=$(basename "$dir") + log "Building '$example' example" + + if ! build_output=$(swift build --package-path "$dir" 2>&1); then + # Only print the build output on failure. + echo "$build_output" + fatal "Build failed for '$example'" + else + log "Build succeeded for '$example'" + fi + fi +done diff --git a/dev/format.sh b/dev/format.sh index 4554e2f19..ac2d7f61a 100755 --- a/dev/format.sh +++ b/dev/format.sh @@ -60,7 +60,7 @@ if "$lint"; then --parallel --recursive --strict \ "${repo}/Sources" \ "${repo}/Tests" \ - "${repo}/Plugins" \ + "${repo}/Examples" \ "${repo}/IntegrationTests/Benchmarks/Benchmarks/GRPCSwiftBenchmark" \ && SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$? @@ -80,6 +80,7 @@ elif "$format"; then --parallel --recursive --in-place \ "${repo}/Sources" \ "${repo}/Tests" \ + "${repo}/Examples" \ "${repo}/IntegrationTests/Benchmarks/Benchmarks/GRPCSwiftBenchmark" \ && SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$? diff --git a/dev/license-check.sh b/dev/license-check.sh index 49dfb4f44..d540293aa 100755 --- a/dev/license-check.sh +++ b/dev/license-check.sh @@ -106,7 +106,7 @@ check_copyright_headers() { ! -name '*.pb.swift' \ ! -name '*.grpc.swift' \ ! -path './Sources/GRPCCore/Documentation.docc/*' \ - ! -path './.build/*') + ! -path '.*/.build/*') } errors=0 From 410f5af4590509e737bb6e1c908afb4866bb85cb Mon Sep 17 00:00:00 2001 From: George Barnett Date: Sat, 21 Sep 2024 11:56:11 +0100 Subject: [PATCH 2/5] Re-run fetch and generate --- .../Generated/rls_config.pb.swift | 9 + dev/Protos/upstream/grpc/core/stats.proto | 38 -- .../upstream/grpc/health/v1/health.proto | 73 ---- .../grpc/reflection/v1/reflection.proto | 147 -------- .../grpc/reflection/v1alpha/reflection.proto | 145 -------- .../grpc/testing/benchmark_service.proto | 48 --- .../upstream/grpc/testing/control.proto | 299 --------------- .../upstream/grpc/testing/messages.proto | 347 ------------------ .../upstream/grpc/testing/payloads.proto | 44 --- dev/Protos/upstream/grpc/testing/stats.proto | 87 ----- .../grpc/testing/worker_service.proto | 49 --- dev/check-generated-code.sh | 2 +- dev/{Protos => protos}/README.md | 0 .../examples/echo/echo.proto | 2 +- .../examples/route_guide/route_guide.proto | 0 dev/{Protos => protos}/fetch.sh | 0 dev/{Protos => protos}/generate.sh | 0 .../upstream/google/rpc/code.proto | 0 .../upstream/grpc/examples/helloworld.proto | 0 .../upstream/grpc/lookup/v1/rls.proto | 0 .../upstream/grpc/lookup/v1/rls_config.proto | 3 + .../grpc/service_config/service_config.proto | 0 22 files changed, 14 insertions(+), 1279 deletions(-) delete mode 100644 dev/Protos/upstream/grpc/core/stats.proto delete mode 100644 dev/Protos/upstream/grpc/health/v1/health.proto delete mode 100644 dev/Protos/upstream/grpc/reflection/v1/reflection.proto delete mode 100644 dev/Protos/upstream/grpc/reflection/v1alpha/reflection.proto delete mode 100644 dev/Protos/upstream/grpc/testing/benchmark_service.proto delete mode 100644 dev/Protos/upstream/grpc/testing/control.proto delete mode 100644 dev/Protos/upstream/grpc/testing/messages.proto delete mode 100644 dev/Protos/upstream/grpc/testing/payloads.proto delete mode 100644 dev/Protos/upstream/grpc/testing/stats.proto delete mode 100644 dev/Protos/upstream/grpc/testing/worker_service.proto rename dev/{Protos => protos}/README.md (100%) rename dev/{Protos => protos}/examples/echo/echo.proto (99%) rename dev/{Protos => protos}/examples/route_guide/route_guide.proto (100%) rename dev/{Protos => protos}/fetch.sh (100%) rename dev/{Protos => protos}/generate.sh (100%) rename dev/{Protos => protos}/upstream/google/rpc/code.proto (100%) rename dev/{Protos => protos}/upstream/grpc/examples/helloworld.proto (100%) rename dev/{Protos => protos}/upstream/grpc/lookup/v1/rls.proto (100%) rename dev/{Protos => protos}/upstream/grpc/lookup/v1/rls_config.proto (99%) rename dev/{Protos => protos}/upstream/grpc/service_config/service_config.proto (100%) diff --git a/Tests/GRPCCoreTests/Configuration/Generated/rls_config.pb.swift b/Tests/GRPCCoreTests/Configuration/Generated/rls_config.pb.swift index 879269999..bc6047eda 100644 --- a/Tests/GRPCCoreTests/Configuration/Generated/rls_config.pb.swift +++ b/Tests/GRPCCoreTests/Configuration/Generated/rls_config.pb.swift @@ -221,6 +221,9 @@ struct Grpc_Lookup_V1_HttpKeyBuilder: Sendable { /// need to separately cache and request URLs with that content. var constantKeys: Dictionary = [:] + /// If specified, the HTTP method/verb will be extracted under this key name. + var method: String = String() + var unknownFields = SwiftProtobuf.UnknownStorage() init() {} @@ -528,6 +531,7 @@ extension Grpc_Lookup_V1_HttpKeyBuilder: SwiftProtobuf.Message, SwiftProtobuf._M 3: .standard(proto: "query_parameters"), 4: .same(proto: "headers"), 5: .standard(proto: "constant_keys"), + 6: .same(proto: "method"), ] mutating func decodeMessage(decoder: inout D) throws { @@ -541,6 +545,7 @@ extension Grpc_Lookup_V1_HttpKeyBuilder: SwiftProtobuf.Message, SwiftProtobuf._M case 3: try { try decoder.decodeRepeatedMessageField(value: &self.queryParameters) }() case 4: try { try decoder.decodeRepeatedMessageField(value: &self.headers) }() case 5: try { try decoder.decodeMapField(fieldType: SwiftProtobuf._ProtobufMap.self, value: &self.constantKeys) }() + case 6: try { try decoder.decodeSingularStringField(value: &self.method) }() default: break } } @@ -562,6 +567,9 @@ extension Grpc_Lookup_V1_HttpKeyBuilder: SwiftProtobuf.Message, SwiftProtobuf._M if !self.constantKeys.isEmpty { try visitor.visitMapField(fieldType: SwiftProtobuf._ProtobufMap.self, value: self.constantKeys, fieldNumber: 5) } + if !self.method.isEmpty { + try visitor.visitSingularStringField(value: self.method, fieldNumber: 6) + } try unknownFields.traverse(visitor: &visitor) } @@ -571,6 +579,7 @@ extension Grpc_Lookup_V1_HttpKeyBuilder: SwiftProtobuf.Message, SwiftProtobuf._M if lhs.queryParameters != rhs.queryParameters {return false} if lhs.headers != rhs.headers {return false} if lhs.constantKeys != rhs.constantKeys {return false} + if lhs.method != rhs.method {return false} if lhs.unknownFields != rhs.unknownFields {return false} return true } diff --git a/dev/Protos/upstream/grpc/core/stats.proto b/dev/Protos/upstream/grpc/core/stats.proto deleted file mode 100644 index ac181b043..000000000 --- a/dev/Protos/upstream/grpc/core/stats.proto +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2017 gRPC 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. - -syntax = "proto3"; - -package grpc.core; - -message Bucket { - double start = 1; - uint64 count = 2; -} - -message Histogram { - repeated Bucket buckets = 1; -} - -message Metric { - string name = 1; - oneof value { - uint64 count = 10; - Histogram histogram = 11; - } -} - -message Stats { - repeated Metric metrics = 1; -} diff --git a/dev/Protos/upstream/grpc/health/v1/health.proto b/dev/Protos/upstream/grpc/health/v1/health.proto deleted file mode 100644 index 13b03f567..000000000 --- a/dev/Protos/upstream/grpc/health/v1/health.proto +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2015 The gRPC 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. - -// The canonical version of this proto can be found at -// https://github.com/grpc/grpc-proto/blob/master/grpc/health/v1/health.proto - -syntax = "proto3"; - -package grpc.health.v1; - -option csharp_namespace = "Grpc.Health.V1"; -option go_package = "google.golang.org/grpc/health/grpc_health_v1"; -option java_multiple_files = true; -option java_outer_classname = "HealthProto"; -option java_package = "io.grpc.health.v1"; - -message HealthCheckRequest { - string service = 1; -} - -message HealthCheckResponse { - enum ServingStatus { - UNKNOWN = 0; - SERVING = 1; - NOT_SERVING = 2; - SERVICE_UNKNOWN = 3; // Used only by the Watch method. - } - ServingStatus status = 1; -} - -// Health is gRPC's mechanism for checking whether a server is able to handle -// RPCs. Its semantics are documented in -// https://github.com/grpc/grpc/blob/master/doc/health-checking.md. -service Health { - // Check gets the health of the specified service. If the requested service - // is unknown, the call will fail with status NOT_FOUND. If the caller does - // not specify a service name, the server should respond with its overall - // health status. - // - // Clients should set a deadline when calling Check, and can declare the - // server unhealthy if they do not receive a timely response. - // - // Check implementations should be idempotent and side effect free. - rpc Check(HealthCheckRequest) returns (HealthCheckResponse); - - // Performs a watch for the serving status of the requested service. - // The server will immediately send back a message indicating the current - // serving status. It will then subsequently send a new message whenever - // the service's serving status changes. - // - // If the requested service is unknown when the call is received, the - // server will send a message setting the serving status to - // SERVICE_UNKNOWN but will *not* terminate the call. If at some - // future point, the serving status of the service becomes known, the - // server will send a new message with the service's serving status. - // - // If the call terminates with status UNIMPLEMENTED, then clients - // should assume this method is not supported and should not retry the - // call. If the call terminates with any other status (including OK), - // clients should retry the call with appropriate exponential backoff. - rpc Watch(HealthCheckRequest) returns (stream HealthCheckResponse); -} diff --git a/dev/Protos/upstream/grpc/reflection/v1/reflection.proto b/dev/Protos/upstream/grpc/reflection/v1/reflection.proto deleted file mode 100644 index 1a2ceedc3..000000000 --- a/dev/Protos/upstream/grpc/reflection/v1/reflection.proto +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright 2016 The gRPC 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. - -// Service exported by server reflection. A more complete description of how -// server reflection works can be found at -// https://github.com/grpc/grpc/blob/master/doc/server-reflection.md -// -// The canonical version of this proto can be found at -// https://github.com/grpc/grpc-proto/blob/master/grpc/reflection/v1/reflection.proto - -syntax = "proto3"; - -package grpc.reflection.v1; - -option go_package = "google.golang.org/grpc/reflection/grpc_reflection_v1"; -option java_multiple_files = true; -option java_package = "io.grpc.reflection.v1"; -option java_outer_classname = "ServerReflectionProto"; - -service ServerReflection { - // The reflection service is structured as a bidirectional stream, ensuring - // all related requests go to a single server. - rpc ServerReflectionInfo(stream ServerReflectionRequest) - returns (stream ServerReflectionResponse); -} - -// The message sent by the client when calling ServerReflectionInfo method. -message ServerReflectionRequest { - string host = 1; - // To use reflection service, the client should set one of the following - // fields in message_request. The server distinguishes requests by their - // defined field and then handles them using corresponding methods. - oneof message_request { - // Find a proto file by the file name. - string file_by_filename = 3; - - // Find the proto file that declares the given fully-qualified symbol name. - // This field should be a fully-qualified symbol name - // (e.g. .[.] or .). - string file_containing_symbol = 4; - - // Find the proto file which defines an extension extending the given - // message type with the given field number. - ExtensionRequest file_containing_extension = 5; - - // Finds the tag numbers used by all known extensions of the given message - // type, and appends them to ExtensionNumberResponse in an undefined order. - // Its corresponding method is best-effort: it's not guaranteed that the - // reflection service will implement this method, and it's not guaranteed - // that this method will provide all extensions. Returns - // StatusCode::UNIMPLEMENTED if it's not implemented. - // This field should be a fully-qualified type name. The format is - // . - string all_extension_numbers_of_type = 6; - - // List the full names of registered services. The content will not be - // checked. - string list_services = 7; - } -} - -// The type name and extension number sent by the client when requesting -// file_containing_extension. -message ExtensionRequest { - // Fully-qualified type name. The format should be . - string containing_type = 1; - int32 extension_number = 2; -} - -// The message sent by the server to answer ServerReflectionInfo method. -message ServerReflectionResponse { - string valid_host = 1; - ServerReflectionRequest original_request = 2; - // The server sets one of the following fields according to the message_request - // in the request. - oneof message_response { - // This message is used to answer file_by_filename, file_containing_symbol, - // file_containing_extension requests with transitive dependencies. - // As the repeated label is not allowed in oneof fields, we use a - // FileDescriptorResponse message to encapsulate the repeated fields. - // The reflection service is allowed to avoid sending FileDescriptorProtos - // that were previously sent in response to earlier requests in the stream. - FileDescriptorResponse file_descriptor_response = 4; - - // This message is used to answer all_extension_numbers_of_type requests. - ExtensionNumberResponse all_extension_numbers_response = 5; - - // This message is used to answer list_services requests. - ListServiceResponse list_services_response = 6; - - // This message is used when an error occurs. - ErrorResponse error_response = 7; - } -} - -// Serialized FileDescriptorProto messages sent by the server answering -// a file_by_filename, file_containing_symbol, or file_containing_extension -// request. -message FileDescriptorResponse { - // Serialized FileDescriptorProto messages. We avoid taking a dependency on - // descriptor.proto, which uses proto2 only features, by making them opaque - // bytes instead. - repeated bytes file_descriptor_proto = 1; -} - -// A list of extension numbers sent by the server answering -// all_extension_numbers_of_type request. -message ExtensionNumberResponse { - // Full name of the base type, including the package name. The format - // is . - string base_type_name = 1; - repeated int32 extension_number = 2; -} - -// A list of ServiceResponse sent by the server answering list_services request. -message ListServiceResponse { - // The information of each service may be expanded in the future, so we use - // ServiceResponse message to encapsulate it. - repeated ServiceResponse service = 1; -} - -// The information of a single service used by ListServiceResponse to answer -// list_services request. -message ServiceResponse { - // Full name of a registered service, including its package name. The format - // is . - string name = 1; -} - -// The error code and error message sent by the server when an error occurs. -message ErrorResponse { - // This field uses the error codes defined in grpc::StatusCode. - int32 error_code = 1; - string error_message = 2; -} - diff --git a/dev/Protos/upstream/grpc/reflection/v1alpha/reflection.proto b/dev/Protos/upstream/grpc/reflection/v1alpha/reflection.proto deleted file mode 100644 index 9cab8a4e0..000000000 --- a/dev/Protos/upstream/grpc/reflection/v1alpha/reflection.proto +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright 2016 The gRPC 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. -// Service exported by server reflection - - -// Warning: this entire file is deprecated. Use this instead: -// https://github.com/grpc/grpc-proto/blob/master/grpc/reflection/v1/reflection.proto - -syntax = "proto3"; - -package grpc.reflection.v1alpha; - -option deprecated = true; -option go_package = "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"; -option java_multiple_files = true; -option java_package = "io.grpc.reflection.v1alpha"; -option java_outer_classname = "ServerReflectionProto"; - -service ServerReflection { - // The reflection service is structured as a bidirectional stream, ensuring - // all related requests go to a single server. - rpc ServerReflectionInfo(stream ServerReflectionRequest) - returns (stream ServerReflectionResponse); -} - -// The message sent by the client when calling ServerReflectionInfo method. -message ServerReflectionRequest { - string host = 1; - // To use reflection service, the client should set one of the following - // fields in message_request. The server distinguishes requests by their - // defined field and then handles them using corresponding methods. - oneof message_request { - // Find a proto file by the file name. - string file_by_filename = 3; - - // Find the proto file that declares the given fully-qualified symbol name. - // This field should be a fully-qualified symbol name - // (e.g. .[.] or .). - string file_containing_symbol = 4; - - // Find the proto file which defines an extension extending the given - // message type with the given field number. - ExtensionRequest file_containing_extension = 5; - - // Finds the tag numbers used by all known extensions of extendee_type, and - // appends them to ExtensionNumberResponse in an undefined order. - // Its corresponding method is best-effort: it's not guaranteed that the - // reflection service will implement this method, and it's not guaranteed - // that this method will provide all extensions. Returns - // StatusCode::UNIMPLEMENTED if it's not implemented. - // This field should be a fully-qualified type name. The format is - // . - string all_extension_numbers_of_type = 6; - - // List the full names of registered services. The content will not be - // checked. - string list_services = 7; - } -} - -// The type name and extension number sent by the client when requesting -// file_containing_extension. -message ExtensionRequest { - // Fully-qualified type name. The format should be . - string containing_type = 1; - int32 extension_number = 2; -} - -// The message sent by the server to answer ServerReflectionInfo method. -message ServerReflectionResponse { - string valid_host = 1; - ServerReflectionRequest original_request = 2; - // The server set one of the following fields according to the message_request - // in the request. - oneof message_response { - // This message is used to answer file_by_filename, file_containing_symbol, - // file_containing_extension requests with transitive dependencies. As - // the repeated label is not allowed in oneof fields, we use a - // FileDescriptorResponse message to encapsulate the repeated fields. - // The reflection service is allowed to avoid sending FileDescriptorProtos - // that were previously sent in response to earlier requests in the stream. - FileDescriptorResponse file_descriptor_response = 4; - - // This message is used to answer all_extension_numbers_of_type requst. - ExtensionNumberResponse all_extension_numbers_response = 5; - - // This message is used to answer list_services request. - ListServiceResponse list_services_response = 6; - - // This message is used when an error occurs. - ErrorResponse error_response = 7; - } -} - -// Serialized FileDescriptorProto messages sent by the server answering -// a file_by_filename, file_containing_symbol, or file_containing_extension -// request. -message FileDescriptorResponse { - // Serialized FileDescriptorProto messages. We avoid taking a dependency on - // descriptor.proto, which uses proto2 only features, by making them opaque - // bytes instead. - repeated bytes file_descriptor_proto = 1; -} - -// A list of extension numbers sent by the server answering -// all_extension_numbers_of_type request. -message ExtensionNumberResponse { - // Full name of the base type, including the package name. The format - // is . - string base_type_name = 1; - repeated int32 extension_number = 2; -} - -// A list of ServiceResponse sent by the server answering list_services request. -message ListServiceResponse { - // The information of each service may be expanded in the future, so we use - // ServiceResponse message to encapsulate it. - repeated ServiceResponse service = 1; -} - -// The information of a single service used by ListServiceResponse to answer -// list_services request. -message ServiceResponse { - // Full name of a registered service, including its package name. The format - // is . - string name = 1; -} - -// The error code and error message sent by the server when an error occurs. -message ErrorResponse { - // This field uses the error codes defined in grpc::StatusCode. - int32 error_code = 1; - string error_message = 2; -} diff --git a/dev/Protos/upstream/grpc/testing/benchmark_service.proto b/dev/Protos/upstream/grpc/testing/benchmark_service.proto deleted file mode 100644 index 5209bd6ef..000000000 --- a/dev/Protos/upstream/grpc/testing/benchmark_service.proto +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2015 gRPC 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. - -// An integration test service that covers all the method signature permutations -// of unary/streaming requests/responses. -syntax = "proto3"; - -import "grpc/testing/messages.proto"; - -package grpc.testing; - -option java_multiple_files = true; -option java_package = "io.grpc.testing"; -option java_outer_classname = "BenchmarkServiceProto"; - -service BenchmarkService { - // One request followed by one response. - // The server returns the client payload as-is. - rpc UnaryCall(SimpleRequest) returns (SimpleResponse); - - // Repeated sequence of one request followed by one response. - // Should be called streaming ping-pong - // The server returns the client payload as-is on each response - rpc StreamingCall(stream SimpleRequest) returns (stream SimpleResponse); - - // Single-sided unbounded streaming from client to server - // The server returns the client payload as-is once the client does WritesDone - rpc StreamingFromClient(stream SimpleRequest) returns (SimpleResponse); - - // Single-sided unbounded streaming from server to client - // The server repeatedly returns the client payload as-is - rpc StreamingFromServer(SimpleRequest) returns (stream SimpleResponse); - - // Two-sided unbounded streaming between server to client - // Both sides send the content of their own choice to the other - rpc StreamingBothWays(stream SimpleRequest) returns (stream SimpleResponse); -} diff --git a/dev/Protos/upstream/grpc/testing/control.proto b/dev/Protos/upstream/grpc/testing/control.proto deleted file mode 100644 index e309e5f9c..000000000 --- a/dev/Protos/upstream/grpc/testing/control.proto +++ /dev/null @@ -1,299 +0,0 @@ -// Copyright 2015 gRPC 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. - -syntax = "proto3"; - -import "grpc/testing/payloads.proto"; -import "grpc/testing/stats.proto"; -import "google/protobuf/timestamp.proto"; - -package grpc.testing; - -option java_multiple_files = true; -option java_package = "io.grpc.testing"; -option java_outer_classname = "ControlProto"; - -enum ClientType { - // Many languages support a basic distinction between using - // sync or async client, and this allows the specification - SYNC_CLIENT = 0; - ASYNC_CLIENT = 1; - OTHER_CLIENT = 2; // used for some language-specific variants - CALLBACK_CLIENT = 3; -} - -enum ServerType { - SYNC_SERVER = 0; - ASYNC_SERVER = 1; - ASYNC_GENERIC_SERVER = 2; - OTHER_SERVER = 3; // used for some language-specific variants - CALLBACK_SERVER = 4; -} - -enum RpcType { - UNARY = 0; - STREAMING = 1; - STREAMING_FROM_CLIENT = 2; - STREAMING_FROM_SERVER = 3; - STREAMING_BOTH_WAYS = 4; -} - -// Parameters of poisson process distribution, which is a good representation -// of activity coming in from independent identical stationary sources. -message PoissonParams { - // The rate of arrivals (a.k.a. lambda parameter of the exp distribution). - double offered_load = 1; -} - -// Once an RPC finishes, immediately start a new one. -// No configuration parameters needed. -message ClosedLoopParams {} - -message LoadParams { - oneof load { - ClosedLoopParams closed_loop = 1; - PoissonParams poisson = 2; - }; -} - -// presence of SecurityParams implies use of TLS -message SecurityParams { - bool use_test_ca = 1; - string server_host_override = 2; - string cred_type = 3; -} - -message ChannelArg { - string name = 1; - oneof value { - string str_value = 2; - int32 int_value = 3; - } -} - -message ClientConfig { - // List of targets to connect to. At least one target needs to be specified. - repeated string server_targets = 1; - ClientType client_type = 2; - SecurityParams security_params = 3; - // How many concurrent RPCs to start for each channel. - // For synchronous client, use a separate thread for each outstanding RPC. - int32 outstanding_rpcs_per_channel = 4; - // Number of independent client channels to create. - // i-th channel will connect to server_target[i % server_targets.size()] - int32 client_channels = 5; - // Only for async client. Number of threads to use to start/manage RPCs. - int32 async_client_threads = 7; - RpcType rpc_type = 8; - // The requested load for the entire client (aggregated over all the threads). - LoadParams load_params = 10; - PayloadConfig payload_config = 11; - HistogramParams histogram_params = 12; - - // Specify the cores we should run the client on, if desired - repeated int32 core_list = 13; - int32 core_limit = 14; - - // If we use an OTHER_CLIENT client_type, this string gives more detail - string other_client_api = 15; - - repeated ChannelArg channel_args = 16; - - // Number of threads that share each completion queue - int32 threads_per_cq = 17; - - // Number of messages on a stream before it gets finished/restarted - int32 messages_per_stream = 18; - - // Use coalescing API when possible. - bool use_coalesce_api = 19; - - // If 0, disabled. Else, specifies the period between gathering latency - // medians in milliseconds. - int32 median_latency_collection_interval_millis = 20; - - // Number of client processes. 0 indicates no restriction. - int32 client_processes = 21; -} - -message ClientStatus { ClientStats stats = 1; } - -// Request current stats -message Mark { - // if true, the stats will be reset after taking their snapshot. - bool reset = 1; -} - -message ClientArgs { - oneof argtype { - ClientConfig setup = 1; - Mark mark = 2; - } -} - -message ServerConfig { - ServerType server_type = 1; - SecurityParams security_params = 2; - // Port on which to listen. Zero means pick unused port. - int32 port = 4; - // Only for async server. Number of threads used to serve the requests. - int32 async_server_threads = 7; - // Specify the number of cores to limit server to, if desired - int32 core_limit = 8; - // payload config, used in generic server. - // Note this must NOT be used in proto (non-generic) servers. For proto servers, - // 'response sizes' must be configured from the 'response_size' field of the - // 'SimpleRequest' objects in RPC requests. - PayloadConfig payload_config = 9; - - // Specify the cores we should run the server on, if desired - repeated int32 core_list = 10; - - // If we use an OTHER_SERVER client_type, this string gives more detail - string other_server_api = 11; - - // Number of threads that share each completion queue - int32 threads_per_cq = 12; - - // c++-only options (for now) -------------------------------- - - // Buffer pool size (no buffer pool specified if unset) - int32 resource_quota_size = 1001; - repeated ChannelArg channel_args = 1002; - - // Number of server processes. 0 indicates no restriction. - int32 server_processes = 21; -} - -message ServerArgs { - oneof argtype { - ServerConfig setup = 1; - Mark mark = 2; - } -} - -message ServerStatus { - ServerStats stats = 1; - // the port bound by the server - int32 port = 2; - // Number of cores available to the server - int32 cores = 3; -} - -message CoreRequest { -} - -message CoreResponse { - // Number of cores available on the server - int32 cores = 1; -} - -message Void { -} - -// A single performance scenario: input to qps_json_driver -message Scenario { - // Human readable name for this scenario - string name = 1; - // Client configuration - ClientConfig client_config = 2; - // Number of clients to start for the test - int32 num_clients = 3; - // Server configuration - ServerConfig server_config = 4; - // Number of servers to start for the test - int32 num_servers = 5; - // Warmup period, in seconds - int32 warmup_seconds = 6; - // Benchmark time, in seconds - int32 benchmark_seconds = 7; - // Number of workers to spawn locally (usually zero) - int32 spawn_local_worker_count = 8; -} - -// A set of scenarios to be run with qps_json_driver -message Scenarios { - repeated Scenario scenarios = 1; -} - -// Basic summary that can be computed from ClientStats and ServerStats -// once the scenario has finished. -message ScenarioResultSummary -{ - // Total number of operations per second over all clients. What is counted as 1 'operation' depends on the benchmark scenarios: - // For unary benchmarks, an operation is processing of a single unary RPC. - // For streaming benchmarks, an operation is processing of a single ping pong of request and response. - double qps = 1; - // QPS per server core. - double qps_per_server_core = 2; - // The total server cpu load based on system time across all server processes, expressed as percentage of a single cpu core. - // For example, 85 implies 85% of a cpu core, 125 implies 125% of a cpu core. Since we are accumulating the cpu load across all the server - // processes, the value could > 100 when there are multiple servers or a single server using multiple threads and cores. - // Same explanation for the total client cpu load below. - double server_system_time = 3; - // The total server cpu load based on user time across all server processes, expressed as percentage of a single cpu core. (85 => 85%, 125 => 125%) - double server_user_time = 4; - // The total client cpu load based on system time across all client processes, expressed as percentage of a single cpu core. (85 => 85%, 125 => 125%) - double client_system_time = 5; - // The total client cpu load based on user time across all client processes, expressed as percentage of a single cpu core. (85 => 85%, 125 => 125%) - double client_user_time = 6; - - // X% latency percentiles (in nanoseconds) - double latency_50 = 7; - double latency_90 = 8; - double latency_95 = 9; - double latency_99 = 10; - double latency_999 = 11; - - // server cpu usage percentage - double server_cpu_usage = 12; - - // Number of requests that succeeded/failed - double successful_requests_per_second = 13; - double failed_requests_per_second = 14; - - // Number of polls called inside completion queue per request - double client_polls_per_request = 15; - double server_polls_per_request = 16; - - // Queries per CPU-sec over all servers or clients - double server_queries_per_cpu_sec = 17; - double client_queries_per_cpu_sec = 18; - - - // Start and end time for the test scenario - google.protobuf.Timestamp start_time = 19; - google.protobuf.Timestamp end_time =20; -} - -// Results of a single benchmark scenario. -message ScenarioResult { - // Inputs used to run the scenario. - Scenario scenario = 1; - // Histograms from all clients merged into one histogram. - HistogramData latencies = 2; - // Client stats for each client - repeated ClientStats client_stats = 3; - // Server stats for each server - repeated ServerStats server_stats = 4; - // Number of cores available to each server - repeated int32 server_cores = 5; - // An after-the-fact computed summary - ScenarioResultSummary summary = 6; - // Information on success or failure of each worker - repeated bool client_success = 7; - repeated bool server_success = 8; - // Number of failed requests (one row per status code seen) - repeated RequestResultCount request_results = 9; -} diff --git a/dev/Protos/upstream/grpc/testing/messages.proto b/dev/Protos/upstream/grpc/testing/messages.proto deleted file mode 100644 index 99e34dcc8..000000000 --- a/dev/Protos/upstream/grpc/testing/messages.proto +++ /dev/null @@ -1,347 +0,0 @@ -// Copyright 2015-2016 gRPC 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. - -// Message definitions to be used by integration test service definitions. - -syntax = "proto3"; - -package grpc.testing; - -option java_package = "io.grpc.testing.integration"; - -// TODO(dgq): Go back to using well-known types once -// https://github.com/grpc/grpc/issues/6980 has been fixed. -// import "google/protobuf/wrappers.proto"; -message BoolValue { - // The bool value. - bool value = 1; -} - -// The type of payload that should be returned. -enum PayloadType { - // Compressable text format. - COMPRESSABLE = 0; -} - -// A block of data, to simply increase gRPC message size. -message Payload { - // The type of data in body. - PayloadType type = 1; - // Primary contents of payload. - bytes body = 2; -} - -// A protobuf representation for grpc status. This is used by test -// clients to specify a status that the server should attempt to return. -message EchoStatus { - int32 code = 1; - string message = 2; -} - -// The type of route that a client took to reach a server w.r.t. gRPCLB. -// The server must fill in "fallback" if it detects that the RPC reached -// the server via the "gRPCLB fallback" path, and "backend" if it detects -// that the RPC reached the server via "gRPCLB backend" path (i.e. if it got -// the address of this server from the gRPCLB server BalanceLoad RPC). Exactly -// how this detection is done is context and server dependent. -enum GrpclbRouteType { - // Server didn't detect the route that a client took to reach it. - GRPCLB_ROUTE_TYPE_UNKNOWN = 0; - // Indicates that a client reached a server via gRPCLB fallback. - GRPCLB_ROUTE_TYPE_FALLBACK = 1; - // Indicates that a client reached a server as a gRPCLB-given backend. - GRPCLB_ROUTE_TYPE_BACKEND = 2; -} - -// Unary request. -message SimpleRequest { - // Desired payload type in the response from the server. - // If response_type is RANDOM, server randomly chooses one from other formats. - PayloadType response_type = 1; - - // Desired payload size in the response from the server. - int32 response_size = 2; - - // Optional input payload sent along with the request. - Payload payload = 3; - - // Whether SimpleResponse should include username. - bool fill_username = 4; - - // Whether SimpleResponse should include OAuth scope. - bool fill_oauth_scope = 5; - - // Whether to request the server to compress the response. This field is - // "nullable" in order to interoperate seamlessly with clients not able to - // implement the full compression tests by introspecting the call to verify - // the response's compression status. - BoolValue response_compressed = 6; - - // Whether server should return a given status - EchoStatus response_status = 7; - - // Whether the server should expect this request to be compressed. - BoolValue expect_compressed = 8; - - // Whether SimpleResponse should include server_id. - bool fill_server_id = 9; - - // Whether SimpleResponse should include grpclb_route_type. - bool fill_grpclb_route_type = 10; - - // If set the server should record this metrics report data for the current RPC. - TestOrcaReport orca_per_query_report = 11; -} - -// Unary response, as configured by the request. -message SimpleResponse { - // Payload to increase message size. - Payload payload = 1; - // The user the request came from, for verifying authentication was - // successful when the client expected it. - string username = 2; - // OAuth scope. - string oauth_scope = 3; - - // Server ID. This must be unique among different server instances, - // but the same across all RPC's made to a particular server instance. - string server_id = 4; - // gRPCLB Path. - GrpclbRouteType grpclb_route_type = 5; - - // Server hostname. - string hostname = 6; -} - -// Client-streaming request. -message StreamingInputCallRequest { - // Optional input payload sent along with the request. - Payload payload = 1; - - // Whether the server should expect this request to be compressed. This field - // is "nullable" in order to interoperate seamlessly with servers not able to - // implement the full compression tests by introspecting the call to verify - // the request's compression status. - BoolValue expect_compressed = 2; - - // Not expecting any payload from the response. -} - -// Client-streaming response. -message StreamingInputCallResponse { - // Aggregated size of payloads received from the client. - int32 aggregated_payload_size = 1; -} - -// Configuration for a particular response. -message ResponseParameters { - // Desired payload sizes in responses from the server. - int32 size = 1; - - // Desired interval between consecutive responses in the response stream in - // microseconds. - int32 interval_us = 2; - - // Whether to request the server to compress the response. This field is - // "nullable" in order to interoperate seamlessly with clients not able to - // implement the full compression tests by introspecting the call to verify - // the response's compression status. - BoolValue compressed = 3; -} - -// Server-streaming request. -message StreamingOutputCallRequest { - // Desired payload type in the response from the server. - // If response_type is RANDOM, the payload from each response in the stream - // might be of different types. This is to simulate a mixed type of payload - // stream. - PayloadType response_type = 1; - - // Configuration for each expected response message. - repeated ResponseParameters response_parameters = 2; - - // Optional input payload sent along with the request. - Payload payload = 3; - - // Whether server should return a given status - EchoStatus response_status = 7; - - // If set the server should update this metrics report data at the OOB server. - TestOrcaReport orca_oob_report = 8; -} - -// Server-streaming response, as configured by the request and parameters. -message StreamingOutputCallResponse { - // Payload to increase response size. - Payload payload = 1; -} - -// For reconnect interop test only. -// Client tells server what reconnection parameters it used. -message ReconnectParams { - int32 max_reconnect_backoff_ms = 1; -} - -// For reconnect interop test only. -// Server tells client whether its reconnects are following the spec and the -// reconnect backoffs it saw. -message ReconnectInfo { - bool passed = 1; - repeated int32 backoff_ms = 2; -} - -message LoadBalancerStatsRequest { - // Request stats for the next num_rpcs sent by client. - int32 num_rpcs = 1; - // If num_rpcs have not completed within timeout_sec, return partial results. - int32 timeout_sec = 2; - // Response header + trailer metadata entries we want the values of. - // Matching of the keys is case-insensitive as per rfc7540#section-8.1.2 - // * (asterisk) is a special value that will return all metadata entries - repeated string metadata_keys = 3; -} - -message LoadBalancerStatsResponse { - enum MetadataType { - UNKNOWN = 0; - INITIAL = 1; - TRAILING = 2; - } - message MetadataEntry { - // Key, exactly as received from the server. Case may be different from what - // was requested in the LoadBalancerStatsRequest) - string key = 1; - // Value, exactly as received from the server. - string value = 2; - // Metadata type - MetadataType type = 3; - } - message RpcMetadata { - // metadata values for each rpc for the keys specified in - // LoadBalancerStatsRequest.metadata_keys. - repeated MetadataEntry metadata = 1; - } - message MetadataByPeer { - // List of RpcMetadata in for each RPC with a given peer - repeated RpcMetadata rpc_metadata = 1; - } - message RpcsByPeer { - // The number of completed RPCs for each peer. - map rpcs_by_peer = 1; - } - // The number of completed RPCs for each peer. - map rpcs_by_peer = 1; - // The number of RPCs that failed to record a remote peer. - int32 num_failures = 2; - map rpcs_by_method = 3; - // All the metadata of all RPCs for each peer. - map metadatas_by_peer = 4; -} - -// Request for retrieving a test client's accumulated stats. -message LoadBalancerAccumulatedStatsRequest {} - -// Accumulated stats for RPCs sent by a test client. -message LoadBalancerAccumulatedStatsResponse { - // The total number of RPCs have ever issued for each type. - // Deprecated: use stats_per_method.rpcs_started instead. - map num_rpcs_started_by_method = 1 [deprecated = true]; - // The total number of RPCs have ever completed successfully for each type. - // Deprecated: use stats_per_method.result instead. - map num_rpcs_succeeded_by_method = 2 [deprecated = true]; - // The total number of RPCs have ever failed for each type. - // Deprecated: use stats_per_method.result instead. - map num_rpcs_failed_by_method = 3 [deprecated = true]; - - message MethodStats { - // The number of RPCs that were started for this method. - int32 rpcs_started = 1; - - // The number of RPCs that completed with each status for this method. The - // key is the integral value of a google.rpc.Code; the value is the count. - map result = 2; - } - - // Per-method RPC statistics. The key is the RpcType in string form; e.g. - // 'EMPTY_CALL' or 'UNARY_CALL' - map stats_per_method = 4; -} - -// Configurations for a test client. -message ClientConfigureRequest { - // Type of RPCs to send. - enum RpcType { - EMPTY_CALL = 0; - UNARY_CALL = 1; - } - - // Metadata to be attached for the given type of RPCs. - message Metadata { - RpcType type = 1; - string key = 2; - string value = 3; - } - - // The types of RPCs the client sends. - repeated RpcType types = 1; - // The collection of custom metadata to be attached to RPCs sent by the client. - repeated Metadata metadata = 2; - // The deadline to use, in seconds, for all RPCs. If unset or zero, the - // client will use the default from the command-line. - int32 timeout_sec = 3; -} - -// Response for updating a test client's configuration. -message ClientConfigureResponse {} - -message MemorySize { - int64 rss = 1; -} - -// Metrics data the server will update and send to the client. It mirrors orca load report -// https://github.com/cncf/xds/blob/eded343319d09f30032952beda9840bbd3dcf7ac/xds/data/orca/v3/orca_load_report.proto#L15, -// but avoids orca dependency. Used by both per-query and out-of-band reporting tests. -message TestOrcaReport { - double cpu_utilization = 1; - double memory_utilization = 2; - map request_cost = 3; - map utilization = 4; -} - -// Status that will be return to callers of the Hook method -message SetReturnStatusRequest { - int32 grpc_code_to_return = 1; - string grpc_status_description = 2; -} - -message HookRequest { - enum HookRequestCommand { - // Default value - UNSPECIFIED = 0; - // Start the HTTP endpoint - START = 1; - // Stop - STOP = 2; - // Return from HTTP GET/POST - RETURN = 3; - } - HookRequestCommand command = 1; - int32 grpc_code_to_return = 2; - string grpc_status_description = 3; - // Server port to listen to - int32 server_port = 4; -} - -message HookResponse { -} diff --git a/dev/Protos/upstream/grpc/testing/payloads.proto b/dev/Protos/upstream/grpc/testing/payloads.proto deleted file mode 100644 index 8cbc9db6c..000000000 --- a/dev/Protos/upstream/grpc/testing/payloads.proto +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2015 gRPC 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. - -syntax = "proto3"; - -package grpc.testing; - -option java_multiple_files = true; -option java_package = "io.grpc.testing"; -option java_outer_classname = "PayloadsProto"; - -message ByteBufferParams { - int32 req_size = 1; - int32 resp_size = 2; -} - -message SimpleProtoParams { - int32 req_size = 1; - int32 resp_size = 2; -} - -message ComplexProtoParams { - // TODO (vpai): Fill this in once the details of complex, representative - // protos are decided -} - -message PayloadConfig { - oneof payload { - ByteBufferParams bytebuf_params = 1; - SimpleProtoParams simple_params = 2; - ComplexProtoParams complex_params = 3; - } -} diff --git a/dev/Protos/upstream/grpc/testing/stats.proto b/dev/Protos/upstream/grpc/testing/stats.proto deleted file mode 100644 index 1f0fae4e5..000000000 --- a/dev/Protos/upstream/grpc/testing/stats.proto +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2015 gRPC 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. - -syntax = "proto3"; - -package grpc.testing; - -import "grpc/core/stats.proto"; - -option java_multiple_files = true; -option java_package = "io.grpc.testing"; -option java_outer_classname = "StatsProto"; - -message ServerStats { - // wall clock time change in seconds since last reset - double time_elapsed = 1; - - // change in user time (in seconds) used by the server since last reset - double time_user = 2; - - // change in server time (in seconds) used by the server process and all - // threads since last reset - double time_system = 3; - - // change in total cpu time of the server (data from proc/stat) - uint64 total_cpu_time = 4; - - // change in idle time of the server (data from proc/stat) - uint64 idle_cpu_time = 5; - - // Number of polls called inside completion queue - uint64 cq_poll_count = 6; - - // Core library stats - grpc.core.Stats core_stats = 7; -} - -// Histogram params based on grpc/support/histogram.c -message HistogramParams { - double resolution = 1; // first bucket is [0, 1 + resolution) - double max_possible = 2; // use enough buckets to allow this value -} - -// Histogram data based on grpc/support/histogram.c -message HistogramData { - repeated uint32 bucket = 1; - double min_seen = 2; - double max_seen = 3; - double sum = 4; - double sum_of_squares = 5; - double count = 6; -} - -message RequestResultCount { - int32 status_code = 1; - int64 count = 2; -} - -message ClientStats { - // Latency histogram. Data points are in nanoseconds. - HistogramData latencies = 1; - - // See ServerStats for details. - double time_elapsed = 2; - double time_user = 3; - double time_system = 4; - - // Number of failed requests (one row per status code seen) - repeated RequestResultCount request_results = 5; - - // Number of polls called inside completion queue - uint64 cq_poll_count = 6; - - // Core library stats - grpc.core.Stats core_stats = 7; -} diff --git a/dev/Protos/upstream/grpc/testing/worker_service.proto b/dev/Protos/upstream/grpc/testing/worker_service.proto deleted file mode 100644 index ff3aa2931..000000000 --- a/dev/Protos/upstream/grpc/testing/worker_service.proto +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2015 gRPC 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. - -// An integration test service that covers all the method signature permutations -// of unary/streaming requests/responses. -syntax = "proto3"; - -import "grpc/testing/control.proto"; - -package grpc.testing; - -option java_multiple_files = true; -option java_package = "io.grpc.testing"; -option java_outer_classname = "WorkerServiceProto"; - -service WorkerService { - // Start server with specified workload. - // First request sent specifies the ServerConfig followed by ServerStatus - // response. After that, a "Mark" can be sent anytime to request the latest - // stats. Closing the stream will initiate shutdown of the test server - // and once the shutdown has finished, the OK status is sent to terminate - // this RPC. - rpc RunServer(stream ServerArgs) returns (stream ServerStatus); - - // Start client with specified workload. - // First request sent specifies the ClientConfig followed by ClientStatus - // response. After that, a "Mark" can be sent anytime to request the latest - // stats. Closing the stream will initiate shutdown of the test client - // and once the shutdown has finished, the OK status is sent to terminate - // this RPC. - rpc RunClient(stream ClientArgs) returns (stream ClientStatus); - - // Just return the core count - unary call - rpc CoreCount(CoreRequest) returns (CoreResponse); - - // Quit this worker - rpc QuitWorker(Void) returns (Void); -} diff --git a/dev/check-generated-code.sh b/dev/check-generated-code.sh index 8e1ef7ce7..67bc71b8e 100755 --- a/dev/check-generated-code.sh +++ b/dev/check-generated-code.sh @@ -24,7 +24,7 @@ here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # Re-generate everything. log "Regenerating protos..." -"$here"/Protos/generate.sh +"$here"/protos/generate.sh # Check for changes. GIT_PAGER='' git diff --exit-code '*.swift' diff --git a/dev/Protos/README.md b/dev/protos/README.md similarity index 100% rename from dev/Protos/README.md rename to dev/protos/README.md diff --git a/dev/Protos/examples/echo/echo.proto b/dev/protos/examples/echo/echo.proto similarity index 99% rename from dev/Protos/examples/echo/echo.proto rename to dev/protos/examples/echo/echo.proto index 7de1534ac..cfba875db 100644 --- a/dev/Protos/examples/echo/echo.proto +++ b/dev/protos/examples/echo/echo.proto @@ -38,4 +38,4 @@ message EchoRequest { message EchoResponse { // The text of an echo response. string text = 1; -} +} \ No newline at end of file diff --git a/dev/Protos/examples/route_guide/route_guide.proto b/dev/protos/examples/route_guide/route_guide.proto similarity index 100% rename from dev/Protos/examples/route_guide/route_guide.proto rename to dev/protos/examples/route_guide/route_guide.proto diff --git a/dev/Protos/fetch.sh b/dev/protos/fetch.sh similarity index 100% rename from dev/Protos/fetch.sh rename to dev/protos/fetch.sh diff --git a/dev/Protos/generate.sh b/dev/protos/generate.sh similarity index 100% rename from dev/Protos/generate.sh rename to dev/protos/generate.sh diff --git a/dev/Protos/upstream/google/rpc/code.proto b/dev/protos/upstream/google/rpc/code.proto similarity index 100% rename from dev/Protos/upstream/google/rpc/code.proto rename to dev/protos/upstream/google/rpc/code.proto diff --git a/dev/Protos/upstream/grpc/examples/helloworld.proto b/dev/protos/upstream/grpc/examples/helloworld.proto similarity index 100% rename from dev/Protos/upstream/grpc/examples/helloworld.proto rename to dev/protos/upstream/grpc/examples/helloworld.proto diff --git a/dev/Protos/upstream/grpc/lookup/v1/rls.proto b/dev/protos/upstream/grpc/lookup/v1/rls.proto similarity index 100% rename from dev/Protos/upstream/grpc/lookup/v1/rls.proto rename to dev/protos/upstream/grpc/lookup/v1/rls.proto diff --git a/dev/Protos/upstream/grpc/lookup/v1/rls_config.proto b/dev/protos/upstream/grpc/lookup/v1/rls_config.proto similarity index 99% rename from dev/Protos/upstream/grpc/lookup/v1/rls_config.proto rename to dev/protos/upstream/grpc/lookup/v1/rls_config.proto index 9d2b6c54c..9762be752 100644 --- a/dev/Protos/upstream/grpc/lookup/v1/rls_config.proto +++ b/dev/protos/upstream/grpc/lookup/v1/rls_config.proto @@ -159,6 +159,9 @@ message HttpKeyBuilder { // for example if you are suppressing a lot of information from the URL, but // need to separately cache and request URLs with that content. map constant_keys = 5; + + // If specified, the HTTP method/verb will be extracted under this key name. + string method = 6; } message RouteLookupConfig { diff --git a/dev/Protos/upstream/grpc/service_config/service_config.proto b/dev/protos/upstream/grpc/service_config/service_config.proto similarity index 100% rename from dev/Protos/upstream/grpc/service_config/service_config.proto rename to dev/protos/upstream/grpc/service_config/service_config.proto From 05eb510975413bfdbb9b24b38c1ac7aeebec8c3d Mon Sep 17 00:00:00 2001 From: George Barnett Date: Mon, 23 Sep 2024 10:02:27 +0100 Subject: [PATCH 3/5] Use stringified version --- Examples/echo/Package.swift | 2 +- Examples/hello-world/Package.swift | 2 +- Examples/route-guide/Package.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Examples/echo/Package.swift b/Examples/echo/Package.swift index 4070fa1fe..d9769fb16 100644 --- a/Examples/echo/Package.swift +++ b/Examples/echo/Package.swift @@ -19,7 +19,7 @@ import PackageDescription let package = Package( name: "echo", - platforms: [.macOS(.v15)], + platforms: [.macOS("15.0")], dependencies: [ .package(url: "https://github.com/grpc/grpc-swift-protobuf", branch: "main"), .package(url: "https://github.com/grpc/grpc-swift-nio-transport", branch: "main"), diff --git a/Examples/hello-world/Package.swift b/Examples/hello-world/Package.swift index 2c207cb83..94c96c027 100644 --- a/Examples/hello-world/Package.swift +++ b/Examples/hello-world/Package.swift @@ -19,7 +19,7 @@ import PackageDescription let package = Package( name: "hello-world", - platforms: [.macOS(.v15)], + platforms: [.macOS("15.0")], dependencies: [ .package(url: "https://github.com/grpc/grpc-swift-protobuf", branch: "main"), .package(url: "https://github.com/grpc/grpc-swift-nio-transport", branch: "main"), diff --git a/Examples/route-guide/Package.swift b/Examples/route-guide/Package.swift index ce45593cf..baf6d2162 100644 --- a/Examples/route-guide/Package.swift +++ b/Examples/route-guide/Package.swift @@ -19,7 +19,7 @@ import PackageDescription let package = Package( name: "route-guide", - platforms: [.macOS(.v15)], + platforms: [.macOS("15.0")], dependencies: [ .package(url: "https://github.com/grpc/grpc-swift-protobuf", branch: "main"), .package(url: "https://github.com/grpc/grpc-swift-nio-transport", branch: "main"), From 2df5548ea83ee4e559a2307279ab2c08611aab27 Mon Sep 17 00:00:00 2001 From: George Barnett Date: Mon, 23 Sep 2024 13:44:39 +0100 Subject: [PATCH 4/5] fixup ci --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 248d19ba4..05a329f30 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -67,6 +67,7 @@ jobs: timeout-minutes: 20 examples: strategy: + fail-fast: false matrix: include: - image: swiftlang/swift:nightly-jammy From eaaf31568b72fe11c3596a92af2306d16db015f4 Mon Sep 17 00:00:00 2001 From: George Barnett Date: Tue, 24 Sep 2024 11:07:10 +0100 Subject: [PATCH 5/5] Update Examples/route-guide/README.md Co-authored-by: Gus Cairo --- Examples/route-guide/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/route-guide/README.md b/Examples/route-guide/README.md index a1c0a282a..d19a53c87 100644 --- a/Examples/route-guide/README.md +++ b/Examples/route-guide/README.md @@ -5,7 +5,7 @@ client. ## Overview -A "rouge-guide" command line tool that uses generated stubs for an 'Route Guide' +A "route-guide" command line tool that uses generated stubs for a 'Route Guide' service allows you to start a server and to make requests against it for each of the four RPC types.