rework
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
1bba83e6fc
commit
09c107ac3e
@ -159,6 +159,21 @@ func main() {
|
|||||||
func newHTTPTask(ctx context.Context, l logger.Logger, m meter.Meter, check string, task *config.Task) (any, []any, error) {
|
func newHTTPTask(ctx context.Context, l logger.Logger, m meter.Meter, check string, task *config.Task) (any, []any, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
c, ok := clients["http"]
|
||||||
|
if !ok {
|
||||||
|
err = fmt.Errorf("unknown client http")
|
||||||
|
l.Error(ctx, "failed to get client", err)
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var req interface{}
|
||||||
|
var rsp interface{}
|
||||||
|
var treq client.Request
|
||||||
|
var opts []client.CallOption
|
||||||
|
var labels []string
|
||||||
|
|
||||||
|
if task.HTTP.OpenAPI != "" {
|
||||||
|
|
||||||
openapiBuf, err := os.ReadFile(task.HTTP.OpenAPI)
|
openapiBuf, err := os.ReadFile(task.HTTP.OpenAPI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Error(ctx, "failed to unmarshal openapi file", err)
|
l.Error(ctx, "failed to unmarshal openapi file", err)
|
||||||
@ -172,30 +187,27 @@ func newHTTPTask(ctx context.Context, l logger.Logger, m meter.Meter, check stri
|
|||||||
}
|
}
|
||||||
_ = doc
|
_ = doc
|
||||||
|
|
||||||
c, ok := clients["http"]
|
|
||||||
if !ok {
|
|
||||||
err = fmt.Errorf("unknown client http")
|
|
||||||
l.Error(ctx, "failed to get client", err)
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
errmap := make(map[string]interface{}, 1)
|
errmap := make(map[string]interface{}, 1)
|
||||||
errmap["default"] = &codecpb.Frame{}
|
errmap["default"] = &codecpb.Frame{}
|
||||||
opts := []client.CallOption{
|
opts = []client.CallOption{
|
||||||
httpcli.ErrorMap(errmap),
|
httpcli.ErrorMap(errmap),
|
||||||
httpcli.Method(task.HTTP.Method),
|
httpcli.Method(task.HTTP.Method),
|
||||||
httpcli.Path(task.HTTP.Endpoint),
|
httpcli.Path(task.HTTP.Endpoint),
|
||||||
// client.WithContentType("application/json"),
|
// client.WithContentType("application/json"),
|
||||||
}
|
}
|
||||||
rsp := &codecpb.Frame{}
|
|
||||||
|
|
||||||
treq := c.NewRequest(task.Name, task.Name, &codecpb.Frame{Data: []byte(task.HTTP.Data)})
|
req = &codecpb.Frame{Data: []byte(task.HTTP.Data)}
|
||||||
|
rsp = &codecpb.Frame{}
|
||||||
|
|
||||||
|
treq = c.NewRequest(task.Name, task.Name, req)
|
||||||
|
|
||||||
|
labels = []string{"check", check, "task", task.Name, "service", task.Name, "endpoint", task.Name}
|
||||||
|
}
|
||||||
|
|
||||||
fn := func() {
|
fn := func() {
|
||||||
labels := []string{"check", check, "task", task.Name, "service", task.Name, "endpoint", task.Name}
|
|
||||||
m.Counter(semconv.ClientRequestInflight, labels...).Inc()
|
m.Counter(semconv.ClientRequestInflight, labels...).Inc()
|
||||||
ts := time.Now()
|
ts := time.Now()
|
||||||
l.Info(ctx, fmt.Sprintf("try to call %s.%s via %s", task.Name, task.Name, task.HTTP.Addr))
|
// l.Info(ctx, fmt.Sprintf("try to call %s.%s via %s", task.Name, task.Name, task.HTTP.Addr))
|
||||||
err = httpconn.Call(ctx, l, c, task.HTTP.Addr, time.Duration(task.Timeout),
|
err = httpconn.Call(ctx, l, c, task.HTTP.Addr, time.Duration(task.Timeout),
|
||||||
treq,
|
treq,
|
||||||
rsp,
|
rsp,
|
||||||
@ -217,6 +229,19 @@ func newHTTPTask(ctx context.Context, l logger.Logger, m meter.Meter, check stri
|
|||||||
func newGRPCTask(ctx context.Context, l logger.Logger, m meter.Meter, check string, task *config.Task) (any, []any, error) {
|
func newGRPCTask(ctx context.Context, l logger.Logger, m meter.Meter, check string, task *config.Task) (any, []any, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
c, ok := clients["grpc"]
|
||||||
|
if !ok {
|
||||||
|
err = fmt.Errorf("unknown client grpc")
|
||||||
|
l.Error(ctx, "failed to get client", err)
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var req interface{}
|
||||||
|
var rsp interface{}
|
||||||
|
var treq client.Request
|
||||||
|
var labels []string
|
||||||
|
|
||||||
|
if task.GRPC.Protoset != "" {
|
||||||
protosetBuf, err := os.ReadFile(task.GRPC.Protoset)
|
protosetBuf, err := os.ReadFile(task.GRPC.Protoset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Error(ctx, "failed to unmarshal protoset file", err)
|
l.Error(ctx, "failed to unmarshal protoset file", err)
|
||||||
@ -236,13 +261,6 @@ func newGRPCTask(ctx context.Context, l logger.Logger, m meter.Meter, check stri
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
c, ok := clients["grpc"]
|
|
||||||
if !ok {
|
|
||||||
err = fmt.Errorf("unknown client grpc")
|
|
||||||
l.Error(ctx, "failed to get client", err)
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
pkg, svc, mth := grpcconn.ServiceMethod(task.GRPC.Endpoint)
|
pkg, svc, mth := grpcconn.ServiceMethod(task.GRPC.Endpoint)
|
||||||
pdesc, err := pfiles.FindDescriptorByName(protoreflect.FullName(pkg + "." + svc))
|
pdesc, err := pfiles.FindDescriptorByName(protoreflect.FullName(pkg + "." + svc))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -264,21 +282,23 @@ func newGRPCTask(ctx context.Context, l logger.Logger, m meter.Meter, check stri
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
req := dynamicpb.NewMessageType(mdesc.Input()).New()
|
req = dynamicpb.NewMessageType(mdesc.Input()).New()
|
||||||
rsp := dynamicpb.NewMessageType(mdesc.Output()).New()
|
rsp = dynamicpb.NewMessageType(mdesc.Output()).New()
|
||||||
|
|
||||||
if err = jsonpbcodec.NewCodec().Unmarshal([]byte(task.GRPC.Data), req); err != nil {
|
if err = jsonpbcodec.NewCodec().Unmarshal([]byte(task.GRPC.Data), req); err != nil {
|
||||||
l.Error(ctx, "failed to unmarshal", err)
|
l.Error(ctx, "failed to unmarshal", err)
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
treq := c.NewRequest(pkg, svc+"."+mth, req)
|
treq = c.NewRequest(pkg, svc+"."+mth, req)
|
||||||
|
|
||||||
|
labels = []string{"check", check, "task", task.Name, "service", svc, "endpoint", mth}
|
||||||
|
}
|
||||||
|
|
||||||
fn := func() {
|
fn := func() {
|
||||||
labels := []string{"check", check, "task", task.Name, "service", svc, "endpoint", mth}
|
|
||||||
m.Counter(semconv.ClientRequestInflight, labels...).Inc()
|
m.Counter(semconv.ClientRequestInflight, labels...).Inc()
|
||||||
ts := time.Now()
|
ts := time.Now()
|
||||||
l.Info(ctx, fmt.Sprintf("try to call %s.%s via %s", svc, mth, task.GRPC.Addr))
|
|
||||||
err = grpcconn.Call(ctx, l, c, task.GRPC.Addr, time.Duration(task.Timeout),
|
err = grpcconn.Call(ctx, l, c, task.GRPC.Addr, time.Duration(task.Timeout),
|
||||||
treq,
|
treq,
|
||||||
rsp)
|
rsp)
|
||||||
|
Loading…
Reference in New Issue
Block a user