mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-22 13:25:21 +02:00
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:
parent
257ba77e8d
commit
2cba8fafd8
@ -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
32
routers/api/bots/grpc.go
Normal 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))
|
||||
}
|
29
routers/api/bots/health.go
Normal file
29
routers/api/bots/health.go
Normal 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))
|
||||
}
|
@ -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))
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user