Co-authored-by: Gorbunov Kirill Andreevich <kgorbunov@mtsbank.ru> Reviewed-on: #5 Co-authored-by: Кирилл Горбунов <kirya_gorbunov_2015@mail.ru> Co-committed-by: Кирилл Горбунов <kirya_gorbunov_2015@mail.ru>
This commit is contained in:
@@ -29,11 +29,8 @@ import (
|
||||
"go.unistack.org/servicechecker/pkg/config"
|
||||
"go.unistack.org/servicechecker/pkg/grpcconn"
|
||||
"go.unistack.org/servicechecker/pkg/httpconn"
|
||||
"go.unistack.org/servicechecker/pkg/protoset"
|
||||
"go.unistack.org/servicechecker/pkg/scheduler"
|
||||
"google.golang.org/protobuf/reflect/protodesc"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/types/descriptorpb"
|
||||
"google.golang.org/protobuf/types/dynamicpb"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -131,7 +128,7 @@ func main() {
|
||||
client.Codec("application/grpc+json", jsonpbcodec.NewCodec()),
|
||||
client.ContentType("application/grpc"),
|
||||
client.Retries(0),
|
||||
// client.TLSConfig(&tls.Config{InsecureSkipVerify: true}),
|
||||
// client.TLSConfig(&tls.Config{InsecureSkipVerify: true}),
|
||||
)
|
||||
if err = gcli.Init(); err != nil {
|
||||
l.Fatal(ctx, "failed to init grpc client", err)
|
||||
@@ -144,7 +141,7 @@ func main() {
|
||||
client.Codec("application/json", jsonpbcodec.NewCodec()),
|
||||
client.ContentType("application/json"),
|
||||
client.Retries(0),
|
||||
// client.TLSConfig(&tls.Config{InsecureSkipVerify: true}),
|
||||
// client.TLSConfig(&tls.Config{InsecureSkipVerify: true}),
|
||||
)
|
||||
if err = hcli.Init(); err != nil {
|
||||
l.Fatal(ctx, "failed to init http client", err)
|
||||
@@ -307,51 +304,28 @@ func newGRPCTask(ctx context.Context, l logger.Logger, m meter.Meter, check stri
|
||||
var rsp interface{}
|
||||
var treq client.Request
|
||||
var labels []string
|
||||
p := protoset.NewProtoSet()
|
||||
|
||||
if task.GRPC.Protoset != "" {
|
||||
pkg, svc, mth := grpcconn.ServiceMethod(task.GRPC.Endpoint)
|
||||
|
||||
protosetBuf, err := os.ReadFile(task.GRPC.Protoset)
|
||||
if err != nil {
|
||||
l.Error(ctx, "failed to unmarshal protoset file", err)
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
fdset := &descriptorpb.FileDescriptorSet{}
|
||||
if err = protocodec.NewCodec().Unmarshal(protosetBuf, fdset); err != nil {
|
||||
l.Error(ctx, "failed to unmarshal protoset file", err)
|
||||
if err = p.AddProtoset(task.GRPC.Addr, svc, protosetBuf); err != nil {
|
||||
l.Error(ctx, "failed add protoset", err)
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
pfileoptions := protodesc.FileOptions{AllowUnresolvable: true}
|
||||
pfiles, err := pfileoptions.NewFiles(fdset)
|
||||
req, rsp, err = p.GetMessage(task.GRPC.Addr, pkg, svc, mth)
|
||||
if err != nil {
|
||||
l.Error(ctx, "failed to use protoset file", err)
|
||||
l.Error(ctx, "failed get req, rsp from protoset", err)
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
pkg, svc, mth := grpcconn.ServiceMethod(task.GRPC.Endpoint)
|
||||
pdesc, err := pfiles.FindDescriptorByName(protoreflect.FullName(pkg + "." + svc))
|
||||
if err != nil {
|
||||
l.Error(ctx, "failed to find service "+pkg+"."+svc)
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
sdesc, ok := pdesc.(protoreflect.ServiceDescriptor)
|
||||
if !ok {
|
||||
err = fmt.Errorf("failed to find service " + pkg + "." + svc)
|
||||
l.Error(ctx, "unable to find service in protoset", err)
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
mdesc := sdesc.Methods().ByName(protoreflect.Name(mth))
|
||||
if mdesc == nil {
|
||||
err = fmt.Errorf("unknown method " + mth)
|
||||
l.Error(ctx, "failed to find method", err)
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
req = dynamicpb.NewMessageType(mdesc.Input()).New()
|
||||
rsp = dynamicpb.NewMessageType(mdesc.Output()).New()
|
||||
|
||||
if err = jsonpbcodec.NewCodec().Unmarshal([]byte(task.GRPC.Data), req); err != nil {
|
||||
l.Error(ctx, "failed to unmarshal", err)
|
||||
return nil, nil, err
|
||||
|
Reference in New Issue
Block a user