improve config
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
26ddc88547
commit
f7127198d6
@ -117,13 +117,14 @@ func main() {
|
|||||||
l.Info(ctx, fmt.Sprintf("check %#+v", check))
|
l.Info(ctx, fmt.Sprintf("check %#+v", check))
|
||||||
for _, task := range check.Tasks {
|
for _, task := range check.Tasks {
|
||||||
l.Info(ctx, fmt.Sprintf("task %#+v", task))
|
l.Info(ctx, fmt.Sprintf("task %#+v", task))
|
||||||
c, ok := clients[task.Type]
|
if task.GRPC != nil {
|
||||||
|
c, ok := clients["grpc"]
|
||||||
if !ok {
|
if !ok {
|
||||||
l.Error(ctx, fmt.Sprintf("unknown client %s", task.Type))
|
l.Error(ctx, fmt.Sprintf("unknown client %s", "grpc"))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
pkg, svc, mth := grpcconn.ServiceMethod(task.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 {
|
||||||
l.Error(ctx, "failed to find service "+pkg+"."+svc)
|
l.Error(ctx, "failed to find service "+pkg+"."+svc)
|
||||||
@ -145,7 +146,7 @@ func main() {
|
|||||||
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.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)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -156,8 +157,8 @@ func main() {
|
|||||||
labels := []string{"check", check.Name, "task", task.Name, "service", svc, "endpoint", mth}
|
labels := []string{"check", check.Name, "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.Addr))
|
l.Info(ctx, fmt.Sprintf("try to call %s.%s via %s", svc, mth, task.GRPC.Addr))
|
||||||
err = grpcconn.Call(ctx, l, c, task.Addr, time.Duration(task.Timeout),
|
err = grpcconn.Call(ctx, l, c, task.GRPC.Addr, time.Duration(task.Timeout),
|
||||||
treq,
|
treq,
|
||||||
rsp)
|
rsp)
|
||||||
te := time.Since(ts)
|
te := time.Since(ts)
|
||||||
@ -170,7 +171,7 @@ func main() {
|
|||||||
m.Counter(semconv.ClientRequestTotal, append(labels, "status", "success")...).Inc()
|
m.Counter(semconv.ClientRequestTotal, append(labels, "status", "success")...).Inc()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,14 +24,33 @@ type Check struct {
|
|||||||
Interval mtime.Duration `json:"interval,omitempty" yaml:"interval,omitempty"`
|
Interval mtime.Duration `json:"interval,omitempty" yaml:"interval,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Task struct {
|
type HTTPConfig struct {
|
||||||
TLSVerify *bool `json:"tls_verify,omitempty" yaml:"tls_verify,omitempty"`
|
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
|
||||||
|
Data string `json:"data,omitempty" yaml:"data,omitempty"`
|
||||||
|
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
||||||
|
OpenAPI string `json:"openapi,omitempty" yaml:"openapi,omitempty"`
|
||||||
|
Method string `json:"method,omitempty" yaml:"method,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GRPCConfig struct {
|
||||||
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
|
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
|
||||||
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
|
||||||
Data string `json:"data,omitempty" yaml:"data,omitempty"`
|
Data string `json:"data,omitempty" yaml:"data,omitempty"`
|
||||||
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
||||||
Type string `json:"type,omitempty" yaml:"type,omitempty"`
|
|
||||||
Protoset string `json:"protoset,omitempty" yaml:"protoset,omitempty"`
|
Protoset string `json:"protoset,omitempty" yaml:"protoset,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GraphQLConfig struct {
|
||||||
|
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
|
||||||
|
Data string `json:"data,omitempty" yaml:"data,omitempty"`
|
||||||
|
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Task struct {
|
||||||
|
HTTP *HTTPConfig `json:"http,omitempty" yaml:"http,omitempty"`
|
||||||
|
GRPC *GRPCConfig `json:"grpc,omitempty" yaml:"grpc,omitempty"`
|
||||||
|
GraphQL *GraphQLConfig `json:"graphql,omitempty" yaml:"graphql"`
|
||||||
|
TLSVerify *bool `json:"tls_verify,omitempty" yaml:"tls_verify,omitempty"`
|
||||||
|
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||||
Timeout mtime.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`
|
Timeout mtime.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user