add empty graphql task
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
4c32535bfa
commit
ee4c343dee
@ -208,6 +208,10 @@ func main() {
|
||||
fn, args, err = newGRPCTask(ctx, l, mtr, check.Name, task)
|
||||
case task.HTTP != nil:
|
||||
fn, args, err = newHTTPTask(ctx, l, mtr, check.Name, task)
|
||||
case task.GraphQL != nil:
|
||||
fn, args, err = newGraphQLTask(ctx, l, mtr, check.Name, task)
|
||||
default:
|
||||
err = fmt.Errorf("unknown task type")
|
||||
}
|
||||
if err != nil {
|
||||
l.Error(ctx, "failed to create task", err)
|
||||
@ -424,3 +428,96 @@ func newGRPCTask(ctx context.Context, l logger.Logger, m meter.Meter, check stri
|
||||
|
||||
return fn, nil, nil
|
||||
}
|
||||
|
||||
func newGraphQLTask(ctx context.Context, l logger.Logger, m meter.Meter, check string, task *config.TaskConfig) (any, []any, 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)
|
||||
if err != nil {
|
||||
l.Error(ctx, "failed to unmarshal openapi file", err)
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
doc, err := openapi_v3.ParseDocument(openapiBuf)
|
||||
if err != nil {
|
||||
l.Error(ctx, "failed to unmarshal openapi file", err)
|
||||
return nil, nil, err
|
||||
}
|
||||
_ = doc
|
||||
|
||||
errmap := make(map[string]interface{}, 1)
|
||||
errmap["default"] = &codecpb.Frame{}
|
||||
opts = []client.CallOption{
|
||||
httpcli.ErrorMap(errmap),
|
||||
httpcli.Method(task.HTTP.Method),
|
||||
httpcli.Path(task.HTTP.Endpoint),
|
||||
|
||||
// client.WithContentType("application/json"),
|
||||
}
|
||||
|
||||
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() {
|
||||
var cerr error
|
||||
|
||||
metadata := make(map[string]string, len(task.HTTP.Metadata))
|
||||
var rquid string
|
||||
for k, v := range task.HTTP.Metadata {
|
||||
if k == "x-request-id" && v == "generate" {
|
||||
uid, err := uuid.NewV7()
|
||||
if err != nil {
|
||||
l.Error(ctx, "failed to generate x-request-id", err)
|
||||
uid = uuid.Nil
|
||||
} else {
|
||||
v = uid.String()
|
||||
}
|
||||
}
|
||||
metadata[k] = v
|
||||
rquid = v
|
||||
}
|
||||
|
||||
l.Info(ctx, fmt.Sprintf("call %s.%s endpoint %s", treq.Service(), treq.Method(), treq.Endpoint()), "x-request-id", rquid)
|
||||
m.Counter(semconv.ClientRequestInflight, labels...).Inc()
|
||||
ts := time.Now()
|
||||
cerr = httpconn.Call(ctx, rquid, l, c, task.HTTP.Addr, time.Duration(task.Timeout),
|
||||
treq,
|
||||
rsp,
|
||||
append(opts, client.WithRequestMetadata(metadata))...,
|
||||
)
|
||||
te := time.Since(ts)
|
||||
m.Counter(semconv.ClientRequestInflight, labels...).Dec()
|
||||
|
||||
m.Summary(semconv.ClientRequestLatencyMicroseconds, labels...).Update(te.Seconds())
|
||||
m.Histogram(semconv.ClientRequestDurationSeconds, labels...).Update(te.Seconds())
|
||||
|
||||
if cerr != nil {
|
||||
m.Counter(semconv.ClientRequestTotal, append(labels, "status", "failure")...).Inc()
|
||||
} else {
|
||||
m.Counter(semconv.ClientRequestTotal, append(labels, "status", "success")...).Inc()
|
||||
}
|
||||
}
|
||||
*/
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user