chore(grpc): add health check and grpc v1, alpha version

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi.Wu 2022-08-20 11:53:19 +08:00 committed by Jason Song
parent 257ba77e8d
commit 2cba8fafd8
6 changed files with 65 additions and 46 deletions

View File

@ -15,4 +15,8 @@ func Routes(r *web.Route) {
runnerServiceRoute(r)
// ping service
pingServiceRoute(r)
// health service
healthServiceRoute(r)
// grpcv1 and v1alpha service
grpcServiceRoute(r)
}

32
routers/api/bots/grpc.go Normal file
View File

@ -0,0 +1,32 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package bots
import (
"code.gitea.io/gitea/modules/web"
"gitea.com/gitea/proto-go/ping/v1/pingv1connect"
"github.com/bufbuild/connect-go"
grpcreflect "github.com/bufbuild/connect-grpcreflect-go"
)
func grpcServiceRoute(r *web.Route) {
compress1KB := connect.WithCompressMinBytes(1024)
// grpcV1
grpcPath, gHandler := grpcreflect.NewHandlerV1(
grpcreflect.NewStaticReflector(pingv1connect.PingServiceName),
compress1KB,
)
// grpcV1Alpha
grpcAlphaPath, gAlphaHandler := grpcreflect.NewHandlerV1Alpha(
grpcreflect.NewStaticReflector(pingv1connect.PingServiceName),
compress1KB,
)
r.Post(grpcPath+"{name}", grpcHandler(gHandler))
r.Post(grpcAlphaPath+"{name}", grpcHandler(gAlphaHandler))
}

View File

@ -0,0 +1,29 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package bots
import (
"code.gitea.io/gitea/modules/web"
"gitea.com/gitea/proto-go/ping/v1/pingv1connect"
"gitea.com/gitea/proto-go/runner/v1/runnerv1connect"
"github.com/bufbuild/connect-go"
grpchealth "github.com/bufbuild/connect-grpchealth-go"
)
func healthServiceRoute(r *web.Route) {
compress1KB := connect.WithCompressMinBytes(1024)
// grpcHealthCheck
grpcHealthPath, gHealthHandler := grpchealth.NewHandler(
grpchealth.NewStaticChecker(
runnerv1connect.RunnerServiceName,
pingv1connect.PingServiceName,
),
compress1KB,
)
r.Post(grpcHealthPath+"{name}", grpcHandler(gHealthHandler))
}

View File

@ -14,8 +14,6 @@ import (
"gitea.com/gitea/proto-go/ping/v1/pingv1connect"
"github.com/bufbuild/connect-go"
grpchealth "github.com/bufbuild/connect-grpchealth-go"
grpcreflect "github.com/bufbuild/connect-grpcreflect-go"
)
type PingService struct{}
@ -43,26 +41,5 @@ func pingServiceRoute(r *web.Route) {
compress1KB,
)
// grpcV1
grpcPath, gHandler := grpcreflect.NewHandlerV1(
grpcreflect.NewStaticReflector(pingv1connect.PingServiceName),
compress1KB,
)
// grpcV1Alpha
grpcAlphaPath, gAlphaHandler := grpcreflect.NewHandlerV1Alpha(
grpcreflect.NewStaticReflector(pingv1connect.PingServiceName),
compress1KB,
)
// grpcHealthCheck
grpcHealthPath, gHealthHandler := grpchealth.NewHandler(
grpchealth.NewStaticChecker(pingv1connect.PingServiceName),
compress1KB,
)
r.Post(connectPath+"{name}", grpcHandler(connecthandler))
r.Post(grpcPath+"{name}", grpcHandler(gHandler))
r.Post(grpcAlphaPath+"{name}", grpcHandler(gAlphaHandler))
r.Post(grpcHealthPath+"{name}", grpcHandler(gHealthHandler))
}

View File

@ -13,8 +13,6 @@ import (
"gitea.com/gitea/proto-go/runner/v1/runnerv1connect"
"github.com/bufbuild/connect-go"
grpchealth "github.com/bufbuild/connect-grpchealth-go"
grpcreflect "github.com/bufbuild/connect-grpcreflect-go"
)
type RunnerService struct{}
@ -55,26 +53,5 @@ func runnerServiceRoute(r *web.Route) {
compress1KB,
)
// grpcV1
grpcPath, gHandler := grpcreflect.NewHandlerV1(
grpcreflect.NewStaticReflector(runnerv1connect.RunnerServiceName),
compress1KB,
)
// grpcV1Alpha
grpcAlphaPath, gAlphaHandler := grpcreflect.NewHandlerV1Alpha(
grpcreflect.NewStaticReflector(runnerv1connect.RunnerServiceName),
compress1KB,
)
// grpcHealthCheck
grpcHealthPath, gHealthHandler := grpchealth.NewHandler(
grpchealth.NewStaticChecker(runnerv1connect.RunnerServiceName),
compress1KB,
)
r.Post(connectPath+"{name}", grpcHandler(connecthandler))
r.Post(grpcPath+"{name}", grpcHandler(gHandler))
r.Post(grpcAlphaPath+"{name}", grpcHandler(gAlphaHandler))
r.Post(grpcHealthPath+"{name}", grpcHandler(gHealthHandler))
}