Skip to content

Commit

Permalink
Health checks
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyzimarev committed Aug 4, 2023
1 parent a96c6f9 commit 61da412
Show file tree
Hide file tree
Showing 43 changed files with 730 additions and 270 deletions.
8 changes: 3 additions & 5 deletions samples/GrpcProjector/GrpcProjector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
</PropertyGroup>
</Target>
<ItemGroup>
<PackageReference Include="MinVer" Version="4.3.0" PrivateAssets="All"/>
<PackageReference Include="Microsoft.NET.Build.Containers" Version="7.0.302"/>
<PackageReference Include="Microsoft.AspNetCore.Grpc.Swagger" Version="0.3.9" />
<PackageReference Include="Serilog" Version="2.12.0"/>
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0"/>
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0"/>
<PackageReference Include="Microsoft.AspNetCore.Grpc.JsonTranscoding" Version="7.0.9" />
<PackageReference Include="Grpc.AspNetCore" Version="2.49.0"/>
</ItemGroup>
<ItemGroup>
<Protobuf Include="Protos\server.proto" GrpcServices="Server"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Grpc.AspNetCore" Version="2.49.0"/>
</ItemGroup>
</Project>
16 changes: 15 additions & 1 deletion samples/GrpcProjector/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using GrpcProjector.Services;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.OpenApi.Models;
using Serilog;
using Serilog.Events;

Expand All @@ -19,10 +20,23 @@
builder.Host.UseSerilog();

builder.Services.AddGrpc();
builder.Services.AddGrpcSwagger();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1",
new OpenApiInfo { Title = "gRPC transcoding", Version = "v1" });
});

if (builder.Environment.IsDevelopment()) { builder.WebHost.ConfigureKestrel(options => options.ListenLocalhost(9091, o => o.Protocols = HttpProtocols.Http2)); }
if (builder.Environment.IsDevelopment()) {
builder.WebHost.ConfigureKestrel(options => options.ListenLocalhost(9091, o => o.Protocols = HttpProtocols.Http1AndHttp2));
}

var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
app.MapGrpcService<ProjectorService>();
app.MapGet("/", () => "Communication with gRPC endpoints must be made through a gRPC client");

Expand Down
7 changes: 6 additions & 1 deletion samples/GrpcProjector/Protos/server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ syntax = "proto3";
package grpc_projection;
option csharp_namespace = "GrpcProjector";
import "google/protobuf/struct.proto";
import "google/api/annotations.proto";

service Projection {
rpc Project (ProjectRequest) returns (ProjectResponse);
rpc GetCheckpoint (GetCheckpointRequest) returns (GetCheckpointResponse);
rpc GetCheckpoint (GetCheckpointRequest) returns (GetCheckpointResponse) {
option (google.api.http) = {
get: "/v1/checkpoint/{checkpointId}"
};
};
rpc StoreCheckpoint (StoreCheckpointRequest) returns (StoreCheckpointResponse);
}

Expand Down
2 changes: 1 addition & 1 deletion samples/GrpcProjector/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"AllowedHosts": "*",
"Kestrel": {
"EndpointDefaults": {
"Protocols": "Http2"
"Protocols": "Http1AndHttp2"
}
}
}
31 changes: 31 additions & 0 deletions samples/GrpcProjector/google/api/annotations.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2015, Google Inc.
//
// 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 google.api;

import "google/api/http.proto";
import "google/protobuf/descriptor.proto";

option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations";
option java_multiple_files = true;
option java_outer_classname = "AnnotationsProto";
option java_package = "com.google.api";
option objc_class_prefix = "GAPI";

extend google.protobuf.MethodOptions {
// See `HttpRule`.
HttpRule http = 72295728;
}
Loading

0 comments on commit 61da412

Please sign in to comment.